Changing a pixel color that is "close" to another color

Reply

Join Date: Oct 2007
Posts: 20
Reputation: bob on whidbey is an unknown quantity at this point 
Solved Threads: 0
bob on whidbey bob on whidbey is offline Offline
Newbie Poster

Changing a pixel color that is "close" to another color

 
0
  #1
Jan 16th, 2008
I store in an image in a RES file. Because it is so large, I first convert it from a BMP to a JPG. Then I load the JPG from the RES file, convert it to a BMP, and can now manipulate the image on a pixel by pixel basis. I want to convert all the "White" pixels to cllMyLightBlue.

It's easy to change one color in a BMP into another color:

Pascal and Delphi Syntax (Toggle Plain Text)
  1. IF Bitmap.Canvas.Pixels[i,j] = clWhite
  2. THEN Bitmap.Canvas.Pixels[i,j] := clMyLightBlue

The problem is - in the process of converting from BMP to JPG back to BMP, some "bleeding" of colors, near the edges, has occurred. While the white areas of the image look basically white, they are not exactly. This approach works pretty well:

Pascal and Delphi Syntax (Toggle Plain Text)
  1. delta := 100000; // determine by trial and error
  2. IF (Bitmap.Canvas.Pixels[i,j] > (clWhite-delta)) and
  3. F (Bitmap.Canvas.Pixels[i,j] < (clWhite-delta)) then
  4. THEN Bitmap.Canvas.Pixels[i,j] := clMyLightBlue

Since the pixel "number" is an amalgam of RGB numbers, it seems that a better approach would be to change the pixel color only if all 3 RGB values were within some tolerance level...perhaps a delta of 10.

How can I test, and replace, specific RGB vlues of a pixel? Is there a better way to clean up my image.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Changing a pixel color that is "close" to another color

 
0
  #2
Jan 17th, 2008
The fact that that works is fluke.

What is the pixel format for your image? (pf1bit, pf4bit, pf8bit, pf15bit, pf16bit, pf24bit, pf32bit, something else?)

If it is pf24bit then every three bytes are a tuple (blue, green, red) --in that order.

If you need to learn more about the different formats then see efg's technical notes on manipulating scanline data.

You might also want to peruse efg's Color Reference page.

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 20
Reputation: bob on whidbey is an unknown quantity at this point 
Solved Threads: 0
bob on whidbey bob on whidbey is offline Offline
Newbie Poster

Re: Changing a pixel color that is "close" to another color

 
0
  #3
Jan 17th, 2008
I too was surprised at how well my kludgy approach seemed to work. Thanks for pointing out efg's tech note.

Since "white" has 255 in all RGB bits I don't have to test for something higher than than. The following code workes very well when I set 'maxd' to 255-50.

with Row[i] do
if (rgbtRed > maxd) and (rgbtGreen > maxd) and (rgbtBlue > maxd) then
Row[i] :=LightBlueBits;
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC