DCMCJPEG - Converting 16bit grayscale to 8bit

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Jantograaf
Posts: 1
Joined: Thu, 2017-09-28, 13:04

DCMCJPEG - Converting 16bit grayscale to 8bit

#1 Post by Jantograaf »

Hi all,

I have a library of images where the customer wants to store them online for archiving purposes. I am trying to compress the images using any lossless codec with a quality factor of 90 (barely noticable). I am, however, aware that we will lose some details in pixel data when converting from 16 to 8 bit. However... is it actually possible?

When I try to convert the images and force them to 8 bit, all I get is a grey image. I've tried everything (mapping, rescaling, windowing...) but I can't seem to find where things go wrong.
When I look at the raw pixel data, however, not every byte has the same value, so there is actual difference between the individual pixels, it's just not showing when opening the DCM file.

I've tried command line combinations of all sorts, however with unsatisfactory results:

Code: Select all

dcmcjpeg.exe +Wn +be +eb +un +q 90 "c:\users\...\Image-C2-C3-20130507050242.dcm" test.dcm
dcmcjpeg.exe +rm +be +eb +un +q 90  "c:\users\...\Image-C2-C3-20130507050242.dcm" test.dcm
dcmcjpeg.exe +ca +be +eb +un +q 90  "c:\users\...\Image-C2-C3-20130507050242.dcm" test.dcm
dcmcjpeg.exe +Ww 32767 65535 +be +eb +un +q 90 "c:\users\...\Image-C2-C3-20130507050242.dcm" test.dcm
...
The original image metadata:

Code: Select all

(0028,0002) US 1                                                 # 1, 2 Samples per Pixel
(0028,0004) CS MONOCHROME1                                       # 1, 12 Photometric Interpretation
(0028,0010) US 2048                                              # 1, 2 Rows
(0028,0011) US 1536                                              # 1, 2 Columns
(0028,0030) DS 0.129\0.129                                       # 2, 12 Pixel Spacing
(0028,0034) IS 1\1                                               # 2, 4 Pixel Aspect Ratio
(0028,0100) US 16                                                # 1, 2 Bits Allocated
(0028,0101) US 14                                                # 1, 2 Bits Stored
(0028,0102) US 13                                                # 1, 2 High Bit
(0028,0103) US 0                                                 # 1, 2 Pixel Representation
(0028,1050) DS 861                                               # 1, 4 Window Center
(0028,1051) DS 20308                                             # 1, 6 Window Width
(0028,1052) DS -298200.4                                         # 1, 10 Rescale Intercept
(0028,1053) DS 29.10124                                          # 1, 8 Rescale Slope
Is there any way to 'command line' compress these images to a lossy 8-bit or even 12-bit version? I am aware that for 12-bit, I can't use baseline encoding (+eb) so I'll have to switch to another process...

If anyone can point me in the right direction, that'd be great!

Thanks in advance!

Jan

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1442
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

Re: DCMCJPEG - Converting 16bit grayscale to 8bit

#2 Post by Marco Eichelberg »

The JPEG baseline codec, selected by "+eb" in your command line, is limited to 8 bits per sample. Use Enhanced Sequential mode (+ee), which permits 12 bits/pixel.
Furthermore, when converting from 16 to 12 bits, you may want to control the mapping from 16 to 12 bit values. By default, this will just be a right-shift, which means that you lose 4 bits of information per pixel. In many cases (e.g. CT), the number of bits actually used in the image is much less than 16 bits (12 or 13), and here it will help if you use one of the VOI windowing options, e.g. --min-max-window.

Finally, if you really want lossless compression, use lossless JPEG (or, even better, JPEG-LS)!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 1 guest