Jeesmol Joseph
Jeesmol Joseph

Reputation: 1

to extract image and meta data from DICOM image using java

i am trying to extract image and metadata from dicom image using java on windows platform. i am new in dcm4che. my code is

i am getting error

Exception in thread "main" java.lang.NoClassDefFoundError:     org/dcm4che2/image/PartialComponentSampleModel
at org.dcm4che2.imageioimpl.plugins.dcm.DicomImageReaderSpi.createReaderInstance(DicomImageReaderSpi.java:146)
at javax.imageio.spi.ImageReaderSpi.createReaderInstance(ImageReaderSpi.java:320)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:529)
at javax.imageio.ImageIO$ImageReaderIterator.next(ImageIO.java:513)
at miec.extraction.extraction.extractionD(extraction.java:32)
at miec.MIEC.main(MIEC.java:46)
Caused by: java.lang.ClassNotFoundException: org.dcm4che2.image.PartialComponentSampleModel
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more

please help me... which all jar files should i include..

Upvotes: 0

Views: 2187

Answers (1)

Deepak Kumar
Deepak Kumar

Reputation: 1044

Use PixelMed
Here the example

import com.pixelmed.dicom.Attribute;
import com.pixelmed.dicom.AttributeList;
import com.pixelmed.dicom.AttributeTag;
import com.pixelmed.dicom.TagFromName;
import com.pixelmed.display.SourceImage;


public class DisplayImageTagsToConsole {

private static AttributeList list = new AttributeList();
public static void readDcmFile() {
    String dicomFile = "E:\\eye\\demo12.dcm";

    try {
        list.read(dicomFile);
        System.out.println("Patient Name:" + getTagInformation(TagFromName.PatientName));
            System.out.println("Patient ID:" + getTagInformation(TagFromName.PatientID));
            System.out.println("Transfer Syntax:" + getTagInformation(TagFromName.TransferSyntaxUID));
        System.out.println("SOP Class:" + getTagInformation(TagFromName.SOPClassUID));
        System.out.println("Modality:" + getTagInformation(TagFromName.Modality));
        System.out.println("Samples Per Pixel:" + getTagInformation(TagFromName.SamplesPerPixel));
        System.out.println("Photometric Interpretation:" + getTagInformation(TagFromName.PhotometricInterpretation));
        System.out.println("Pixel Spacing:" + getTagInformation(TagFromName.PixelSpacing));
        System.out.println("Bits Allocated:" + getTagInformation(TagFromName.BitsAllocated));
        System.out.println("Bits Stored:" + getTagInformation(TagFromName.BitsStored));
        System.out.println("High Bit:" + getTagInformation(TagFromName.HighBit));
        SourceImage img = new com.pixelmed.display.SourceImage(list);
        System.out.println("Number of frames " + img.getNumberOfFrames());
        System.out.println("Width " + img.getWidth());//all frames will have same width
        System.out.println("Height " + img.getHeight());//all frames will have same height  
        System.out.println("Is Grayscale? " + img.isGrayscale());
        System.out.println("Pixel Data present:" + (list.get(TagFromName.PixelData) != null));

    } catch (Exception e) {
        e.printStackTrace();
    }
}

private static String getTagInformation(AttributeTag attrTag) {
    return Attribute.getDelimitedStringValuesOrEmptyString(list, attrTag);
  }
}

Upvotes: 1

Related Questions