convert to Jpeg a compressed DICOM image

1,562 views
Skip to first unread message

Thanasis Iliopoulos

unread,
Dec 15, 2015, 10:06:05 AM12/15/15
to dcm4che
Hi to the group!

i am converting my DICOM images to Jpeg using Dcm2Jpg utility class, however recently i faced the case where i need to convert some compressed DICOM images to Jpeg.

My code:

public void convertDcmToJpeg(File dcmObjFile, File jpgFile) throws IOException {

    Dcm2Jpg dcm2Jpg = new Dcm2Jpg();
    log.info("converting: " + dcmObjFile.getName() + " to jpeg: " + jpgFile.getName());
    try {
                dcm2Jpg.convert(dcmObjFile, jpgFile);
    }
    ...
}

where Dcm2Jpg is the original dcm4che utility class. The process fails on the two red/bold lines: 

public void convert(File src, File dest) throws IOException {
        log.info("file to be created: " + dest.getAbsolutePath());
        Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("DICOM");
        ImageReader reader = iter.next();
        DicomImageReadParam param = 
            (DicomImageReadParam) reader.getDefaultReadParam();
        param.setWindowCenter(center);
        param.setWindowWidth(width);
        param.setVoiLutFunction(vlutFct);
        param.setPresentationState(prState);
        param.setPValue2Gray(pval2gray);
        param.setAutoWindowing(autoWindowing);
        ImageInputStream iis = ImageIO.createImageInputStream(src);
        BufferedImage bi;  
        try {
            reader.setInput(iis, false);
            bi = reader.read(frame - 1, param);
            if (bi == null) {
                log.info("\nError: " + src + " - couldn't read!");
                return;
            }
            encodeByImageIO(bi, dest);
        } finally {
            CloseUtils.safeClose(iis);
        }
        log.info('.');
}

and the exception i get:

org.dcm4che2.data.ConfigurationError: No Image Reader of class com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReader available for format:jpeg
at org.dcm4che2.imageio.ImageReaderFactory.getReaderForTransferSyntax(ImageReaderFactory.java:99)
at org.dcm4che2.imageioimpl.plugins.dcm.DicomImageReader.initCompressedImageReader(DicomImageReader.java:410)
at org.dcm4che2.imageioimpl.plugins.dcm.DicomImageReader.initImageReader(DicomImageReader.java:395)
at org.dcm4che2.imageioimpl.plugins.dcm.DicomImageReader.read(DicomImageReader.java:636)
at b.e.a(Dcm2Jpg.java:179)
at l.i.a(ProcessDicomFiles.java:2020)
at l.i.b(ProcessDicomFiles.java:1992)
at l.i.j(ProcessDicomFiles.java:1626)
at g.a.execute(MainJob.java:87)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)

So, i am wondering how could i convert to JPEG compressed DICOM images. Do i have first have to de-compressed using the utility class Dcm2Dcm? If yes is there any examples... Which method of this class can be used for de-compressing DICOM images?

Any other parameters or details about dicom image decompression that i would need to know about?

Thanks in advace for you time!

sd...@rad365.com

unread,
Jan 12, 2016, 6:54:22 AM1/12/16
to dcm4che
Hi Thanasis,

I also faced same problem. You need to install JAI & JAI IO in your system and it'll work fine. 

Dimitri Pianeta

unread,
Jan 12, 2016, 11:04:11 AM1/12/16
to dcm4che

For java 8 isn't solver for imagei and JAI.

Dave Franken

unread,
Jan 13, 2016, 2:29:00 AM1/13/16
to dcm4che
What's important here is that the directory the clib_jiio.dll (for Windows) is in is actually added to your PATH (which makes Java add it to its library paths), not your CLASSPATH.

Thanasis Iliopoulos

unread,
Jan 23, 2017, 10:52:18 AM1/23/17
to dcm4che
Hi again ...

I have installed JAI/JAI-IO in my system and i think i am including all the necessary jar files in my project ...

However i keep receiving this error ... Can not convert a compressed dicom file (JPGLossless) to JPG ...



Below is my system / project info:

OS: Windows 64-bit
Java: 1.8.0_60 (JDK/JRE)

Jar files in my project (relative to JAI):
dcm4che-core-2.0.29.jar
dcm4che-image-2.0.29.jar
dcm4che-imageio-2.0.29.jar
dcm4che-imageio-rle-2.0.29.jar
jai-imageio.jar
clibwrapper_jiio.jar
jai-core.jar
jai-codec.jar

I have also included to PATH directory to which clib_jiio.dll is located ...

Am i missing anything?

Thanks

Thanasis Iliopoulos

unread,
Jan 23, 2017, 4:10:07 PM1/23/17
to dcm4che
Maybee this is the case?


First make sure you use 32 bit JVM on your Spring Framework Java Application.

C:\Program Files (x86)\Java\jdk1.7.0\jre\bin


So is this due to the fact that i use 64bit JDK for my project? 


I have the issue mentioned above only for "jpegloss" dicom compressed files. 



On Tuesday, 15 December 2015 17:06:05 UTC+2, Thanasis Iliopoulos wrote:
Reply all
Reply to author
Forward
0 new messages