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.

Parameters:

  • blobs (Array<String>)

    an array of binary string blobs containing compressed pixel data

Returns:

  • (Array<MiniMagick::Image>, FalseClass)
    • an array of images, or false (if decompression failed)



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.

Parameters:

  • image (MiniMagick::Image)

    a mini_magick image object

  • photometry (String)

    a code describing the photometry of the pixel data (e.g. ‘MONOCHROME1’ or ‘COLOR’)

Returns:

  • (Array<Integer>)

    an array of pixel values

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.

Parameters:

  • photometry (String)

    a code describing the photometry of the pixel data (e.g. ‘MONOCHROME1’ or ‘COLOR’)

Returns:

  • (String)

    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.

Parameters:

  • blob (String)

    binary string blob containing pixel data

  • columns (Integer)

    the number of columns

  • rows (Integer)

    the number of rows

  • depth (Integer)

    the bit depth of the encoded pixel data

  • photometry (String)

    a code describing the photometry of the pixel data (e.g. ‘MONOCHROME1’ or ‘COLOR’)

  • format (String) (defaults to: 'png')

    the image format to use

Returns:

  • (Magick::Image)

    a mini_magick image object



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