X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FKMeans.fs;h=9bb0691ab80ae8214e6067a2a4785cfb2e7acd42;hb=a498bc4223a22cd38b91b3348912301e15c077ae;hp=6e529476c496309d6c1778024210b10749038798;hpb=1b8e45987bde692ab5602c281f878707f70459b7;p=master-thesis.git diff --git a/Parasitemia/ParasitemiaCore/KMeans.fs b/Parasitemia/ParasitemiaCore/KMeans.fs index 6e52947..9bb0691 100644 --- a/Parasitemia/ParasitemiaCore/KMeans.fs +++ b/Parasitemia/ParasitemiaCore/KMeans.fs @@ -1,27 +1,28 @@ module ParasitemiaCore.KMeans -open System.Collections.Generic open System.Drawing open Emgu.CV open Emgu.CV.Structure -type Result = { - fg: Image - mean_bg: float32 - mean_fg: float32 - d_fg: Image } // Euclidean distances of the foreground to mean_fg. +type Result = + { + fg : Image + mean_bg : float32 + mean_fg : float32 + d_fg : Image // Euclidean distances of the foreground to mean_fg. + } -let kmeans (img: Image) : Result = +let kmeans (img : Image) : Result = let nbIteration = 4 let w = img.Width let h = img.Height let min = ref [| 0.0 |] - let minLocation = ref <| [| Point() |] + let minLocation = ref <| [| Point () |] let max = ref [| 0.0 |] - let maxLocation = ref <| [| Point() |] - img.MinMax(min, max, minLocation, maxLocation) + let maxLocation = ref <| [| Point () |] + img.MinMax (min, max, minLocation, maxLocation) let minf = float32 (!min).[0] let maxf = float32 (!max).[0] @@ -30,7 +31,7 @@ let kmeans (img: Image) : Result = let mutable mean_fg = minf + (maxf - minf) / 4.f use mutable d_bg : Image = null let mutable d_fg : Image = null - let fg = new Image(img.Size) + let fg = new Image (img.Size) let imgData = img.Data let fgData = fg.Data @@ -39,14 +40,14 @@ let kmeans (img: Image) : Result = match d_bg with | null -> () | _ -> - d_bg.Dispose() - d_fg.Dispose() + d_bg.Dispose () + d_fg.Dispose () // EmGu doesn't import the in-place version of 'AbsDiff' so we have to create two images for each iteration. - d_bg <- img.AbsDiff(Gray(float mean_bg)) - d_fg <- img.AbsDiff(Gray(float mean_fg)) + d_bg <- img.AbsDiff (Gray (float mean_bg)) + d_fg <- img.AbsDiff (Gray (float mean_fg)) - CvInvoke.Compare(d_fg, d_bg, fg, CvEnum.CmpType.LessThan) + CvInvoke.Compare (d_fg, d_bg, fg, CvEnum.CmpType.LessThan) let mutable bg_total = 0.f let mutable bg_nb = 0 @@ -56,8 +57,7 @@ let kmeans (img: Image) : Result = for i = 0 to h - 1 do for j = 0 to w - 1 do - if fgData.[i, j, 0] > 0uy - then + if fgData.[i, j, 0] > 0uy then fg_total <- fg_total + imgData.[i, j, 0] fg_nb <- fg_nb + 1 else