Emile, your two pieces of code will result in two different image types. Do you want a grayscale image or a black and white one?
Since you mentioned old pictures I guess you want grayscale images as a result. Also, I guess you are coding this for you own and for fun, right? I ask this because there are free tools that can convert color pictures to grayscale, and even process an entire folder of pictures at once (I use ImageJ and I know it works with entire folders).
all I want is strip the yellow from the image (or as I wrote earlier, keep only the black part).
Yes, it is for fun - my own use -; while you were there, you may see a colored scan with yellow background… Usually, I run GIMP and do a white balance and most of the time the result is GREAT. But this do not really works for the non colored images.
Sam: Brightness and Luminosity.
I tried that with GIMP, but the results were bad (IMHO).
I recall far better results, but it may be with colored images…
So I too am confused… are you attempting to filter out a specific color and leave all the other colors? Or are you attempting to convert a color comic to a grayscale one?
Removing a specific color will be difficult becaulse all the “yellow” pixels are not the same as far as the computer is concerned (what you see as yellow might not be yellow at all at the pixel level).
If you wish to change it to grayscale… THAT is easy to do… just use the equation in the last line of Sams post above
I only want to extrack the Black parts of the (Black and White) image. That image can be a week at the sun rays or as old as you (or me) ;).
THe code that gaves me the best result is:
For y As Integer = 0 To lastY
For x As Integer = 0 To lastX
aColor = surf.Pixel(x,y)
If aColor.Red < 80 And aColor.Green < 80 And aColor.Blue < 80 Then
// Set the color to Black
aColor = RGB(0,0,0)
// Set the color to White
aColor = RGB(255,255,255)
// Plot the new Color
BP_Surf.Pixel(x,y) = aColor
// Display the changed image
cImage.Backdrop = Black_Pict
I was watching TV when I was asking myself “What if I set White in the Else (I probably already do that, but…).
So I tried, then I changed the If test (this is new) and then I increased the value (in steps up to 80).
I will add a Control to set that value as 8 (or 16) step, so I can change the value in one Run ;).
Here is some old RB code I wrote way back in the days when I was doing pattern/color recognition for computer vision. Unfortunately, no idea any more how I came up with those formulas Documenting stuff was not my forte back then…
for x = 0 to tPic.width - 1
for y = 0 to tPic.height - 1
Col = SrcRGB.Pixel(x,y)
H = Col.Hue * 255
V = Col.Value * 255
S = Col.Saturation * 200
' you may want to play with the 25 and 195 value to get a better result, making the range wider or more narrow
minV = 25 - (30/215 * (S - 40))
maxV = 195 + (70/215 * (S - 40))
if V >= minV and V <= maxV then
tgtRGB.pixel(x,y) = Col
tgtRGB.pixel(x,y) = &CFFFFFF
It’s a really simply color table, made from an array of 255 integers. Xojo uses the channel value (0 ~ 255) to look up what you want the value to be.
If you set the first 127 values to zero ( black ) and the remaining values to 255 ( white ), you’d get a black and white image.
The downside to Xojo’s version is that it operates on a per channel basis and not per color, so some of the really cool things that we can do with huge LUTS, we can’t in Xojo. However in it’s own right, it’s a nice thing to have.