LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   dcm4che2: is it possible to skip jai to use DicomImageReader? (http://www.linuxquestions.org/questions/programming-9/dcm4che2-is-it-possible-to-skip-jai-to-use-dicomimagereader-4175433727/)

eantoranz 10-23-2012 03:38 PM

dcm4che2: is it possible to skip jai to use DicomImageReader?
 
Hi!

I'm trying to process a simple dicom file using dcm4che2.

When I try to run a standalone application, if I provide it with a lot of jars in the classpath (dcm4che-core, commons-cli, dcm4che-image, dcm4che-imageio, jai_imageio, slf4j-api) I get to process the file successfully:

Code:

package org.dcm4che2.tool.dcm2jpg;

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Iterator;

import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;

/**
 * Copyright 2012 CPS Tecnologias de Informacion
 * <p>
 * All rights reserved
 * <p>
 * <p>
 *
 * @author Edmundo Carmona <ecarmona@cps.la>
 *
 */

public class Straight {

        /**
        * @param args
        */
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                try {
                        File src = new File(
                                        "/home/antoranz/Documentos/dicom/samples/matlab/examples/sample_data/DICOM/digest_article/brain_002.dcm");
                        File dst = new File(
                                        "/home/antoranz/Descargas/java/dcm4chee/src/dcm4che-2.0.26/dcm4che-tool/dcm4che-tool-dcm2jpg/src/output/prueba.jpg");
                       
                        Iterator<ImageReader> iter = ImageIO
                                        .getImageReadersByFormatName("DICOM");
                        ImageReader reader = iter.next();
                        ImageInputStream iis = ImageIO.createImageInputStream(src);
                        reader.setInput(iis, false);
                        System.err.println("This image has " + reader.getNumImages(false)
                                        + " images");
                        for (int i = 0; i < reader.getNumImages(false); i++) {
                                BufferedImage bi = reader.read(i);
                                System.err.println("Read image " + i);
                                System.err.println("\tHeight: " + bi.getHeight());
                                System.err.println("\tWidth: " + bi.getWidth());
                                String[] properties = bi.getPropertyNames();
                                if (properties != null) {
                                        for (int j = 0; j < properties.length; j++) {
                                                System.out.println("\t" + properties[j] + "="
                                                                + bi.getProperty(properties[j]));
                                        }
                                }
                        }

                        /*
                        * while (iter.hasNext()) {
                        * System.err.println("Un reader de la imagen"); ImageReader reader
                        * = iter.next();
                        *
                        * }
                        */
                } catch (Exception e) {
                        e.printStackTrace();
                        System.exit(1);
                }

        }
}

Great.... now, I try to do basically the same thing in a servlet (application running in tomcat) I get a NoSuchElementException when I ask for the DICOM reader. I have checked file by file that the jars I was talking about before are actually in tomcat's libs and they are. Why is that?

What I'm wondering is if it's possible to skip jai altogether and work with DicomImageReader directly somehow?

Thanks in advance.

eantoranz 10-23-2012 03:56 PM

I solved it by calling ImageIO.scanForPlugins() before ImageIO.getImageReadersByFormatName()


All times are GMT -5. The time now is 11:32 PM.