Page 1 of 1

12-bit grayscale images

Posted: 2007-06-20T11:18:57-07:00
by jbrandon5
I have a series of raw format grayscale images, all with 12 bits per pixel. However, the pixels are padded with 4 bits in the MSBs, so that each pixel is 2 bytes long.

Is this the standard format for raw GRAY files? I can't seem to get IM to properly recognize these. For example, if I want to convert the image to a BMP, I've tried the following:

convert -size 4096x1714 -depth 12 gray:<input_file.raw> bmp:<output_file.bmp>

This doesn't output the correct image, and neither does using -depth 16.

What is the correct way to tell IM to handle 12-bit pixels, and do the samples need to be packed in the file, or can they be padded out to 16 bits?

Re: 12-bit grayscale images

Posted: 2007-06-20T12:17:05-07:00
by magick
Add -endian lsb or -endian msb along with -depth 16 and see if that fixes the problem.

Re: 12-bit grayscale images

Posted: 2007-06-20T14:13:26-07:00
by jbrandon5
I can see different results using the -endian option, but none of them are correct:

display -size 4096x1714 -depth 16 -endian msb gray:stem0.raw All black output
display -size 4096x1714 -depth 16 -endian lsb gray:stem0.raw Image shapes recognizable, but looks like MSBs and LSBs are swapped

display -size 4096x1714 -depth 12 -endian msb gray:stem0.raw Image shapes recognizable, but strong vertical striations
display -size 4096x1714 -depth 12 -endian lsb gray:stem0.raw Same as previous one


The pixels are stored big-endian, so I would expect that option to work, but something is still off. Any other ideas? Thanks!

Re: 12-bit grayscale images

Posted: 2007-06-20T15:07:11-07:00
by magick
We have a couple of ideas but to save time can you post a URL to one of your images and its width and height. We'll get it displayed properly and then post the proper command here.

Re: 12-bit grayscale images

Posted: 2007-06-20T16:00:30-07:00
by glennrp
You should have padded them in the lsb. Your "black" images may be really very dark gray,
with values 0-3855. To view the existing images you will have to multiply each pixel by 17.

Re: 12-bit grayscale images

Posted: 2007-06-20T17:22:11-07:00
by jbrandon5
Yes, that was the problem. These images were output from a software JPEG2000 decoder, and there was no option where to place the 12-bit samples inside the 16 bits (the MSBs were padded), so I had to rewrite the files myself in order to view them.

Then this was the correct command: display -size 4096x1714 -depth 16 -endian msb gray:input.raw gray:output.raw

It appears that the -depth option tells IM to always expect packed samples for a RAW pixel format. It would be useful if the documentation stated this, since I originally was confused whether to use -depth 12 or -depth 16.

Thanks for your assistance!