X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FGranulometry.fs;h=0afe5ccb1501ca8c68591d522b98b62e77b7a375;hp=ed8bda6e439cfe24559e0d1664b38db5ac8f30f9;hb=170abb893b9e6babbf93276e39e8c984cedbc68f;hpb=aee6cf83f81c6378c458f75bbfaf7c9fa5521135 diff --git a/Parasitemia/ParasitemiaCore/Granulometry.fs b/Parasitemia/ParasitemiaCore/Granulometry.fs index ed8bda6..0afe5cc 100644 --- a/Parasitemia/ParasitemiaCore/Granulometry.fs +++ b/Parasitemia/ParasitemiaCore/Granulometry.fs @@ -8,9 +8,13 @@ open Emgu.CV.Structure open Utils -// 'range': a minimum and maximum radius. -// 'scale': <= 1.0, to speed up the process. -let findRadiusByClosing (img: Image) (range: int * int) (scale: float) : int = +/// +/// Granulometry by closing on the image 'img' by testing circle structrual elements with radius range in 'range'. +/// +/// +/// Minimum radius * maximum radius +/// le 1.0, to speed up the process. +let findRadiusByClosing (img: Image) (range: int * int) (scale: float) (useOctagon: bool) : int = use scaledImg = if scale = 1. then img else img.Resize(scale, CvEnum.Inter.Area) let r1, r2 = range @@ -20,7 +24,7 @@ let findRadiusByClosing (img: Image) (range: int * int) (scale: f let intensityImg = scaledImg.GetSum().Intensity // 's' must be odd. - let octagon (s: int) : Matrix = + let octagon (s: int) : Mat = if s % 2 = 0 then failwith "s must be odd" let m = new Matrix(Array2D.create s s 1uy) let r = (float s) / (Math.Sqrt 2. + 2.) |> roundInt @@ -32,12 +36,13 @@ let findRadiusByClosing (img: Image) (range: int * int) (scale: f m.[s - i - 1, j] <- 0uy m.[i, s - j - 1] <- 0uy m.[s - i - 1, s - j - 1] <- 0uy - m + m.Mat let mutable previous_n = Double.NaN for r in r1' .. r2' do - let se = CvInvoke.GetStructuringElement(CvEnum.ElementShape.Ellipse, Size(2 * r, 2 * r), Point(-1, -1)) - //let se = octagon (2 * r - 1) + let se = if useOctagon + then octagon (2 * r - 1) // It doesnd't speed up the process. + else CvInvoke.GetStructuringElement(CvEnum.ElementShape.Ellipse, Size(2 * r, 2 * r), Point(-1, -1)) use closed = scaledImg.MorphologyEx(CvEnum.MorphOp.Close, se, Point(-1, -1), 1, CvEnum.BorderType.Replicate, MCvScalar(0.0)) @@ -52,8 +57,14 @@ let findRadiusByClosing (img: Image) (range: int * int) (scale: f float (max + r1') / scale |> roundInt -let findRadiusByAreaClosing (img: Image) (range: int * int) : int = - let r1, r2 = range +/// +/// Granulometry by area closing on the image 'img' by testing the circle area into the given radius range. +/// +let findRadiusByAreaClosing (img: Image) (radiusRange: int * int) : int = + let r1, r2 = radiusRange + + if r1 > r2 + then failwithf "'radiusRange' invalid : %A" radiusRange use imgCopy = img.Copy() @@ -64,6 +75,6 @@ let findRadiusByAreaClosing (img: Image) (range: int * int) : int if r <> r1 && diff > maxDiff then maxDiff <- diff - max_r <- r - 1 ) + max_r <- r - 1) max_r