Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Convert 16 bit image to 12 bit image

Posted on 2011-03-22
8
881 Views
Last Modified: 2012-08-14
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.
0
Comment
Question by:Veerabhadraiahhv
  • 3
  • 3
  • 2
8 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 35189710
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.
0
 
LVL 11

Expert Comment

by:lenordiste
ID: 35193452
jensfiederer is right, you need to know what those bits are used for. How is your image encoded (or not...) ? BMP, JPG, PNG ... ?
0
 
LVL 4

Author Comment

by:Veerabhadraiahhv
ID: 35196810
I have a DICOM image, it may be signed image or unsigned image.
I need to convert these images to 12 bit DICOM image.
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 35197692
Fortunately, the DICOM standard is publicly available:

ftp://medical.nema.org/medical/dicom/2009/
0
 
LVL 11

Expert Comment

by:lenordiste
ID: 35202007
there seems to exist free/open source libraries to work with DICOM. Have you had the chance to look at those:
http://opendicom.sourceforge.net/
http://sourceforge.net/projects/dicom-cs/
0
 
LVL 4

Author Comment

by:Veerabhadraiahhv
ID: 35277525
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;
                }
0
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
ID: 35279161
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.
0
 
LVL 11

Expert Comment

by:lenordiste
ID: 35285278
jensfiederer's approach seems more appropriate. Try with a large sample of images (especially those above 4095) and see which turns out best.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question