写点什么

dcm4che 解析 修改 保存 dicom 文件

作者:JefferLiu
  • 2023-01-17
    辽宁
  • 本文字数:3681 字

    阅读完需:约 12 分钟

public static String dicomParse(String filePath) {
File srcFile = new File(filePath); if(!isDicom(srcFile)){ return " not dicom "; }
Attributes dcmObj; Attributes fmi; DicomInputStream din; DicomInfo dicomInfo = null;
try { din = new DicomInputStream(srcFile);
//din.readDataset(-1, -1); dcmObj = din.readDataset(); fmi = din.readFileMetaInformation();
// patient String patientName = dcmObj.getString(Tag.PatientName); String patientId = dcmObj.getString(Tag.PatientID); String patientSex = dcmObj.getString(Tag.PatientSex); String patientAge = dcmObj.getString(Tag.PatientAge); String patientBirthDay = dcmObj.getString(Tag.PatientBirthDate);
//Station String manufacturer = dcmObj.getString(Tag.Manufacturer); String modelName = dcmObj.getString(Tag.ManufacturerModelName); String stationName = dcmObj.getString(Tag.StationName);
//Study String studyInstanceUID = dcmObj.getString(Tag.StudyInstanceUID); String studyDate = dcmObj.getString(Tag.StudyDate); String studyTime = dcmObj.getString(Tag.StudyTime); String studyID = dcmObj.getString(Tag.StudyID); String accessionNumber = dcmObj.getString(Tag.AccessionNumber); String studyDescription = dcmObj.getString(Tag.StudyDescription);
//Series String seriesInstanceUID = dcmObj.getString(Tag.SeriesInstanceUID); String seriesNumber = dcmObj.getString(Tag.SeriesNumber); String modality = dcmObj.getString(Tag.Modality); String institutionName = dcmObj.getString(Tag.InstitutionName); String institutionalDepartmentName = dcmObj.getString(Tag.InstitutionalDepartmentName); String seriesDescription = dcmObj.getString(Tag.SeriesDescription); String bodyPartExamined = dcmObj.getString(Tag.BodyPartExamined);
//Object
//DICOM Object String SOPInstanceUID = dcmObj.getString(Tag.SOPInstanceUID); String imageType = dcmObj.getString(Tag.ImageType); // ORIGINAL\PRIMARY\AXIAL\HELICAL String SOPClassUID = dcmObj.getString(Tag.SOPClassUID); // 1.2.840.10008.5.1.4.1.1.2 String transferSyntaxUID = dcmObj.getString(Tag.TransferSyntaxUID); //1.2.840.10008.1.2.1 String instanceNumber = dcmObj.getString(Tag.InstanceNumber); String photometricInterpretation = dcmObj.getString(Tag.PhotometricInterpretation); String samplesPerPixel = dcmObj.getString(Tag.SamplesPerPixel); String pixelRepresentation = dcmObj.getString(Tag.PixelRepresentation); String columns = dcmObj.getString(Tag.Columns); String rows = dcmObj.getString(Tag.Rows); String bitsAllocated = dcmObj.getString(Tag.BitsAllocated); String bitsStored = dcmObj.getString(Tag.BitsStored);
String imagePlane = dcmObj.getString(Tag.ImagePlanePixelSpacing); // ? String pixelSpacing = dcmObj.getString(Tag.PixelSpacing); String sliceLocation = dcmObj.getString(Tag.SliceLocation); String sliceThickness = dcmObj.getString(Tag.SliceThickness); String imagePosition = dcmObj.getString(Tag.ImagePosition); String imageOrientation = dcmObj.getString(Tag.ImageOrientation);
dicomInfo = DicomInfo.builder() .patientName(patientName) .patientAge(patientAge) .patientBirthDay(patientBirthDay) .patientId(patientId) .patientSex(patientSex)
.manufacturer(manufacturer) .modelName(modelName) .stationName(stationName)
.studyInstanceUID(studyInstanceUID) .studyDate(studyDate) .studyTime(studyTime) .studyID(studyID) .accessionNumber(accessionNumber) .studyDescription(studyDescription)
.seriesInstanceUID(seriesInstanceUID) .seriesNumber(seriesNumber) .modality(modality) .institutionName(institutionName) .institutionalDepartmentName(institutionalDepartmentName) .seriesDescription(seriesDescription) .bodyPartExamined(bodyPartExamined)
.SOPInstanceUID(SOPInstanceUID) .imageType(imageType) // ORIGINAL\PRIMARY\AXIAL\HELICAL .SOPClassUID(SOPClassUID) // 1.2.840.10008.5.1.4.1.1.2 .transferSyntaxUID(transferSyntaxUID) //1.2.840.10008.1.2.1 .instanceNumber(instanceNumber) .photometricInterpretation(photometricInterpretation) .samplesPerPixel(samplesPerPixel) .pixelRepresentation(pixelRepresentation) .columns(columns) .rows(rows) .bitsAllocated(bitsAllocated) .imagePlane(imagePlane) .pixelSpacing(pixelSpacing) .sliceLocation(sliceLocation) .sliceThickness(sliceThickness) .imagePosition(imagePosition) .imageOrientation(imageOrientation) .build();

din.close();
File targetFile = null; if(folderOptionInfo.getCoverFlag() == 0){ targetPath = filePath.replace(folderOptionInfo.getSourceFolder(), folderOptionInfo.getTargetFolder()); File file = new File(targetPath); if(!file.exists()) { FileUtils.touch(new File(targetPath)); } targetFile = new File(targetPath); }else { targetPath = srcFile.getAbsolutePath(); targetFile = srcFile; }
DicomOutputStream dos = new DicomOutputStream(targetFile); dos.writeDataset(fmi, dcmObj); dos.finish(); dos.flush(); dos.close(); result = targetPath + " OK"; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; }
复制代码

DICOM(Digital Imaging and Communications in Medicine)即医学数字成像和通信,是医学图像和相关信息的国际标准(ISO 12052)。它定义了质量能满足临床需要的可用于数据交换的医学图像格式。 [1] 

DICOM 被广泛应用于放射医疗,心血管成像以及放射诊疗诊断设备(X射线CT核磁共振,超声等),并且在眼科和牙科等其它医学领域得到越来越深入广泛的应用。在数以万计的在用医学成像设备中,DICOM 是部署最为广泛的医疗信息标准之一。当前大约有百亿级符合 DICOM 标准的医学图像用于临床使用。

自从 1985 年 DICOM 标准第一版发布以来,DICOM 给放射学实践带来了革命性的改变,X 光胶片被全数字化的工作流程所代替。就像 Internet 成为信息传播应用的全新平台,DICOM 使“改变临床医学面貌”的高级医学图像应用成为可能。比如在急诊科中,心脏负荷测试,乳腺癌的检查,DICOM 为医生和病人服务,是医学成像有效工作的标准。

用户头像

JefferLiu

关注

复杂的东西简单讲,简单的东西深刻讲。 2018-08-21 加入

已昏懒人

评论

发布
暂无评论
dcm4che 解析 修改 保存 dicom文件_JefferLiu_InfoQ写作社区