Page 1 of 1

white and black threshold & change white and block value

Posted: 2010-01-29T19:06:45-07:00
by sweet-town
I have a YCbCr file, I want to force all pixels with Y > 235 to 235 (instead of 255), and force all pixels with Y<16 to 16 (instead of 0)

It is pretty close to what white-threshold and black-threshold do, but I want the white point to be 235 instead of 255, and the black point to be 16 instead of 0.
I could not find a way to do that. Help please!

-white-threshold Force to white all pixels above the threshold while leaving all pixels at or below the threshold unchanged.
-black-threshold Force to black all pixels below the threshold while leaving all pixels at or above the threshold unchanged.

Thanks.

-st

Re: white and black threshold & change white and block value

Posted: 2010-01-29T19:28:17-07:00
by fmw42
If you are on Q8 IM, then

convert yimage +level 16,235 new_yimage

if you are on Q16, then you must convert to percent (min=100*16/255 and max=100*235/255)

convert yimage +level min,max% new_yimage


see http://www.imagemagick.org/Usage/color/#level_plus

Re: white and black threshold & change white and block value

Posted: 2010-02-01T01:05:48-07:00
by sweet-town
Thanks for the reply. However I read the exlanations of +level through the link you provided, it does not seem to be what I want.
+level not only modifies the black and white value, it compresses the values in between also.
For my application, I do not want to change the value in between.
I only want to threshold pixels with Y > 235 to 235 (instead of 255), threshold all pixels with Y<16 to 16 (instead of 0), while leave the values in between unchanged. is there a way to do this in IM?

BTW, how do I know if I'm on Q8 IM or Q16 IM? I did a " convert -version", it shows my version is 6.2.4 .

Thanks.

Re: white and black threshold & change white and block value

Posted: 2010-02-01T09:29:53-07:00
by fmw42
your version 6.2.4 is very old (over 300 versions old). you might consider upgrading. when i do that I get

convert -version
Version: ImageMagick 6.5.9-1 2010-01-16 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC


To do what you want, convert your thresholds to percent as mentioned earlier and do the following:

convert image -white-threshold max% -black-threshold min% result

you can also see my script, plm at the link below