Image Processing with Liberty BASIC

These are examples of reading the colour of the pixels of an existing image, and creating a new one with colour & tone/brightness variations. They were later followed by the inverse and conic variations detailed elsewhere. I also tried various convolutions and vignetting effects...

....original 'Lena.bmp',

....false colour look-up image also needed.

16 variations on Lena

A series of False Coloured variations

Sorry these animations have a few artifacts showing- my carelessness.

Thresholded black and white variations

Sinusoidal shear

Rotational swirl



Edge detection and inversion


The following code is a typical variation. Shows reading pixels and re-writing them. For other effects you just change what to do with the pixels- a geometric re-position and/or re-colouring.



      dim ColLookUp$( 256, 12)

      data 5, 18, 33, 44, 53, 62, 80, 93, 105, 118, 129

      WindowWidth  =720: WindowHeight =500

      graphicbox,   38, 10, 206, 206    '   drawing area 200x200 for bmp file.
      graphicbox #w.gb2,   8,240, 261, 140    '   drawing area for colour look-up.
      graphicbox #w.gb3, 290, 10, 406, 408    '   drawing area for false colour copy.

      open "Bitmap demo" for window as #w

      #w     "trapclose [quit]"  "down ; fill white"
      #w.gb2 "down ; fill white"
      #w.gb3 "down ; fill white"

      loadbmp "lena", "lena.bmp" "drawbmp lena 2 2 ; flush"

      loadbmp "table", "QuadSpectrum.bmp"
      #w.gb2 "drawbmp table 1 1 ; flush"

      handleg2 =hwnd( #w.gb2)
      calldll #user32, "GetDC", handleg2 as ulong, h2DC as ulong

      for l =1 to 11                                 '   since my bmp has 11 graduated colour stripes
            read yy                                 '   which is how far down next colour stripe is centred
            for v =0 to 255
                calldll #gdi32, "GetPixel", h2DC as ulong, v as long, yy as long,      pixcol as long
                bl = int(  pixcol /( 256*256))
                gr = int( (pixcol               -bl *256*256) / 256)
                re = int(  pixcol               -bl *256*256 - gr *256)
                ColLookUp$( v, l) =str$( re) +" " +str$( gr) +" " +str$( bl)
                print v, l, ColLookUp$( v, l)
            next v
      next l

      unloadbmp "table"
      callDll #user32, "ReleaseDC", handleg2 as ulong, h2DC as ulong, result as ushort

      handlegb =hwnd(
      calldll #user32, "GetDC", handlegb as ulong, hDC as ulong

  for ch =1 to 11

      for y =1 to 200  '   Display false colour version
        for x =1 to 200
          calldll #gdi32, "GetPixel", hDC as ulong, x as long, y as long, pixcol as long
          bl = int(  pixcol /( 256*256))
          gr = int( (pixcol               -bl *256*256) / 256)
          re = int(  pixcol               -bl *256*256 - gr *256)

          gray =int( ( re +gr +bl) /3)

          #w.gb3, "color "; ColLookUp$( gray, ch)
          #w.gb3 "set "; x +102; " "; y +  102

        next x
      next y

      #w.gb3 "flush"
      #w.gb3 "getbmp scr 102 102 200 200"
      bmpsave "scr", "falseCol1" +right$( "000" +str$( ch), 3) +".bmp"
  next ch

      callDll #user32, "ReleaseDC", handlegb as ulong, hDC as ulong, result as ushort
      close #w

e-mail me if you want the other variations. In all cases you'll want to save the ORIGINAL 'Lena' as a bmp into the folder where you save the Liberty BASIC code.