lib/metamri/raw_image_file.rb in metamri-0.1.22 vs lib/metamri/raw_image_file.rb in metamri-0.1.23
- old
+ new
@@ -1,9 +1,10 @@
-
+require 'pp'
require 'rubygems';
require 'yaml';
require 'sqlite3';
+require 'dicom'
=begin rdoc
Implements a collection of metadata associated with a raw image file. In
this case, by image we mean one single file. For the case of Pfiles one file
corresponds to a complete 4D data set. For dicoms one file corresponds to a single
@@ -15,10 +16,11 @@
class RawImageFile
#:stopdoc:
MIN_HDR_LENGTH = 400
DICOM_HDR = "dicom_hdr"
RDGEHDR = "rdgehdr"
+ RUBYDICOM_HDR = "rubydicom"
MONTHS = {
:jan => "01", :feb => "02", :mar => "03", :apr => "04", :may => "05",
:jun => "06", :jul => "07", :aug => "08", :sep => "09", :oct => "10",
:nov => "11", :dec => "12"
}
@@ -59,10 +61,18 @@
attr_reader :rep_time
# Number of bold reps in the complete functional task run.
attr_reader :bold_reps
# Import Warnings - Fields that could not be read.
attr_reader :warnings
+ # Serialized RubyDicomHeader Object (for DICOMs only)
+ attr_reader :dicom_header
+ # DICOM Sequence UID
+ attr_reader :dicom_sequence_uid
+ # DICOM Series UID
+ attr_reader :dicom_series_uid
+ # DICOM Study UID
+ attr_reader :dicom_study_uid
=begin rdoc
Creates a new instance of the class given a path to a valid image file.
Throws IOError if the file given is not found or if the available header reading
@@ -80,11 +90,10 @@
@warnings = []
# try to read the header, raise an IOError if unsuccessful
begin
@hdr_data, @hdr_reader = read_header(absfilepath)
- #puts "@hdr_data: #{@hdr_data}; @hdr_reader: #{@hdr_reader}"
rescue Exception => e
raise(IOError, "Header not readable for file #{@filename}. #{e}")
end
# file type is based on file name but only if the header was read successfully
@@ -248,16 +257,19 @@
"rmr_number = '#{@rmr_number}' AND timestamp = '#{@timestamp.to_s}' AND filename = '#{@filename}'"
end
=begin rdoc
Reads the file header using one of the available header reading utilities.
-Returns both the header data as a one big string, and the name of the utility
+Returns both the header data as either a RubyDicom object or one big string, and the name of the utility
used to read it.
Note: The rdgehdr is a binary file; the correct version for your architecture must be installed in the path.
=end
def read_header(absfilepath)
+ # header = DICOM::DObject.new(absfilepath)
+ # return [header, RUBYDICOM_HDR] if defined? header.read_success && header.read_success
+
header = `#{DICOM_HDR} '#{absfilepath}' 2> /dev/null`
#header = `#{DICOM_HDR} #{absfilepath}`
if ( header.index("ERROR") == nil and
header.chomp != "" and
header.length > MIN_HDR_LENGTH )
@@ -290,13 +302,23 @@
Parses the header data and extracts a collection of instance variables. If
@hdr_data and @hdr_reader are not already availables, this function does nothing.
=end
def import_hdr
raise(IndexError, "No Header Data Available.") if @hdr_data == nil
- dicom_hdr_import if (@hdr_reader == "dicom_hdr")
- rdgehdr_import if (@hdr_reader == "rdgehdr")
+ case @hdr_reader
+ when "rubydicom" then rubydicom_hdr_import
+ when "dicom_hdr" then dicom_hdr_import
+ when "rdgehdr" then rdgehdr_import
+ end
end
+
+=begin rdoc
+Extract a collection of metadata from @hdr_data retrieved using RubyDicom
+=end
+def rubydicom_hdr_import
+
+end
=begin rdoc
Extracts a collection of metadata from @hdr_data retrieved using the dicom_hdr
utility.
=end
\ No newline at end of file