X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FGranulometry.fs;h=877df99384d1f2671cd7481fc3d34dc3f78dfc9f;hb=04d4504e7b248a82ddfc1a41d325e59d24146590;hp=ed8bda6e439cfe24559e0d1664b38db5ac8f30f9;hpb=4bfa3cbdc6145e6944f02e24829ab2ef3a851ac1;p=master-thesis.git diff --git a/Parasitemia/ParasitemiaCore/Granulometry.fs b/Parasitemia/ParasitemiaCore/Granulometry.fs index ed8bda6..877df99 100644 --- a/Parasitemia/ParasitemiaCore/Granulometry.fs +++ b/Parasitemia/ParasitemiaCore/Granulometry.fs @@ -1,6 +1,7 @@ module ParasitemiaCore.Granulometry open System +open System.IO open System.Drawing open Emgu.CV @@ -8,9 +9,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 @@ -36,8 +41,9 @@ let findRadiusByClosing (img: Image) (range: int * int) (scale: f 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)).Mat // It doesn'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,18 +58,24 @@ 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() let mutable maxDiff = 0.f let mutable max_r = r1 - ImgTools.areaCloseFWithFun imgCopy [ for r in r1 .. r2 -> Math.PI * float r ** 2. |> roundInt, r ] (fun r diff -> + Morpho.areaCloseFWithFun imgCopy [ for r in r1 .. r2 -> Math.PI * float r ** 2. |> roundInt, r ] (fun r diff -> if r <> r1 && diff > maxDiff then maxDiff <- diff - max_r <- r - 1 ) + max_r <- r - 1) max_r