X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemia%2FImgTools.fs;h=527831383b9a7c1896ade3ae0e26568c2f12ffc4;hp=cc09405b3477005646cf8f560eea32016e54dbcf;hb=dec96d50e56e1932bbfa09e6bedf90d6b707ccbd;hpb=ba64921fb9a0c36cd8cf802cbf1b2c0f79bc25f6 diff --git a/Parasitemia/Parasitemia/ImgTools.fs b/Parasitemia/Parasitemia/ImgTools.fs index cc09405..5278313 100644 --- a/Parasitemia/Parasitemia/ImgTools.fs +++ b/Parasitemia/Parasitemia/ImgTools.fs @@ -9,6 +9,15 @@ open Emgu.CV.Structure open Utils +// Normalize image values between 0uy and 255uy. +let normalizeAndConvert (img: Image) : Image = + 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() + 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) @@ -151,8 +160,8 @@ let drawLine (img: Image<'TColor, 'TDepth>) (color: 'TColor) (x0: float) (y0: fl 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 @@ -164,8 +173,8 @@ let drawEllipse (img: Image<'TColor, 'TDepth>) (e: Types.Ellipse) (color: 'TColo 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 @@ -174,4 +183,7 @@ let drawEllipse (img: Image<'TColor, 'TDepth>) (e: Types.Ellipse) (color: 'TColo 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