Class: Axon::BilinearScaler
- Inherits:
-
Object
- Object
- Axon::BilinearScaler
- Defined in:
- lib/axon/scalers.rb
Overview
A Bilinear Image Scaler
Axon::BilinearScaler scales images using the bilinear interpolation method.
Bilinear interpolation calculates the color values in the resulting image by looking at the four nearest pixels for each pixel in the resulting image.
This gives a more accurate representation than nearest-neighbor interpolation, at the expense of slightly blurring the resulting image.
Example
n = Axon::BilinearScaler.new(image_in, 50, 75)
n.width # => 50
n.height # => 75
n.gets # => String
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
The height of the generated image.
-
#lineno ⇒ Object
readonly
The index of the next line that will be fetched by gets, starting at 0.
-
#width ⇒ Object
readonly
The width of the generated image.
Instance Method Summary collapse
-
#color_model ⇒ Object
Gets the color model of the scaled image.
-
#components ⇒ Object
Gets the components in the scaled image.
-
#gets ⇒ Object
Gets the next scanline from the cropped image.
-
#initialize(source, width, height) ⇒ BilinearScaler
constructor
:call-seq: BilinearScaler.new(image_in, width, height).
Constructor Details
#initialize(source, width, height) ⇒ BilinearScaler
:call-seq:
BilinearScaler.new(image_in, width, height)
Scales image_in
to the size width
x height
using the bilinear interpolation method.
107 108 109 110 111 112 113 114 115 |
# File 'lib/axon/scalers.rb', line 107 def initialize(source, width, height) raise ArgumentError if width < 1 || height < 1 @width = width @height = height @source = source @lineno = 0 @buf1 = nil @buf2 = nil end |
Instance Attribute Details
#height ⇒ Object (readonly)
The height of the generated image.
96 97 98 |
# File 'lib/axon/scalers.rb', line 96 def height @height end |
#lineno ⇒ Object (readonly)
The index of the next line that will be fetched by gets, starting at 0.
99 100 101 |
# File 'lib/axon/scalers.rb', line 99 def lineno @lineno end |
#width ⇒ Object (readonly)
The width of the generated image.
93 94 95 |
# File 'lib/axon/scalers.rb', line 93 def width @width end |
Instance Method Details
#color_model ⇒ Object
Gets the color model of the scaled image. Same as the color model of the source image.
127 128 129 |
# File 'lib/axon/scalers.rb', line 127 def color_model @source.color_model end |
#components ⇒ Object
Gets the components in the scaled image. Same as the components of the source image.
120 121 122 |
# File 'lib/axon/scalers.rb', line 120 def components @source.components end |
#gets ⇒ Object
Gets the next scanline from the cropped image.
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/axon/scalers.rb', line 133 def gets return nil if @lineno >= @height sample = @lineno * @source.height / @height.to_f sample_i = sample.to_i ty = sample - sample_i @lineno += 1 get_buf(sample_i) Interpolation.bilinear(@buf1, @buf2, @width, ty, components) end |