How to generate DICOM JPEG compression image without JFIF header

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
zhangfubin119
Posts: 4
Joined: Mon, 2019-04-22, 10:51

How to generate DICOM JPEG compression image without JFIF header

#1 Post by zhangfubin119 »

Hi, Teachers,

I am a DICOM developer from china. I am developping a project on JPEG compression。 and I used transfer syntax 1.2.840.10008.1.2.4.70. I tried to use sample code of DCMTK org to compress XA(monochrome2 and multi-frames) DICOM image. but the compressed image cannot be decompressed by other storage scp such as JDICOM tool. And error info is "the marker ffe0 can not be recognized". I downloaded some XA sample dicom files with JPEG compression. And I found there are no JFIF header.

Firstly, as My understanding, JFIF header should not exist in DICOM jpeg file. Could you please confirm if My understanding is right or not?

If my understanding is right, why is there JFIF header in DCMTK jpeg compression file for photometric interpretation "monochrome2"。 I am confused. should have JFIF header in JPEG compression DICOM file?

I expected your reply. Thanks so much.

Regards,
Tony

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How to generate DICOM JPEG compression image without JFIF header

#2 Post by Michael Onken »

Hi,

the JFIF header is actually permitted in DICOM, see part 5 (number #3 in section on JPEG compression).

I don't think the DCMTK JPEG compressor (or the related tool dcmcjpeg) does make use of any JFIF header information.

Best regards,
Michael

zhangfubin119
Posts: 4
Joined: Mon, 2019-04-22, 10:51

Re: How to generate DICOM JPEG compression image without JFIF header

#3 Post by zhangfubin119 »

Hi Michael,

Thanks for your reply.

Actually, I used sample code "https://support.dcmtk.org/docs/mod_dcmjpeg.html" to compress XA image. I can find the following marker in compressed file.
"FF D8 FF E0 00 10 4A 46 49 46 00 01 01 00 00 01 00 01 00 00 FF C3"

There is APP0 info between FF D8 and FF C3. Is this correct?
I found there is no such APP0 info in some sample DICOM JPEG image.

Could you please send me a sample XA DICOM image with JPEG Lossless(1.2.840.10008.1.2.4.70)?

Regards,
Tony

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How to generate DICOM JPEG compression image without JFIF header

#4 Post by Michael Onken »

Hi,

maybe the file you are compression is already JPEG compressed so your API calls do not have any effect at all? Use the dcmdump tool and look at the Transfer Syntax denoted in the DICOM meta header to find out.

To create a JPEG-compressed DICOM file just use the tool dcmcjpeg from DCMTK. It compresses an existing uncompressed DICOM file to JPEG transfer syntax(es). You just need to call

Code: Select all

dcmcjpeg input.dcm output.dcm
where input.dcm is the uncompressed input DICOM file and output.dcm is the desired JPEG-compressed output filename.

Best,
Michael

zhangfubin119
Posts: 4
Joined: Mon, 2019-04-22, 10:51

Re: How to generate DICOM JPEG compression image without JFIF header

#5 Post by zhangfubin119 »

Michael,

Thanks for your comments.

I try to compress my original DICOM file(Un-compression, XA, MONOCHROME2) to JPEG transfer syntax with "dcmcjpeg input.dcm output.dcm". And I found there still is APP0 info " FF E0 00 10 4A 46 49 46 00 01 01 00 00 01 00 01 00 00" in output.dcm. Such file with APP0 info cannot be de-compressed by other DICOM tool such as JDICOM.

I want to confirm if compressed DICOM file with APP0 info is correct or not and why all other sample compression DICOM files I get from internet do not include APP0 info?

Could you please send me sample compressed DICOM file(XA, MONOCHROME2)which is compressed by DCMTK? I want to check if APP0 info exist.
Thanks so much for your help.

Tony

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How to generate DICOM JPEG compression image without JFIF header

#6 Post by Michael Onken »

Hi Tony,

I think you are right, the JFIF header is in the file. I actually though it's not inside, sorry for misdirecting you. I had a different behaviour in mind since the img2dcm tool removes the JFIF header when converting JPEG to DICOM.

It is not possible to disable the existance of JFIF header information (FF D8 FF E0...) in files produced by the DCMTK JPEG compressor. However, note that as I stated earlier, that this behaviour is covered by the DICOM standard.

I uploaded an image (XA, MONOCHROME2, originally found on the Internet) compressed by DCMTK here: http://dicom.guru/download/xa_jpeg_lossless.dcm .

Best regards,
Michael

zhangfubin119
Posts: 4
Joined: Mon, 2019-04-22, 10:51

Re: How to generate DICOM JPEG compression image without JFIF header

#7 Post by zhangfubin119 »

Michael,

Thanks so much for your confirmation and sample image.

I found a solution that there is no APP0 info( FF E0...) in compressed JPEG file by DCMTK. My test file is XA image with photo metric interpretation "MONOCHROME2".
My solution is:
1, Set value of tag PhotoMetricInterpretation(0028,0004) to null before compressing like following:

Code: Select all

	dataset->findAndGetElement(DCM_PhotometricInterpretation, pPhotometric);
	pPhotometric->putString("");
   
2, Compress data like following:

Code: Select all

	dataset->chooseRepresentation(EXS_JPEGProcess14V1, &params);
   
3,Reset value of tag PhotoMetricInterpretation(0028,0004) to "MONOCHROME2".

As my solution, there will be no APP0 info(FF E0...) in compressed JPEG file. And compressed file can be decompressed by other storageSCP tool such "JDICOM". Could you please confirm if my solution is feasible or not?

Tony

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How to generate DICOM JPEG compression image without JFIF header

#8 Post by Michael Onken »

I tried a file with empty Photometric Interpretation with DCMTK's dcmcjpeg tool (which does basically the same as calling changeRepresentation) and for me the JFIF information is present in the resulting file. My first impression from looking at the JPEG compressor code is that it always writes such markers. Are you sure your call to changeRepresentation() actually works at all?

Maybe my DCMTK colleague Marco knows by heart, since he wrote the code many years ago.

I find it hard to imagine that JDICOM and other tools cannot decompress files with such JPEG markers. Maybe something else is fishy in your code. Maybe you should also try dcmcjpeg to compress your uncompressed file (dcmcjpeg uncompressed.dcm jpeg.dcm) and then try to send/use that with JDICOM.

Best regards,
Michael

Post Reply

Who is online

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