Page 1 of 1

convert specify the valid range of pixel values

Posted: 2015-05-07T02:56:37-07:00
by diaadi
Hi all,

I have an image with 12bit/pixel data. That is, the pixel values range from 0 to 2^12-1.
But the pixel is stored in two bytes. (16 bits out of which only 12 bits are valid)

Is there a way I can make convert to process only 12 bits and not entire 16 bits ?
Because I tried using enhance using "depth 16" option and it has generated output whose values range from 0 to 65535. But I want the output also to restrict to 12 bits.

Which convert option can be used ? Depth doesn't seem be correct option.


Thanks!

Re: convert specify the valid range of pixel values

Posted: 2015-05-07T03:23:14-07:00
by snibgo
What processing do you want to do?

If the input is 12-bits/channel/pixel but stored in 16 bits, and you want the same for output, then there is no problem. No conversion is needed. The only oddity is that the top or bottom four bits will be zero.

If the top 4 bits are zero and you want to convert to 16 bits, you could multiply by 16.

Re: convert specify the valid range of pixel values

Posted: 2015-05-07T09:31:15-07:00
by diaadi
I want to perform contrast stretch.but the output after stretch is becoming 16-bit...I want the output to be 12bt as well

Re: convert specify the valid range of pixel values

Posted: 2015-05-07T10:17:06-07:00
by snibgo
Have you tried multiplying by 16 before the contrast-stretch, then dividing by 16?

Re: convert specify the valid range of pixel values

Posted: 2015-05-07T22:29:55-07:00
by diaadi
snibgo,
I am using the command "convert" .
How can be specify x16 and /16 in the command ?

Re: convert specify the valid range of pixel values

Posted: 2015-05-07T22:35:25-07:00
by snibgo

Code: Select all

convert in.ext -evaluate Multiply 16 -contrast-stretch {whatever} -evaluate Divide 16 out.ext
See http://www.imagemagick.org/script/comma ... p#evaluate

I don't know if "LeftShift 4" might be faster or better.

Re: convert specify the valid range of pixel values

Posted: 2015-05-18T23:19:33-07:00
by diaadi
Thanks snibgo. What you said worked!