Getting dicom header data

53 views
Skip to first unread message

Nathaniel

unread,
Dec 5, 2012, 1:01:43 PM12/5/12
to ruby-...@googlegroups.com
Hi,

Sorry if this is a repeat post, I can't seem to find the last one I tried to post.
I want to use the dicim gem to help load dicim header data into a database. Basically, for a given dicom file, I want to generate a N-by-3 array, where the columns are the Tag ID, Tag Name, and Tag Value. I imagine that this is very simple to do, but I'm relatively new to Ruby and I'm a bit lost with this gem. It would be much appreciate if someone could provide a concrete example that does something like:

def get_dicom_headers_array

  header_array = []

  ObjectSpace.each_object(DICOM::DictionaryElement) do |e|

    header_array.push( [ e.tag_id, e.tag_name, e.tag_value  ] )

  end

  header_array

end


Thanks.

Christoffer Lervåg

unread,
Dec 5, 2012, 5:15:02 PM12/5/12
to ruby-...@googlegroups.com
Hello Nathaniel

If you want to extract the tags, names and values of all top level data elements from a particular DICOM file, you could do something like this:

require 'dicom'
dcm = DICOM::DObject.read('file.dcm')
ary = dcm.elements.collect {|element| [element.tag, element.name, element.value]}

That would give you the data in an array to transfer to a database. Do be aware that content of DICOM files vary a lot, and it might not be easy to represent mixed source DICOM data in an ordinary SQL database setup. If you run into any problems in this regard, you may want to check out Simon's work on transferring DICOM data to a CouchDB non-SQL database [1].

Best regards,
Reply all
Reply to author
Forward
0 new messages