Skip to content

Instantly share code, notes, and snippets.

@tshm
Created December 10, 2010 13:23
Show Gist options
  • Save tshm/1bedf5afe9d47e4c8ddc to your computer and use it in GitHub Desktop.
Save tshm/1bedf5afe9d47e4c8ddc to your computer and use it in GitHub Desktop.
dicom sample
#!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