open Utils
+// Normalize image values between 0uy and 255uy.
+let normalizeAndConvert (img: Image<Gray, float32>) : Image<Gray, byte> =
+ let min = ref [| 0.0 |]
+ let minLocation = ref <| [| Point() |]
+ let max = ref [| 0.0 |]
+ let maxLocation = ref <| [| Point() |]
+ img.MinMax(min, max, minLocation, maxLocation)
+ ((img - (!min).[0]) / ((!max).[0] - (!min).[0]) * 255.0).Convert<Gray, byte>()
+
let gaussianFilter (img : Image<'TColor, 'TDepth>) (standardDeviation : float) : Image<'TColor, 'TDepth> =
let size = 2 * int (ceil (4.0 * standardDeviation)) + 1
img.SmoothGaussian(size, size, standardDeviation, standardDeviation)
img.Draw(LineSegment2D(Point(x0, y0), Point(x1, y1)), color, 1);
let drawEllipse (img: Image<'TColor, 'TDepth>) (e: Types.Ellipse) (color: 'TColor) =
- let cosAlpha = cos e.alpha
- let sinAlpha = sin e.alpha
+ let cosAlpha = cos e.Alpha
+ let sinAlpha = sin e.Alpha
let mutable x0 = 0.0
let mutable y0 = 0.0
for theta in 0.0 .. thetaIncrement .. 2.0 * Math.PI do
let cosTheta = cos theta
let sinTheta = sin theta
- let x = e.cx + cosAlpha * e.a * cosTheta - sinAlpha * e.b * sinTheta
- let y = e.cy + sinAlpha * e.a * cosTheta + cosAlpha * e.b * sinTheta
+ let x = e.Cx + cosAlpha * e.A * cosTheta - sinAlpha * e.B * sinTheta
+ let y = e.Cy + sinAlpha * e.A * cosTheta + cosAlpha * e.B * sinTheta
if not first_iteration
then
first_iteration <- false
x0 <- x
- y0 <- y
\ No newline at end of file
+ y0 <- y
+
+let drawEllipses (img: Image<'TColor, 'TDepth>) (ellipses: Types.Ellipse list) (color: 'TColor) =
+ List.iter (fun e -> drawEllipse img e color) ellipses
\ No newline at end of file