![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I need a colormatrix that will change every non white pixel in an image to black, and leave all white pixels white. Any ideas? |
|
I need a colormatrix that will change every non white pixel in an image to black, and leave all white pixels white. Any ideas? Carlos Aloatti |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Michael: Thank you very much for your answer. There is only one problem: colors that have one or more of the RGB channels = 255 do not turn black, but for example RGB(255,0,0) or RGB(0,255,0) Maybe one option would be to remap this colors to black, there are only six colors to remap: 255,0,0 0,255,0 0,0,255 255,255,0 0,255,255 255,0,255 Another option (that I don't like, I considered it not elegant) is adding an internediate pass to your solution to convert to "grayscale": First pass: 1/255, 0, 0, 0, 0, ; 0, 1/255, 0, 0, 0, ; 0, 0, 1/255, 0, 0, ; 0, 0, 0, 1, 0, ; 0, 0, 0, 0, 1) Second pass: 0.17, 0.17, 0.17, 0, 0, ; 0.17, 0.17, 0.17, 0, 0, ; 0.17, 0.17, 0.17, 0, 0, ; 0, 0, 0, 1, 0, ; 0, 0, 0, 0, 1) Third pass: 255, 0, 0, 0, 0, ; 0, 255, 0, 0, 0, ; 0, 0, 255, 0, 0, ; 0.0, 0.0, 0.0, 1, 0, ; 0.0, 0.0, 0.0, 0, 1) The result is that only rgb(1,1,1) pixels get converted to rgb(1,1,1) and pixels like (1,1,0) get converted to (0,0,0) Why 0.17? Because 0.17 * 3 = 0.51 so only RGB(1,1,1) make it to 0.51 and get rounded up to 1 The big problem I see here is that colormatrices are 1 based instead of being 255 based, that would have eliminated this kind of "playing with rounding" things. I have found another solution, but somehow I don't like it either. What I do is apply a colormatrix that will turn the image to "half grayscale": 0.2, 0.2, 0.2, 0, 0 0.2, 0.2, 0.2, 0, 0 0.1, 0.1, 0.1, 0, 0 0.0, 0.0, 0.0, 1, 0 0.0, 0.0, 0.0, 0, 1 Why do I use 0.2,0.2,01? Because of rounding errors, this gives me a one decimal value for white: rgb(127.5,127.5,127.5) Then I apply a Threshold of 0.5 (=127.5) and I get what I wanted. The big problem I encountered is rounding errors, problems with colors like RGB(254,255,255) getting converted to white for example. I guess I will just check which one is faster and use that one. I must mention that I am using the Visual FoxPro GDIPlusX port of the .NET drawing classes. Carlos Alloatti |
#5
| |||
| |||
|
|
I need a colormatrix that will change every non white pixel in an image to black, and leave all white pixels white. Any ideas? |
#6
| |||
| |||
|
|
It looks like the rounding will be an issue. You can always try to create a 1bpp empty mask bitmap and use LockBits to cycle through all of the colors of the image and set the corresponding mask pixels accordingly. This approach may be faster as there is no floating point operations and float to integer conversions. |
#7
| |||
| |||
|
|
"Carlos Alloatti" <calloa... (AT) gmail (DOT) com> wrote in message news:c7b91cf8-3d88-43ca-87e4-391951a356b5 (AT) c29g2000hsa (DOT) googlegroups.com... I need a colormatrix that will change every non white pixel in an image to black, and leave all white pixels white. Any ideas? Why not just use LockBits? It will be faster and cleaner code. Michael |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |