Page 1 of 1

Threshold & separate outputs a bilevel rather than a grayscale

Posted: 2015-02-26T10:40:18-07:00
by tom_dl
When I threshold a channel and then use -separate to save only this channel, the image I get is in 'bilevel' mode (acording to identify), rather than grayscale.

I use this line:

Code: Select all

convert input.png -colorspace lab -channel G -separate -threshold 50% -channel G -separate output.png
And obviously I'm expecting an image with only 2 colors (black + white) so I guess IM is choosing bilevel as it is all that's necessary. However, when compositing multiple images of this type, I get strange results, where the images regain their channel identity, and produce colored images.

How can I fix the output type as 'Grayscale'?

Re: Threshold & separate outputs a bilevel rather than a grayscale

Posted: 2015-02-26T10:56:54-07:00
by tom_dl
I've tried:

Code: Select all

convert input.png -colorspace lab -channel G -separate -threshold 50% -channel G -separate -type grayscale output.png
to no avail, by the way.

Re: Threshold & separate outputs a bilevel rather than a grayscale

Posted: 2015-02-26T11:09:20-07:00
by fmw42
I am not sure I understand what your ultimate goal is. Can you explain what you are trying to do functionally step-by-step. Your command above does not make sense to me. Once you have separated a channel, there is no reason to separate it again.

try

Code: Select all

convert input.png -colorspace lab -channel G -separate +channel -threshold 50% output.png
That is going to make one bilevel output since it only has two colors, black and white. That thresholded image with be the A channel in LAB, but the result will lose any information about the fact that it came from LAB colorspace.

After this step, what is you are trying to do next? What are you expecting from the final result.

If you only want to threshold one channel of the LAB image and keep the rest the same, then

Code: Select all

convert input.png -colorspace lab -channel R -threshold +channel -colorspace sRGB result.png
This will threshold the L channel of LAB and keep the others unchanged and then convert back to sRGB. Note that it is not a good idea to change the AB channels non-symmetrically. That will cause weird color shifts.

Re: Threshold & separate outputs a bilevel rather than a grayscale

Posted: 2015-02-26T12:20:28-07:00
by snibgo
I point out the problems in your near-identical thread viewtopic.php?f=1&t=27109

Re: Threshold & separate outputs a bilevel rather than a grayscale

Posted: 2015-02-26T16:03:25-07:00
by fmw42
snibgo wrote:I point out the problems in your near-identical thread viewtopic.php?f=1&t=27109

Yes, I forgot to add +channel in one of my examples on the other page. Also you are right about -set colorspace. I was just trying to convert back to sRGB at the end.

My error. You are correct.