Method: RTKIT::Image#load_pixel_data

Defined in:
lib/rtkit/image.rb

#load_pixel_data(dcm) ⇒ Object

Transfers the pixel data, as well as the related image properties and the DObject instance itself, to the Image instance.

Parameters

  • dcm – A DICOM object containing image data that will be applied to the Image instance.

Raises:



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/rtkit/image.rb', line 162

def load_pixel_data(dcm)
  raise ArgumentError, "Invalid argument 'dcm'. Expected DObject, got #{dcm.class}." unless dcm.is_a?(DICOM::DObject)
  raise ArgumentError, "Invalid argument 'dcm'. Expected an image related modality, got #{dcm.value(MODALITY)}." unless IMAGE_MODALITIES.include?(dcm.value(MODALITY))
  # Set attributes common for all image modalities, i.e. CT, MR, RTDOSE & RTIMAGE:

  @dcm = dcm
  @narray = dcm.narray
  @date = dcm.value(IMAGE_DATE)
  @time = dcm.value(IMAGE_TIME)
  @uid = dcm.value(SOP_UID)
  @columns = dcm.value(COLUMNS)
  @rows = dcm.value(ROWS)
  # Some difference in where we pick our values depending on if we have an RTIMAGE or another type:

  if @series.modality == 'RTIMAGE'
    image_position = dcm.value(RT_IMAGE_POSITION).split("\\")
    raise "Invalid DICOM image: 2 basckslash-separated values expected for RT Image Position (Patient), got: #{image_position}" unless image_position.length == 2
    @pos_x = image_position[0].to_f
    @pos_y = image_position[1].to_f
    @pos_slice = nil
    spacing = dcm.value(IMAGE_PLANE_SPACING).split("\\")
    raise "Invalid DICOM image: 2 basckslash-separated values expected for Image Plane Pixel Spacing, got: #{spacing}" unless spacing.length == 2
    @col_spacing = spacing[1].to_f
    @row_spacing = spacing[0].to_f
  else
    image_position = dcm.value(IMAGE_POSITION).split("\\")
    raise "Invalid DICOM image: 3 basckslash-separated values expected for Image Position (Patient), got: #{image_position}" unless image_position.length == 3
    @pos_x = image_position[0].to_f
    @pos_y = image_position[1].to_f
    self.pos_slice = image_position[2].to_f
    spacing = dcm.value(SPACING).split("\\")
    raise "Invalid DICOM image: 2 basckslash-separated values expected for Pixel Spacing, got: #{spacing}" unless spacing.length == 2
    @col_spacing = spacing[1].to_f
    @row_spacing = spacing[0].to_f
    raise "Invalid DICOM image: Direction cosines missing (DICOM tag '#{IMAGE_ORIENTATION}')." unless dcm.exists?(IMAGE_ORIENTATION)
    @cosines = dcm.value(IMAGE_ORIENTATION).split("\\").collect {|val| val.to_f} if dcm.value(IMAGE_ORIENTATION)
    raise "Invalid DICOM image: 6 values expected for direction cosines (DICOM tag '#{IMAGE_ORIENTATION}'), got #{@cosines.length}." unless @cosines.length == 6
  end
end