package com.testone;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import org.dcm4che3.data.Attributes;
import org.dcm4che3.imageio.plugins.dcm.DicomImageReadParam;
import org.dcm4che3.util.SafeClose;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class Dcm2jpgIOStreamOutput {
private final ImageReader imageReader = ImageIO.getImageReadersByFormatName("DICOM").next();
private float windowCenter;
private float windowWidth;
private boolean autoWindowing = true;
private int windowIndex;
private int voiLUTIndex;
private boolean preferWindow = true;
private Attributes prState;
private int overlayActivationMask = 0xffff;
private int overlayGrayscaleValue = 0xffff;
private int frame = 1;
public int getFrame() {
return frame;
}
public void setFrame(int frame) {
this.frame = frame;
}
public void setWindowCenter(float windowCenter) {
this.windowCenter = windowCenter;
}
public void setWindowWidth(float windowWidth) {
this.windowWidth = windowWidth;
}
public void setAutoWindowing(boolean autoWindowing) {
this.autoWindowing = autoWindowing;
}
public void setWindowIndex(int windowIndex) {
this.windowIndex = windowIndex;
}
public void setVoiLUTIndex(int voiLUTIndex) {
this.voiLUTIndex = voiLUTIndex;
}
public void setPreferWindow(boolean preferWindow) {
this.preferWindow = preferWindow;
}
public void setPrState(Attributes prState) {
this.prState = prState;
}
public void setOverlayActivationMask(int overlayActivationMask) {
this.overlayActivationMask = overlayActivationMask;
}
public void setOverlayGrayscaleValue(int overlayGrayscaleValue) {
this.overlayGrayscaleValue = overlayGrayscaleValue;
}
public void convert(File src, File dest) throws IOException{
Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("DICOM");
ImageReader reader = iter.next();
ImageInputStream iis = ImageIO.createImageInputStream(src);
BufferedImage bi;
OutputStream out = null;
try{
reader.setInput(iis, false);
bi = readImage(iis);
if (bi == null) {
System.out.println("\nError: " + src + " - couldn't read!");
return;
}
out = new BufferedOutputStream(new FileOutputStream(dest));
JPEGImageEncoder enc = JPEGCodec.createJPEGEncoder(out); //这里也可以使用流将图像导出到web应用,用来搭建web版的PACS等。
enc.encode(bi);
}finally{
SafeClose.close(iis);
SafeClose.close(out);
}
}
private 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 BufferedImage readImage(ImageInputStream iis) throws IOException{
imageReader.setInput(iis);
return imageReader.read(frame -1, readParam());
}
}
debuk
- 粉丝: 4
- 资源: 11
最新资源
- 1.电力系统短路故障引起电压暂降 2.不对称短路故障分析 包括:共两份自编word+相应matlab模型 1.短路故障的发生频次以及不同类型短路故障严重程度,本文选取三类典型的不对称短路展开研究
- 开源基于51单片机的多功能智能闹钟设计,课设毕设借鉴参考
- 深度强化学习电气工程复现文章,适合小白学习 关键词:能量管理 深度学习 强化学习 深度强化学习 能源系统 优化调度 编程语言:python平台 主题:用于能源系统优化调度的深度强化学习算法的性能比较
- 泰州市2005-2024年近20年历史气象数据下载
- 盐城市2005-2024年近20年历史气象数据下载
- 连云港市2005-2024年近20年历史气象数据下载
- 南通市2005-2024年近20年历史气象数据下载
- 饿了么bxet参数算法
- 医护人员检测22-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- nvm desktop -4.0.5-x64-setup
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0