Module: Magro::Transform

Defined in:
lib/magro/transform.rb

Overview

Transform module provide functions of image transfom.

Class Method Summary collapse

Class Method Details

.resize(image, height:, width:) ⇒ Numo::UInt8

Resizes an image with bilinear interpolation method.

Examples:

require 'numo/narray'
require 'magro'

image = Numo::UInt8.new(16, 16).seq
resized = Magro::Transform.resize(image, height: 64, width: 64)

Parameters:

  • image (Numo::UInt8)

    (shape: [height, width, n_channels] or [height, width]) Image data to be saved.

  • height (Integer)

    Requested height in pixels.

  • width (Integer)

    Requested width in pixels.

Returns:

  • (Numo::UInt8)

    (shape: [height, width, n_channels] or [height, width]) Resized image data.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/magro/transform.rb', line 21

def resize(image, height:, width:)
  n_channels = image.shape[2]

  if n_channels.nil?
    bilinear_resize(image, height, width)
  else
    resized = image.class.zeros(height, width, n_channels)
    n_channels.times { |c| resized[true, true, c] = bilinear_resize(image[true, true, c], height, width) }
    resized
  end
end