package com.bla;
import org.dcm4che3.image.BufferedImageUtils;
import org.dcm4che3.imageio.plugins.dcm.DicomImageReadParam;
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
public class Example {
private static ImageReader imageReader;
private static int overlayActivationMask = 0xffff;
private static int overlayGrayscaleValue = 0xffff;
public static void main(String[] args) throws IOException {
imageReader =
ImageIO.getImageReadersByFormatName("DICOM").next();
convert(new File("/1236Ani.dcm"), new File("/1236Ani.jpeg"));
}
private static void convert(File src, File dest) throws IOException {
try (ImageInputStream iis = ImageIO.createImageInputStream(src)) {
BufferedImage bi = readImage(iis);
bi = convert(bi);
dest.delete();
try (ImageOutputStream ios = ImageIO.createImageOutputStream(dest)) {
writeImage(ios, bi);
}
}
}
private static BufferedImage convert(BufferedImage bi) {
ColorModel cm = bi.getColorModel();
return cm.getNumComponents() == 3 ? BufferedImageUtils.convertToIntRGB(bi) : bi;
}
private static BufferedImage readImage(ImageInputStream iis) throws IOException {
imageReader.setInput(iis);
return imageReader.read(0, readParam());
}
private static ImageReadParam readParam() {
DicomImageReadParam param =
(DicomImageReadParam) imageReader.getDefaultReadParam();
// param.setWindowCenter(windowCenter);
// param.setWindowWidth(windowWidth);
// param.setAutoWindowing(autoWindowing);
// param.setWindowIndex(windowIndex);
// param.setVOILUTIndex(voiLUTIndex);
// param.setPreferWindow(preferWindow);
// param.setPresentationState(prState);
param.setOverlayActivationMask(overlayActivationMask);
param.setOverlayGrayscaleValue(overlayGrayscaleValue);
return param;
}
private static void writeImage(ImageOutputStream ios, BufferedImage bi)
throws IOException {
ImageWriter imageWriter;
Iterator<ImageWriter> imageWriters =
ImageIO.getImageWritersByFormatName("JPEG");
imageWriter = imageWriters.next();
imageWriter.setOutput(ios);
imageWriter.write(null, new IIOImage(bi, null, null), imageWriter.getDefaultWriteParam());
}
}
--
You received this message because you are subscribed to the Google Groups "dcm4che" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dcm4che+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dcm4che/59d7498c-61db-46d6-bb59-b50af59172d1%40googlegroups.com.
--You received this message because you are subscribed to the Google Groups "dcm4che" group.To unsubscribe from this group and stop receiving emails from it, send an email to dcm4che+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dcm4che/95e3651f-bf7d-478b-b31d-3031af82f1b4%40googlegroups.com.