X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FKMeans.fs;h=dfd2593b132bc7ca82762733581095d34ad712e9;hb=b87b35b922551f122228df1fd9c530bbb807935a;hp=86f1e3b5a7102cacbb12c7aa394ccb3683c75cfc;hpb=4bfa3cbdc6145e6944f02e24829ab2ef3a851ac1;p=master-thesis.git diff --git a/Parasitemia/ParasitemiaCore/KMeans.fs b/Parasitemia/ParasitemiaCore/KMeans.fs index 86f1e3b..dfd2593 100644 --- a/Parasitemia/ParasitemiaCore/KMeans.fs +++ b/Parasitemia/ParasitemiaCore/KMeans.fs @@ -6,13 +6,15 @@ 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. - -let kmeans (img: Image) : Result = +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 nbIteration = 4 let w = img.Width let h = img.Height @@ -35,7 +37,7 @@ let kmeans (img: Image) : Result = let imgData = img.Data let fgData = fg.Data - for i in 1 .. nbIteration do + for i = 1 to nbIteration do match d_bg with | null -> () | _ -> @@ -54,10 +56,9 @@ let kmeans (img: Image) : Result = let mutable fg_total = 0.f let mutable fg_nb = 0 - for i in 0 .. h - 1 do - for j in 0 .. w - 1 do - if fgData.[i, j, 0] > 0uy - then + for i = 0 to h - 1 do + for j = 0 to w - 1 do + if fgData.[i, j, 0] > 0uy then fg_total <- fg_total + imgData.[i, j, 0] fg_nb <- fg_nb + 1 else