dcm4che2 - How do you adjust window center and window width?

120 views
Skip to first unread message

Collin Walling

unread,
Aug 17, 2015, 5:04:23 AM8/17/15
to dcm...@googlegroups.com
I am creating a DICOM image viewer using the dcm4che2 library.

I want to adjust the window center and window width of an image. I tried using the methods defined 
for the DicomImageReadParam class to do this as the DICOM file is being read from my disk, but 
nothing is happening to the image. A piece of the code I used is below:


    File myDicomFile = new File(imagePath);
    BufferedImage myJpegImage = null;

    Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("DICOM");

    ImageReader reader = (ImageReader) iter.next();

    DicomImageReadParam param = (DicomImageReadParam) reader.getDefaultReadParam();
        
    // Here is where I try to adjust the center and width
    param.setWindowCenter(center);
    param.setWindowWidth(width);

    // Read from the file and store it in the BufferedImage
    try {
        ImageInputStream iis = ImageIO.createImageInputStream(myDicomFile);
        reader.setInput(iis, false);
        myJpegImage = reader.read(0, param);
        iis.close();

        if (myJpegImage == null) {
            System.out.println("\nError: couldn't read dicom image!");
            return;
        }
        } catch (IOException e) {
        System.out.println("\nError: couldn't read dicom image!" + e.getMessage());
        return;
    }

// Below would be some swing code to display the BufferedImage on a frame.

Center and width are both predefined float variables.

I've also tried to run the dcm2jpg tool, providing the -c and -w arguments to see if I would
get any results, but to no avail.

Do the setWindowCenter and setWindowWidth actually affect the image at all? There is 
also a DicomImageReader class, maybe I should be using that instead of ImageReader?

Any advice would be appreciated.

Thank you.
- Collin

ChadN

unread,
Aug 21, 2015, 3:12:17 PM8/21/15
to dcm4che
You may also need

param.setAutoWindowing( false );

Otherwise, I think it computes the ww/wc and overrides what you entered in your param's.

Collin Walling

unread,
Aug 21, 2015, 3:41:57 PM8/21/15
to dcm4che
That seems to have done the trick... I should also note that I was attempting to apply these values to an
Ultrasound image, which I guess doesn't work too well?

Thanks for your post, I can work with it now. 
Reply all
Reply to author
Forward
0 new messages