Advertisement
4tolexx

dicom modification

May 15th, 2025
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.04 KB | None | 0 0
  1. # class DicomModification
  2. #   attr_reader :source, :overwrite, :remove
  3.  
  4. #   def initialize(source:, overwrite: {}, remove: [])
  5. #     @source = source
  6. #     @overwrite = overwrite
  7. #     @remove = remove
  8. #   end
  9.  
  10. #   def write_changes!
  11. #     # modify_tags(parsed_dicom)
  12. #     # remove_tags(parsed_dicom)
  13. #     tag_list = modify_tags(parsed_dicom) + remove_tags(parsed_dicom)
  14. #     run_dcmodify(tag_list)
  15. #   end
  16.  
  17. #   private
  18.  
  19. #   def parsed_dicom
  20. #     @parsed_dicom ||= DICOM::DObject.read(source)
  21. #   end
  22.  
  23. #   def modify_tags(dicom)
  24. #     # modifications = overwrite
  25. #     #                   .select { |tag, _| dicom.exists?(tag) }
  26. #     #                   .flat_map { |tag, value| ["-m", "#{tag}=#{value}"] }
  27. #     # run_dcmodify(modifications) unless modifications.empty?
  28. #     overwrite.flat_map { |tag, value| ["-m", "#{tag}=#{value}"] if dicom.exists?(tag) }
  29. #   end
  30.  
  31. #   def remove_tags(dicom)
  32. #     # removals = remove
  33. #     #              .select { |tag| dicom.exists?(tag) }
  34. #     #              .flat_map { |tag| ["-e", tag] }
  35. #     # run_dcmodify(removals) unless removals.empty?
  36. #     remove.flat_map { |tag| ["-e", tag] if dicom.exists?(tag) }
  37. #   end
  38.  
  39. #   def run_dcmodify(args)
  40. #     system("dcmodify", "+te", *args, source)
  41. #   end
  42. # end
  43.  
  44. # class DicomModification
  45. #   attr_reader :source, :overwrite, :remove
  46.  
  47. #   def initialize(source:, overwrite: {}, remove: [])
  48. #     @source = source
  49. #     @overwrite = overwrite
  50. #     @remove = remove
  51. #   end
  52.  
  53. #   def write_changes!
  54. #     tag_list = modify_tags(parsed_dicom) + remove_tags(parsed_dicom)
  55. #     run_dcmodify(tag_list)
  56. #   end
  57.  
  58. #   private
  59.  
  60. #   def parsed_dicom
  61. #     @parsed_dicom ||= DICOM::DObject.read(source)
  62. #   end
  63.  
  64. #   def modify_tags(dicom)
  65. #     overwrite.flat_map { |tag, value| ["-m", "#{tag}=#{value}"] if dicom.exists?(tag) }
  66. #   end
  67.  
  68. #   def remove_tags(dicom)
  69. #     remove.flat_map { |tag| ["-e", tag] if dicom.exists?(tag) }
  70. #   end
  71.  
  72. #   def run_dcmodify(args)
  73. #     system("dcmodify", "+te", *args, source)
  74. #   end
  75. # end
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement