convert specify the valid range of pixel values

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
diaadi
Posts: 7
Joined: 2015-05-07T01:56:45-07:00
Authentication code: 6789

convert specify the valid range of pixel values

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert specify the valid range of pixel values

Post 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.
snibgo's IM pages: im.snibgo.com
diaadi
Posts: 7
Joined: 2015-05-07T01:56:45-07:00
Authentication code: 6789

Re: convert specify the valid range of pixel values

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert specify the valid range of pixel values

Post by snibgo »

Have you tried multiplying by 16 before the contrast-stretch, then dividing by 16?
snibgo's IM pages: im.snibgo.com
diaadi
Posts: 7
Joined: 2015-05-07T01:56:45-07:00
Authentication code: 6789

Re: convert specify the valid range of pixel values

Post by diaadi »

snibgo,
I am using the command "convert" .
How can be specify x16 and /16 in the command ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert specify the valid range of pixel values

Post 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.
snibgo's IM pages: im.snibgo.com
diaadi
Posts: 7
Joined: 2015-05-07T01:56:45-07:00
Authentication code: 6789

Re: convert specify the valid range of pixel values

Post by diaadi »

Thanks snibgo. What you said worked!
Post Reply