没有合适的资源?快使用搜索试试~ 我知道了~
首页Java实现解析dcm医学影像文件并提取文件信息的方法示例
资源详情
资源评论
资源推荐
Java实现解析实现解析dcm医学影像文件并提取文件信息的方法示例医学影像文件并提取文件信息的方法示例
主要介绍了Java实现解析dcm医学影像文件并提取文件信息的方法,结合实例形式分析了java基于第三方库文件针对dcm医学影像文件的解析操作相关实
现技巧,需要的朋友可以参考下
本文实例讲述了Java实现解析dcm医学影像文件并提取文件信息的方法。分享给大家供大家参考,具体如下:
一、安装一、安装
首先去Github 下载源码,然后执行mvn install进行本地安装,Maven中央仓库,竟然没有该jar。。安装成功之后如下:
然后在POM.XML文件中引入该jar包:
<dependency>
<groupId>org.dcm4che</groupId>
<artifactId>dcm4che-core</artifactId>
<version>3.3.2</version>
</dependency>
二、测试类二、测试类
/**
* projectName: xxx
* fileName: DisplayTag.java
* packageName: com.xxxx.xxxx.common.util
* date: 2018-03-26 10:07
* copyright(c) 2017-2020 xxx公司
*/
package com.gz.medicine.common.util;
import java.awt.image.Raster;
import java.io.File;
import java.io.IOException;
import java.sql.Time;
import java.util.Arrays;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.dcm4che3.data.Attributes;
import org.dcm4che3.data.ElementDictionary;
import org.dcm4che3.data.Fragments;
import org.dcm4che3.data.Sequence;
import org.dcm4che3.data.Tag;
import org.dcm4che3.data.VR;
import org.dcm4che3.io.DicomEncodingOptions;
import org.dcm4che3.io.DicomInputStream;
import org.dcm4che3.io.DicomOutputStream;
import org.dcm4che3.util.SafeClose;
import java.awt.image.Raster;
import java.io.IOException;
import java.util.Arrays;
/**
* @version: V1.0
* @author: fendo
* @className: DisplayTag
* @packageName: com.xxxx.xxxx.common.util
* @description: Tag解析
* @data: 2018-03-26 10:07
**/
public final class DisplayTag {
private static Attributes obj=null, object =null;
private static DicomInputStream din;
private static double resultFactorDix;
private String result = null;
private Double result2 = null;
private String nom = null;
private String nounString = null;
private int val2 = 0;
private int valeurReturn;
private String nounUnit = null;
private static double resultFacteurDix = 0;
private Double valueSpatial = null;
private String nounUnitRatio = null;
private DicomInputStream dis;
private static final char[] HEX_DIGITS = {
'0' , '1' , '2' , '3' , '4' , '5' ,
'6' , '7' , '8' , '9' , 'A' , 'B' ,
'C' , 'D' , 'E' , 'F'
};
private DicomEncodingOptions encOpts = DicomEncodingOptions.DEFAULT;
private static ElementDictionary dict = ElementDictionary.getStandardElementDictionary();
public DisplayTag(File file ){
try {
setObject(loadDicomObject(file) );
} catch (IOException ex) {
Logger.getLogger(DisplayTag.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* Read metadata of Dicom 3.0
* @param f : input file
* @return Attributes
* @throws IOException
*/
public static Attributes loadDicomObject(File f) throws IOException {
if (f == null){
return null;
}else{
DicomInputStream dis = new DicomInputStream(f);
//attr.setSpecificCharacterSet("GBK");
return dis.readDataset(-1, -1);
}
}
/**
* Put attribut
* @param obj
*/
public void setObject(Attributes obj){
this.obj = obj;
}
/**
* Giving attribut of metadata
* @return
*/
public static Attributes getObject(){
return obj;
}
/**
* Display metadata
* @param file : file inout
* @throws IOException
*/
public String readTagDicom(File file) throws IOException{
din = new DicomInputStream(file);
object = din.readFileMetaInformation() ;
String value = object.toString();
object = din.readDataset(-1, -1);
return value;
}
/**
* Permet d'afficher l'heure d'une valeur dicom en standard international yyyy.mm.dd/ Permit display time in format yyyy.mm.dd
* @param Tag : valeur du tag / int tag
* @param valueBool : si true Format yyyy.mm.dd sinon format dd.mm.yyyy/ if true then format yyyy.mm.dd else dd.mm.yyyy
* @param valueNoun : "dot" mettre la date en format yyyy.mm.dd ou dd.mm.yyyy sinon en format yyyy mm dd ou dd mm yyyy/ "dot" put yyyy.mm.dd or dd.mm.dd or dd.mm.yyyy else yyyy mm or dd mm yyyy
* @return afficher le string du tag selon le standard international/ return string Date
* @throws IOException
*/
public String dicomDate(int Tag,boolean valueBool, String valueNoun) throws IOException{
if(getObject().contains(Tag)==true ){
String tagValue = getObject().getString(Tag);
String tagDayFomat = FormatDate(tagValue,valueBool,valueNoun);
return tagDayFomat;
}else{
return null;
}
}
/**
* Permet d'afficher l'heure d'une valeur dicom en standard international yyyy.mm.dd/ Permit display a time in metadata for yyyy.mm.dd
* @param object
* @param Tag : valeur du tag/ value of tag
* @param valueBool : si true Format yyyy.mm.dd sinon format dd.mm.yyyy/ if true format yyyy.mm.dd else dd.mm.yyyy
* @param valueNoun : "dot" mettre la date en format yyyy.mm.dd ou dd.mm.yyyy sinon en format yyyy mm dd ou dd mm yyyy/dot" put yyyy.mm.dd or dd.mm.dd or dd.mm.yyyy else yyyy mm or dd mm yyyy
* @return afficher le string du tag selon le standard international/ return string date
* @throws IOException
*/
public static String dicomDate(Attributes object , int Tag,boolean valueBool, String valueNoun) throws IOException{
String tagValue = object.getString(Tag);
String tagDayFomat = FormatDate(tagValue,valueBool,valueNoun);
return tagDayFomat;
}
/**
* Format tag
* @param Numero : String date
* @param valueBool : if true Format yyyy.mm.dd else format dd.mm.yyyy
* @param valueNoun : "dot" put the date in format yyyy.mm.dd or dd.mm.yyyy else in format yyyy mm dd or dd mm yyyy
* @return
*/
public static String FormatDate(String Numero, boolean valueBool,String valueNoun) {
if (Numero.matches("^[0-9]*$")) {//If la chaine de caractère est un nombre ou un chiffre
StringBuffer r = new StringBuffer();
if (valueBool ==true){//Format yyyy.mm.dd
for (int i = 0, j = Numero.length(); i < j; i++) {
r.append(Numero.charAt(i));
if ((i == 3)||(i == 5) ){
if(valueNoun == null ? "dot" == null : valueNoun.equals("dot")){
r.append('.');
}else{
r.append(' ');
}
}
}
return r.toString();
}else{
for (int i = 6, j =8; i<j; i++) {//jours
r.append(Numero.charAt(i));
if(i ==7 ){
if(valueNoun == null ? "dot" == null : valueNoun.equals("dot")){
r.append('.');
}else{
r.append(' ');
}
}
}
for (int i = 4, j =6; i<j; i++) {
r.append(Numero.charAt(i));//The first char value of the sequence is at index zero, the next at index one, and so on, as for array indexing.
if(i ==5 ){
if(valueNoun == null ? "dot" == null : valueNoun.equals("dot")){
r.append('.');
}else{
r.append(' ');
}
}
}
for (int i = 0, j =4; i<j; i++) {
r.append(Numero.charAt(i));//The first char value of the sequence is at index zero, the next at index one, and so on, as for array indexing.
}
return r.toString();
}
}
return Numero;
}
/**
* Read value tag of VR = DA
*
* If use setDicomObject(readDicomObject(File f)), and getHeaderDateValue(getDicomObject())
* @param tagNr "0000,0010"
* @return
*/
public Date getHeaderDateValue(String tagNr) {
return getHeaderDateValue(toTagInt(tagNr));
}
/**
* Read value tag of VR = DA
*
* @param tagNr see dcm4che2
* @return
*/
public Date getHeaderDateValue(int tagNr) {
return getObject().getDate(tagNr);
}
/**
* Converts the string representation of a header number
* e.g. 0008,0010 to the corresponding integer as 0x00080010
* as used in the @see org.dcm4che2.data.Tag
* @param headerNr e.g. 0008,0010
* @return 0x00080010 as int
*/
public static int toTagInt(String headerNr){
return Integer.parseInt(headerNr.replaceAll(",", ""), 16);
}
/**
* Read value tag of VR = DA
* @param tagNr
* @param dicomObj
* @return
*/
public Date getHeaderDateValue(int tagNr,Attributes dicomObj) {
return dicomObj.getDate(tagNr);
}
/**
* Read value tag of VR = DA
* @param tagNr :"0000,0010"
* @param dicomObj
* @return
*/
public Date getHeaderDateValue(String tagNr,Attributes dicomObj) {
return getHeaderDateValue(toTagInt(tagNr), dicomObj);
}
/**
* Remove string ^ in file dicom
* @param num
* @return
剩余13页未读,继续阅读
weixin_38570278
- 粉丝: 4
- 资源: 980
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0