Created
December 10, 2010 13:23
-
-
Save tshm/1bedf5afe9d47e4c8ddc to your computer and use it in GitHub Desktop.
dicom sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!env ruby | |
require 'fileutils' | |
require 'rubygems' | |
require 'dicom' | |
require 'ap' | |
SUID_TAG = "0020,000E" | |
LATE_TAG = "0020,0062" | |
VIEW_TAG = "0018,5101" | |
ACQN_TAG = "0020,0012" | |
files = Dir["*_SET*/DICOMOBJ/SYN*"] | |
#ap files; exit | |
#h = Hash.new([]) | |
h = {} | |
files.each do |fn| | |
o = DICOM::DObject.new(fn) | |
next unless o.read_success | |
id = o.value(SUID_TAG) | |
lr = o.value(LATE_TAG) | |
view = o.value(VIEW_TAG) | |
next unless view | |
h[id]=[] unless h[id] | |
h[id] << {:lr => lr, :view => view, :fn => fn, :an => o.value(ACQN_TAG)} | |
end | |
i = 0 | |
h.each do |k,v| | |
v.each do |hh| | |
ap name = "out/%04d_%s%s.dcm" % [i, hh[:lr], hh[:view]] | |
if File.exists?(name) | |
FileUtils.mv(name, name.gsub(/\.dcm/, '_0.dcm')) | |
end | |
FileUtils.cp(hh[:fn] ,name) | |
end | |
i+=1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment