当前位置:   article > 正文

jpg转dicom_dcm4che将jpg转化为dicom

dcm4che将jpg转化为dicom

工具类 

  1. package com.zhy.admin.util;
  2. import com.zhy.db.domain.medical.Medical;
  3. import com.zhy.db.util.StringUtil;
  4. import lombok.AllArgsConstructor;
  5. import lombok.Getter;
  6. import org.dcm4che3.tool.jpg2dcm.Jpg2Dcm;
  7. import java.io.File;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. /**
  11. * dcm工具
  12. *
  13. * @author zhaohy
  14. */
  15. public class Jpg2DcmUtil {
  16. /**
  17. * jpg转dcm
  18. *
  19. * @param jpgFilePath 图片地址
  20. * @param dcmFilePath 生成dcm路径
  21. */
  22. public static void jpgToDcm(String jpgFilePath, String dcmFilePath) {
  23. File file = new File(dcmFilePath.substring(0, dcmFilePath.lastIndexOf("/")));
  24. if (!file.exists() && !file.isDirectory()) {
  25. file.mkdirs();
  26. }
  27. String[] jd = {"--no-app", "--", jpgFilePath, dcmFilePath};
  28. Jpg2Dcm.main(jd);
  29. }
  30. /**
  31. * jpg转dcm
  32. *
  33. * @param jpgFilePath 图片地址
  34. * @param dcmFilePath 生成dcm路径
  35. * @param medical dcm其他信息
  36. */
  37. public static void jpgToDcm(String jpgFilePath, String dcmFilePath, Medical medical) {
  38. File file = new File(dcmFilePath.substring(0, dcmFilePath.lastIndexOf("/")));
  39. if (!file.exists() && !file.isDirectory()) {
  40. file.mkdirs();
  41. }
  42. List<String> list = new ArrayList<>(16);
  43. list.add("--no-app");
  44. if (StringUtil.isNotBlank(medical.getStudyInstanceUid())) {
  45. list.add("-m");
  46. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.studyInstanceUid.name()) + "=" + medical.getStudyInstanceUid());
  47. }
  48. if (StringUtil.isNotBlank(medical.getSeriesInstanceUid())) {
  49. list.add("-m");
  50. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.seriesInstanceUid.name()) + "=" + medical.getSeriesInstanceUid());
  51. }
  52. if (StringUtil.isNotBlank(medical.getModality())) {
  53. list.add("-m");
  54. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.modality.name()) + "=" + medical.getModality());
  55. }
  56. if (StringUtil.isNotBlank(medical.getPatientAge())) {
  57. list.add("-m");
  58. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.patientAge.name()) + "=" + medical.getPatientAge());
  59. }
  60. if (StringUtil.isNotBlank(medical.getPatientBirthDate())) {
  61. list.add("-m");
  62. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.patientBirthDate.name()) + "=" + medical.getPatientBirthDate());
  63. }
  64. if (StringUtil.isNotBlank(medical.getPatientId())) {
  65. list.add("-m");
  66. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.patientId.name()) + "=" + medical.getPatientId());
  67. }
  68. if (StringUtil.isNotBlank(medical.getPatientName())) {
  69. list.add("-m");
  70. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.patientName.name()) + "=" + medical.getPatientName());
  71. }
  72. if (StringUtil.isNotBlank(medical.getPatientSex())) {
  73. list.add("-m");
  74. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.patientSex.name()) + "=" + medical.getPatientSex());
  75. }
  76. if (StringUtil.isNotBlank(medical.getStudyDate())) {
  77. list.add("-m");
  78. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.studyDate.name()) + "=" + medical.getStudyDate());
  79. }
  80. if (StringUtil.isNotBlank(medical.getStudyDescription())) {
  81. list.add("-m");
  82. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.studyDescription.name()) + "=" + medical.getStudyDescription());
  83. }
  84. if (StringUtil.isNotBlank(medical.getBodyPartExamined())) {
  85. list.add("-m");
  86. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.bodyPartExamined.name()) + "=" + medical.getBodyPartExamined());
  87. }
  88. if (StringUtil.isNotBlank(medical.getSeriesDescription())) {
  89. list.add("-m");
  90. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.seriesDescription.name()) + "=" + medical.getSeriesDescription());
  91. }
  92. if (StringUtil.isNotBlank(medical.getSeriesTime())) {
  93. list.add("-m");
  94. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.seriesTime.name()) + "=" + medical.getSeriesTime());
  95. }
  96. if (StringUtil.isNotBlank(medical.getSopInstanceUid())) {
  97. list.add("-m");
  98. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.sopInstanceUid.name()) + "=" + medical.getSopInstanceUid());
  99. }
  100. if (StringUtil.isNotBlank(medical.getSliceLocation())) {
  101. list.add("-m");
  102. list.add(StringUtil.toUpperCaseFirstOne(Medical.Column.sliceLocation.name()) + "=" + medical.getSliceLocation());
  103. }
  104. list.add("--");
  105. list.add(jpgFilePath);
  106. list.add(dcmFilePath);
  107. Jpg2Dcm.main(list.toArray(new String[0]));
  108. }
  109. public static void main(String[] args) {
  110. List<File> fileList = FileUtil.getAllFile(new File("C:\\Users\\zhy\\Desktop\\Pictures"));
  111. fileList.forEach(file -> jpgToDcm(file.getPath(), file.getPath() + ".dcm"));
  112. }
  113. /**
  114. * 类型枚举
  115. */
  116. @Getter
  117. @AllArgsConstructor
  118. public enum Type {
  119. /**
  120. * dcm2jpg
  121. */
  122. TO_JPG(1, "dcm2jpg"),
  123. /**
  124. * jpg2dcm
  125. */
  126. TO_DCM(2, "jpg2dcm");
  127. private int code;
  128. private String name;
  129. }
  130. }

引用

  1. compile ('org.dcm4che.tool:dcm4che-tool-jpg2dcm-5.20.0'){
  2. exclude group: 'org.slf4j',module: 'slf4j-log4j12'
  3. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/520691
推荐阅读
相关标签
  

闽ICP备14008679号