Page 1 of 1

Use of '-levels' option

Posted: 2018-03-07T05:50:31-07:00
by peterhull90
Hi,
I've got an gray scale raw image where every pixel is one byte in the range 0=black, 15=white. I wanted to convert this, and thought the -level option was the right one.

Code: Select all

convert -size 104x160 -depth 8 gray:input -level 0,15 output.png
but this gives me an image mostly white with some black pixels.

To test this, create a grayscale image

Code: Select all

convert -size 16x16 -depth 8 "gradient:black-gray(15)" 1.png
And

Code: Select all

convert 1.png -level 0,15 2.png
I would expect this to be something similar to what '-normalize' would do, but I get a row of black pixels at the top the rest is white.

Is this a bug or am I using '-level' wrong?

Using Version: ImageMagick 6.9.9-11 Q16 x86_64 2017-09-30
(for Cygwin)

Re: Use of '-levels' option

Posted: 2018-03-07T06:19:18-07:00
by snibgo
You create 1.png with 8 bits per channel, just one channel. But you are using IM Q16, so when 1.png is read, pixels are expanded to 16 bits/channel. This expansion is done by multiplying by 257. So the instead of 15 in the level, use 15*257 which is 3855.

Re: Use of '-levels' option

Posted: 2018-03-07T06:47:47-07:00
by peterhull90
Got it, thanks.