img2dcm says F: Error converting file: Not a JPEG file

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
bruce.ho
Posts: 2
Joined: Wed, 2023-03-15, 09:25

img2dcm says F: Error converting file: Not a JPEG file

#1 Post by bruce.ho »

I installed dcmtk just fine. I am able to use img2dcm on any random jpg image and convert to a dcm file. But when I use dcmj2pnm to convert a dcm image into jpeg, then try to convert that image back to jpeg, I get this error message - F: Error converting file: Not a JPEG file

The jpeg image I converted is perfectly fine. I am able to open it up using Mac preview. I also tried the +on2 option to make the jpeg 16 bit, but the same result.


is there some option I have to specify?

bruce.ho
Posts: 2
Joined: Wed, 2023-03-15, 09:25

Re: img2dcm says F: Error converting file: Not a JPEG file

#2 Post by bruce.ho »

--write-jpeg option seems to do the trick. However, this converts the image into 8 bits and the pixel depth is lost.

I can add the +on2 option and get a 16 bit jpeg image, however, I can find no way to convert the jpeg back to dicom. It always says F: Error converting file: Not a JPEG file.

Does any one know how to achieve this?

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

Re: img2dcm says F: Error converting file: Not a JPEG file

#3 Post by Michael Onken »

Hi,

dcmj2pnm cannot write 16 bit JPEG (I think), option +on2 is short for --write-16-bit-png i.e. it will write PNG files.

Best regards,
Michael

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: img2dcm says F: Error converting file: Not a JPEG file

#4 Post by J. Riesmeier »

I can add the +on2 option and get a 16 bit jpeg image
No, +on2 creates a PNG image with 16 bits per sample. Here's the relevant excerpt from the dcmj2pnm manpage:

Code: Select all

  image format:
    +op   --write-raw-pnm       write 8-bit binary PGM/PPM (default for files)
    +opb  --write-8-bit-pnm     write 8-bit ASCII PGM/PPM (default for stdout)
    +opw  --write-16-bit-pnm    write 16-bit ASCII PGM/PPM
    +opn  --write-n-bit-pnm     [n]umber: integer
                                write n-bit ASCII PGM/PPM (1..32)
    +ob   --write-bmp           write 8-bit (monochrome) or 24-bit (color) BMP
    +obp  --write-8-bit-bmp     write 8-bit palette BMP (monochrome only)
    +obt  --write-24-bit-bmp    write 24-bit truecolor BMP
    +obr  --write-32-bit-bmp    write 32-bit truecolor BMP
    +ot   --write-tiff          write 8-bit (monochrome) or 24-bit (color) TIFF
    +on   --write-png           write 8-bit (monochrome) or 24-bit (color) PNG
    +on2  --write-16-bit-png    write 16-bit (monochrome) or 48-bit (color) PNG
    +oj   --write-jpeg          write 8-bit lossy JPEG (baseline)

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

Re: img2dcm says F: Error converting file: Not a JPEG file

#5 Post by Marco Eichelberg »

To add to what my colleagues already said, there is no such thing as a "16 bit JPEG", unless you consider the lossless JPEG encoding that nobody outside the medical world supports.
img2dcm expects an image using the Baseline lossy JPEG format (i.e. the JPEG format your camera or smart phone produces).

Post Reply

Who is online

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