module DICOM::ImageProcessor::DcmMiniMagick
This module contains methods for interacting with pixel data using the mini_magick gem.
Public Class Methods
Creates image objects from an array of compressed, binary string blobs.
@param [Array<String>] blobs an array of binary string blobs containing compressed pixel data @return [Array<MiniMagick::Image>, FalseClass] - an array of images, or false (if decompression failed)
# 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
Extracts an array of pixels (integers) from an image object.
@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).
@param [MiniMagick::Image] image a mini_magick image object @param [String] photometry a code describing the photometry of the pixel data (e.g. 'MONOCHROME1' or 'COLOR') @return [Array<Integer>] an array of pixel values
# 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
Converts a given DICOM
photometry string to a mini_magick pixel map string.
@param [String] photometry a code describing the photometry of the pixel data (e.g. 'MONOCHROME1' or 'COLOR') @return [String] a mini_magick pixel map string
# 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
Creates an image object from a binary string blob.
@param [String] blob binary string blob containing pixel data @param [Integer] columns the number of columns @param [Integer] rows the number of rows @param [Integer] depth the bit depth of the encoded pixel data @param [String] photometry a code describing the photometry of the pixel data (e.g. 'MONOCHROME1' or 'COLOR') @param [String] format the image format to use @return [Magick::Image] a mini_magick image object
# 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