2
votes

In my C# Silverlight application, I am trying to decode DICOM images in compressed JPEG transfer syntax, using the FJCore class library.

The DICOM images are normally compressed with 12-bit precision. When trying to decode such an image using the original FJCore source code, I get an exception saying "Unsupported codec type", because in the original FJCore implementation only SOF0 (Baseline DCT) and SOF2 (Progressive DCT) Start-of-Frame markers are supported. If I change the implementation to also accept the SOF1 marker (Extended Sequential DCT) and treat SOF1 frames the same way as SOF0 frames, the images are decoded, but only 8 bits are accounted for.

A typical 12-bit precision image now looks like this after decoding with the modified FJCore library:

12-bit precision JPEG image encoded to 8-bit precision by FJCore

Ideally, the image should look like this:

12-bit precision JPEG image encoded to full 12-bit precision

As far as I have been able to tell from the FJCore implementation, the image precision is recorded in the JpegFrame class, but it is never used. The original FJCore implementation seems to only fully support grayscale images with 8 bit precision.

I am planning to "take the bull by the horns" and try to extend FJCore myself to support 12-bit precision for grayscale images. But before I do, I thought I should pose the question here in StackOverflow to see if anyone has encountered and solved this problem before? In that case, I would be very happy to learn how you solved the problem.

Many thanks in advance!
Anders @ Cureos

1
@Hans, I am sorry that you don't like my way of posting questions to SO. In the best of worlds, FJCore would have an alive and vibrant user or developer forum, but unfortunately there is no sign of development or developer interaction since early 2009. I have noticed that FJCore has been discussed a few times on SO (even has its own tag) so I took the opportunity to post my question here. I am not asking for someone to do the job, but if anyone knows of an open-source solution to the 12-bit precision issue, this would be of great help to me (and potentially other developers as well).Anders Gustafsson
After a very quick look at the source code, it seems that the codec is able to read 12 bits images. Looking at the images above I would say that a VOI/LUT transform has to be applied to the frame returned by FJCore EDIT: I'm looking at the images again, and now it doesn't look like a VOI/LUT problem anymore. The high bits are simply truncatedPaolo Brandoli
Thanks Paolo for taking the time to look into this. I suspected a truncation error; glad you are able to confirm this.Anders Gustafsson

1 Answers

2
votes

I just updated my own JPEG decoder to handle the extended mode and what I needed to change was my inverse DCT. Before changing the code, the output looked similar to your sample image above. I have always stored 16-bit coefficient values from the entropy decode, but my DCT calculation was corrupting the larger values by using 16-bit integers to hold temporary values while doing the math. I changed the DCT code to use 32-bit integers for the calculations and that solved the problem.