Class: RImageAnalysisTools::Drawing
- Inherits:
-
Object
- Object
- RImageAnalysisTools::Drawing
- Defined in:
- lib/rimageanalysistools/drawing.rb
Overview
A collection of methods for drawing into an existing image.
Instance Method Summary collapse
-
#circle(im, center, radius) ⇒ void
Draws a circle into an image.
-
#draw(im, draw_value = 255.0) ⇒ void
A basic drawing method that iterates through an entire image.
-
#draw_shape(im, location, shape_name = :circle, shape_parameters = 10) ⇒ void
Draws a specified shape into an image.
-
#ellipse(im, foci, radius_inc) ⇒ void
Draws an ellipse into an image.
Instance Method Details
#circle(im, center, radius) ⇒ void
This method returns an undefined value.
Draws a circle into an image.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/rimageanalysistools/drawing.rb', line 142 def circle(im, center, radius) lower = ImageCoordinate[center[0]-radius-1, center[1]-radius-1, 0,0,0] upper = ImageCoordinate[center[0]+radius+1, center[1]+radius+1, 0,0,0] im.box_conservative(lower, upper, [:x, :y]) draw(im) do |ic| xdiff = ic[:x] - center[0] ydiff = ic[:y] - center[1] if (Math.hypot(xdiff, ydiff) - radius).abs <= Math.sqrt(2) then true else false end end lower.recycle upper.recycle end |
#draw(im, draw_value = 255.0) ⇒ void
This method returns an undefined value.
A basic drawing method that iterates through an entire image. At each coordinate, an attached block is evaluated for a boolean response that determines whether that coordinate is overwritten with a specified value. The attached block will be given a single parameter, which is the current ImageCoordinate.
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rimageanalysistools/drawing.rb', line 96 def draw(im, draw_value = 255.0) im.each do |ic| if (yield ic) then im.setValue(ic, draw_value) end end end |
#draw_shape(im, location, shape_name = :circle, shape_parameters = 10) ⇒ void
This method returns an undefined value.
Draws a specified shape into an image.
123 124 125 126 127 128 129 130 131 |
# File 'lib/rimageanalysistools/drawing.rb', line 123 def draw_shape(im, location, shape_name=:circle, shape_parameters= 10) if self.respond_to?(shape_name) then self.send(shape_name, im, location, shape_parameters) end end |
#ellipse(im, foci, radius_inc) ⇒ void
This method returns an undefined value.
Draws an ellipse into an image.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/rimageanalysistools/drawing.rb', line 179 def ellipse(im, foci, radius_inc) min_x = foci[0][0] max_x = foci[1][0] min_y = foci[0][1] max_y = foci[1][1] if foci[1][0] < min_x then min_x = foci[1][0] max_x = foci[0][0] end if foci[1][1] < min_y then min_y = foci[1][1] max_y = foci[0][1] end radius = radius_inc + Math.hypot(max_x-min_x, max_y-min_y) lower = ImageCoordinate[min_x-radius-1, min_y-radius-1, 0,0,0] upper = ImageCoordinate[max_x+radius+1, max_y+radius+1, 0,0,0] im.box_conservative(lower, upper, [:x, :y]) draw(im) do |ic| xdiff0 = ic[:x] - foci[0][0] ydiff0 = ic[:y] - foci[0][1] xdiff1 = ic[:x] - foci[1][0] ydiff1 = ic[:y] - foci[1][1] if (Math.hypot(xdiff0, ydiff0) + Math.hypot(xdiff1, ydiff1) - radius).abs <= Math.sqrt(2) then true else false end end end |