Convert 16 bit image to 12 bit image

Hi Experts,

I new to C# and image processing. I have a 16 bit image stored in a byte array.
Anybody could help me to convert this to 12 bit image.
Who is Participating?
Jens FiedererConnect With a Mentor Test Developer/ValidatorCommented:
So you are just throwing away the high order 4 bits.

The other approach would be to discard the low order bits

pixelVal = pixelVal >> 4;

One way discards subtle differences, the other could result in some images where all the bits are 4095.
Jens FiedererTest Developer/ValidatorCommented:
Just throw away 4 bits!

Actually, not all "image"s are built alike - you'll want to know what the bits are used for.

Odds are your existing image uses either 5 bits for each color with a spare bit used either for intensity or transparency, or 4 bits for each color and 4 bits for intensity, and your target image wants 4 bit for color.  You have to know, though.
jensfiederer is right, you need to know what those bits are used for. How is your image encoded (or not...) ? BMP, JPG, PNG ... ?
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

VeerabhadraiahhvAuthor Commented:
I have a DICOM image, it may be signed image or unsigned image.
I need to convert these images to 12 bit DICOM image.
Jens FiedererTest Developer/ValidatorCommented:
Fortunately, the DICOM standard is publicly available:
there seems to exist free/open source libraries to work with DICOM. Have you had the chance to look at those:
VeerabhadraiahhvAuthor Commented:
I got the answer and thanks for your  comments.
I'm using the following code to convert 16 bit images to 12 bit image.

             if (pixelVal > 4095)
                    pixelVal = 4095;
jensfiederer's approach seems more appropriate. Try with a large sample of images (especially those above 4095) and see which turns out best.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.