NoSuchElementException

448 views
Skip to first unread message

Kevin Moray

unread,
May 2, 2016, 3:25:06 AM5/2/16
to dcm4che

Hello, 

I created a Swing application that convets DICOM into PNG file. Here's my method: 

public static DicomInfo extractDicomData(File file, File tempDirectory) {
  DicomInfo dicomInfo = new DicomInfo();
  try {
    BufferedImage image = null;
    ImageIO.scanForPlugins();
    Iterator iterator = ImageIO.getImageReadersByFormatName("DICOM");
    ImageReader reader = (ImageReader) iterator.next();
    DicomImageReadParam param = (DicomImageReadParam) reader.getDefaultReadParam();
    ImageInputStream iis = ImageIO.createImageInputStream(file);
    reader.setInput(iis, false);
    image = reader.read(0, param);
    iis.close();

    if (image == null) {
      LogFile.getInstance().log("error", "couln't read dicom image!");
      return null;
    }
    LogFile.getInstance().log("info", "Dicom file Loaded");
    File jpegFile = File.createTempFile("dicom", ".jpg", tempDirectory);
    LogFile.getInstance().log("info", "Temp file : " + jpegFile.getAbsolutePath());
    OutputStream output = new BufferedOutputStream(new FileOutputStream(jpegFile));

    ImageWriter writer = null;
    Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
    writer = (ImageWriter) iter.next();
    ImageOutputStream ios = ImageIO.createImageOutputStream(output);
    writer.setOutput(ios);
    ImageWriteParam iwparam = new JPEGImageWriteParam(Locale.getDefault());
    iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    iwparam.setCompressionQuality(Float.parseFloat(PropertiesCache.getInstance().getProperty("CompressionQuality")));
    writer.write(null, new IIOImage(image, null, null), iwparam);
    ios.flush();
    writer.dispose();
    ios.close();
    output.close();
    dicomInfo.setImage(jpegFile);
    dicomInfo.setSourcePath(file);
  } catch (Exception ex) {
    LogFile.getInstance().log("error", "No image available in this dicom file " + file.getName());
    LogFile.getInstance().log("Exception", ex.toString());
    ex.printStackTrace();
    return null;
  }

  try {
    DicomInputStream dicomInputStream = new DicomInputStream(file);
    DicomObject object = dicomInputStream.readDicomObject();
    dicomInfo.setStudyDate((Date) getMetaData(object, "Study Date", Types.DATE));
    dicomInfo.setStudyDescription((String) getMetaData(object, "Study Description", Types.VARCHAR));
    dicomInfo.setPatientName((String) getMetaData(object, "Patient’s Name", Types.VARCHAR));
    dicomInfo.setPatientId((Long) getMetaData(object, "Patient ID", Types.BIGINT));
    dicomInfo.setPatientBirthdate((Date) getMetaData(object, "Patient’s Birth Date", Types.DATE));
    dicomInfo.setPatientSex((String) getMetaData(object, "Patient’s Sex", Types.VARCHAR));
  } catch (IOException ex) {
    LogFile.getInstance().log("error", "unable to get METADATA");
    LogFile.getInstance().log("Exception", ex.getMessage());
    ex.printStackTrace();
  }

  return dicomInfo;
}

And i get this error:

java.util.NoSuchElementException
        at javax.imageio.spi.FilterIterator.next(Unknown Source)
        at javax.imageio.ImageIO$ImageReaderIterator.next(Unknown Source)
        at javax.imageio.ImageIO$ImageReaderIterator.next(Unknown Source)
        at be.fmpfbz.dicomupload.client.tools.DicomTools.extractDicomData(DicomTools.java:73)
        at be.fmpfbz.dicomupload.client.task.ExtractDicomInfoTask.doInBackground(ExtractDicomInfoTask.java:51)
        at be.fmpfbz.dicomupload.client.task.ExtractDicomInfoTask.doInBackground(ExtractDicomInfoTask.java:17)
        at javax.swing.SwingWorker$1.call(Unknown Source)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at javax.swing.SwingWorker.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.lang.Thread.run(Unknown Source)


Here is my MANIFEST.MF file:

Manifest-Version: 1.0
Main-Class: be.fmpfbz.dicomupload.client.DicomUpload
Built-By: Kevin MORAY
Created-By: Kevin MORAY
Specification-Title: Java Advanced Imaging Image I/O Tools
Specification-Version: 1.1
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: com.sun.media.imageio
Implementation-Version: 1.1
Implementation-Vendor: Sun Microsystems, Inc.

Do you have an idea ?
Reply all
Reply to author
Forward
0 new messages