Class: CVFFI::ImagePatch::CircularMask
- Defined in:
- lib/opencv-ffi-wrappers/features2d/image_patch.rb
Instance Attribute Summary
Attributes inherited from Mask
Instance Method Summary collapse
- #build_circle(radius) ⇒ Object
-
#initialize(size) ⇒ CircularMask
constructor
A new instance of CircularMask.
- #to_a ⇒ Object
- #valid?(i, j) ⇒ Boolean
Methods inherited from Mask
Constructor Details
#initialize(size) ⇒ CircularMask
Returns a new instance of CircularMask.
44 45 46 47 48 |
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 44 def initialize(size) super(size) @mask = build_circle( size/2.0 ) end |
Instance Method Details
#build_circle(radius) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 50 def build_circle( radius ) ## Returns row-major Array of Arrays center = CVFFI::Point.new(radius,radius) @mask = Array.new(radius.ceil) { |i| Array.new(radius.ceil) { |j| pt = CVFFI::Point.new( 0.5 + j, 0.5 + i ) center.l2distance( pt ) <= radius ? true : false } } # Now mirror the one quadrant across Y, then across X @mask.map! { |a| a + a.reverse } @mask + @mask.reverse end |
#to_a ⇒ Object
69 70 71 |
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 69 def to_a @mask.map { |m| m.map { |m| m ? true: false } } end |
#valid?(i, j) ⇒ Boolean
65 66 67 |
# File 'lib/opencv-ffi-wrappers/features2d/image_patch.rb', line 65 def valid?(i,j) @mask[i][j] end |