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