Question

I am having some trouble displaying a dicom file. I have tried many things to display the picture onto the frame but all it does is make an error which is "image is empty". Any suggestions would be appreciated. (I know that the image is not empty and that it is able to access the image from the laptop).

Thank you.

Here is my code (which is coded in java):

class Open{
public static void main(String s) throws IOException{
    String [] array = s.split("/");
    String k = array[0];
    k+= "/";
    k += array[1];
    k+= "/";
    k += array[2];
    k+= "/";
    k+= array[3];
    k+= "/";
    k+= array[4];
    k+= "/";
    System.out.println(k);

    System.out.println(s.length());

    if(s.length() == 0){
        System.out.println("The path and filename are empty!");
        System.exit(0);
    }

    File source = new File(k, array[5]);

    final Image image = ImageIO.read(source);
    //final BufferedImage image = ImageIO.read(new File(k, array[5]));

    if(image == null){
        System.out.println("The image is empty or can't be read!");
        System.exit(0);
    }

    JFrame frame = new JFrame();
    final Rectangle bounds = new Rectangle(0,0,240, 240);

    JPanel panel = new JPanel();
    //{
//          public void paintComponent(Graphics g){
 ////               Rectangle box = g.getClipBounds();
 ////               ((Graphics2D)g).fill(box);
 ////               
////                if(bounds.intersects(box)){
//                  g.drawImage(image,0,0,null);
 ////               }
//          }
//      };

    JLabel b = new JLabel(new ImageIcon(image));
    panel.add(b);
    frame.getContentPane().add(panel);
    panel.setPreferredSize(new Dimension(300, 300));
    frame.pack();
    frame.setVisible(true);
}
}
Was it helpful?

Solution

You can do it with PixelMed. The documentation is pretty much non-existent, but there are javadocs.

If you primarily intend to display the image, you should be able to use SourceImage and SingleImagePanel from the com.pixelmed.display package to load and display the image. If you want to parse DICOM attributes, you could start with one of the read methods in com.pixelmed.dicom.AttributeList.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top