Module: DICOM::ImageProcessor::DcmMiniMagick

Defined in:
lib/dicom/image_processor_mini_magick.rb

Overview

This module contains methods for interacting with pixel data using the mini_magick gem.

Class Method Summary collapse

Class Method Details

.decompress(blobs) ⇒ Array<MiniMagick::Image>, FalseClass

Creates image objects from an array of compressed, binary string blobs.



15
16
17
18
19
20
21
22
# File 'lib/dicom/image_processor_mini_magick.rb', line 15

def decompress(blobs)
  images = Array.new
  # We attempt to decompress the pixels using ImageMagick:

  blobs.each do |string|
    images << MiniMagick::Image.read(string)
  end
  return images
end

.export_pixels(image, photometry) ⇒ Array<Integer>

Note:

This feature is not available as of yet in the mini_magick image processor. If this feature is needed, please try another image processor (RMagick).

Extracts an array of pixels (integers) from an image object.

Raises:

  • (ArgumentError)


33
34
35
36
# File 'lib/dicom/image_processor_mini_magick.rb', line 33

def export_pixels(image, photometry)
  raise ArgumentError, "Expected MiniMagick::Image, got #{image.class}." unless image.is_a?(MiniMagick::Image)
  raise "Exporting pixels is not yet available with the mini_magick processor. Please try another image processor (RMagick)."
end

.im_map(photometry) ⇒ String

Converts a given DICOM photometry string to a mini_magick pixel map string.

Raises:

  • (ArgumentError)


57
58
59
60
61
62
63
64
65
66
# File 'lib/dicom/image_processor_mini_magick.rb', line 57

def im_map(photometry)
  raise ArgumentError, "Expected String, got #{photometry.class}." unless photometry.is_a?(String)
  if photometry.include?('COLOR') or photometry.include?('RGB')
    return 'rgb'
  elsif photometry.include?('YBR')
    return 'ybr'
  else
    return 'gray' # (Assuming monochromeX - greyscale)

  end
end

.import_pixels(blob, columns, rows, depth, photometry, format = 'png') ⇒ Magick::Image

Creates an image object from a binary string blob.



48
49
50
# File 'lib/dicom/image_processor_mini_magick.rb', line 48

def import_pixels(blob, columns, rows, depth, photometry, format='png')
  image = MiniMagick::Image.import_pixels(blob, columns, rows, depth, im_map(photometry), format)
end