Page 4 of 4

Re: How to check image color or back and white

Posted: 2019-06-11T22:09:11-07:00
by BenjaminKim

I was finally able to work out exactly what I needed. Many thanks to those who helped and helped guide me to the solution I needed.

In running tests across many, many thousands of PDFs, I kept getting inconsistent results for what I was trying to accomplish. This was no fault of ImageMagick - it was due to the way two different engines were rasterizing the original PDF. It's a long story.

Once I got past that, I was trying to leverage HSB - but it still wasn't producing expected results. I kept digging, and ultimately found that .NET's "Color.GetBrightness()" method uses HSL, not HSB. ... mework-4.8 Of course, I now see that it says at the very top that is uses "HSL", but I actually had verified this via the old fashioned approach - getting RGB values and running it through the HSL formula.

And as I was ultimately comparing against images generated in .NET, it all came together.

All said - this is what I've used once the PDF has been rasterized. I used quantum values to be a bit more precise.

magick sample.tif -colorspace HSL -channel L -separate -range-threshold 43908,43908,65530,65530 -negate -compress group4 mask.tif