Realbasic: Emboss filter

I’m checking out several ways to do computer vision and Embossing may be a pre-filter I will use to find endges fast.

Writing an Emboss filter turned out to be easier than I thought. The principle is that a pixel in the image is replaced either by a highlight or a shadow, depending if the boundaries in the picture are light or dark.

If the contrast is low, then it becomes gray.

Here is the code for an emboss filter in Realbasic.

Function Emboss(tmpPic as picture) As picture
  dim width as integer = tmpPic.Width
  dim height as integer = tmpPic.Height
  dim srcSurf as RGBSurface = tmpPic.RGBSurface
  Dim dst as Picture
  dst = NewPicture(width, height, 32)
  dim dstSurf as RGBSurface = dst.RGBSurface
  dim i, j as integer
  dim upperLeft, LowerRight as Color
  dim redDiff, greenDiff, blueDiff, Diff  as integer
  dim grayColor as integer
  dim newColor as Color
  for i  = 0 to height - 1
    for j = 0 to width - 1
      if i > 0 and j > 0 then
        upperLeft = srcSurf.Pixel(j-1,i-1)
      end if
      if i < height - 2 and j < width - 2 then
        LowerRight = srcSurf.Pixel(j+1,i+1)
      end if
      redDiff = bitwise.bitAnd(LowerRight.Red, 255) - bitwise.bitAnd(upperLeft.Red, 255)
      redDiff = bitwise.bitAnd(LowerRight.Green, 255) - bitwise.bitAnd(upperLeft.Green, 255)
      blueDiff = bitwise.bitAnd(lowerRight.Blue, 255) - bitwise.bitAnd(upperLeft.Blue, 255)
      diff = redDiff
      if (abs(greenDiff) > abs(diff)) then
        diff = greenDiff
      end if
      if (abs(blueDiff) > abs(diff)) then
        diff = blueDiff
      end if
      grayColor = 128 + diff
      if (grayColor > 255) then
        grayColor = 255
      elseif (grayColor < 0) then
        grayColor = 0
      end if
      newColor = RGB(grayColor, grayColor, grayColor)
      dstSurf.Pixel(j, i) = newColor
  Return dst
End Function

See ya!

Click here to Donation if you like my work


About Alwaysbusy

My name is Alain Bailleul and I'm the Senior Software Architect/Engineer at One-Two. I like to experiment with new technologies, Computer Vision and A.I. My projects are programmed in B4X , Xojo, C#, java, HTML, CSS and JavaScript. View all posts by Alwaysbusy

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: