java dicom转换jpg_JAVA代码实现DICOM文件转换JPG

这是一个Java代码示例,演示如何解析DICOM文件并将其转换为JPG图像。程序使用了ij.plugin.DICOM类来读取DICOM文件,并通过ImageIO将BufferedImage写入JPEG格式。
摘要由CSDN通过智能技术生成

package com.example;

import java.awt.image.BufferedImage;

import java.io.File;

import javax.imageio.ImageIO;

import ij.plugin.DICOM;

/**

* dicom文件java解析,生成图片

* 不过这里不能解析压缩的dicom文件

*/

public class ImageDemo {

public static void main(String args[]) {

// create("test1.dcm"); //在本地目录生成test1.dcm.jpg图片文件

create2("D:\\dicom\\test3.dcm"); //在电脑dicom文件夹下生成test1.dcm.jpg图片文件

}

/**

* 根据dicom文件生成jpg图片

*

* 这里输入的是image文件夹的dicom文件名字,

* 运行即可得到一个jpg图片,显示的是dicom里面的图形

*/

private static void create(String fileName) {

try {

String projectPath = System.getProperty("user.dir");

//Check class DICOM

DICOM dicom = new DICOM();

String imagePath = projectPath + "\\image\\" + fileName;

dicom.run(imagePath);

BufferedImage bi = (BufferedImage) dicom.getImage();

int width = bi.getWidth();

int height = dicom.getHeight();

System.out.println("width: " + width + "\n" + "height: " + height);

imagePath = projectPath + "\\image\\" + fileName + ".jpg";

ImageIO.write(bi, "jpg", new File(imagePath));

System.out.println("Hehe,Game over!!!");

} catch (Exception e) {

System.out.println("错误" + e.getMessage());

}

}

/**

* 输入一个dicom文件的绝对路径和名字

* 获取一个jpg文件

*/

private static void create2(String filePath) {

try {

DICOM dicom = new DICOM();

dicom.run(filePath);

BufferedImage bi = (BufferedImage) dicom.getImage();

int width = bi.getWidth();

int height = dicom.getHeight();

System.out.println("width: " + width + "\n" + "height: " + height);

String imagePath = filePath + ".jpg";

ImageIO.write(bi, "jpg", new File(imagePath));

System.out.println("Hehe,Game over!!!");

} catch (Exception e) {

System.out.println("错误" + e.getMessage());

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值