X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FImgTools%2FOtsu.fs;h=8d976ff0710b7b25bbdf86ac07455a937dea7a68;hp=82dfde4e9b718336f7789654217c44f338455970;hb=b87b35b922551f122228df1fd9c530bbb807935a;hpb=2e3cd07dd099944059ef5e7a7f5ef57ffe3d677b diff --git a/Parasitemia/ParasitemiaCore/ImgTools/Otsu.fs b/Parasitemia/ParasitemiaCore/ImgTools/Otsu.fs index 82dfde4..8d976ff 100644 --- a/Parasitemia/ParasitemiaCore/ImgTools/Otsu.fs +++ b/Parasitemia/ParasitemiaCore/ImgTools/Otsu.fs @@ -2,7 +2,7 @@ open Histogram -let otsu (hist: Histogram) : float32 * float32 * float32 = +let otsu (hist : Histogram) : float32 * float32 * float32 = let mutable sumB = 0 let mutable wB = 0 let mutable maximum = 0.0 @@ -11,17 +11,14 @@ let otsu (hist: Histogram) : float32 * float32 * float32 = for i = 0 to hist.data.Length - 1 do wB <- wB + hist.data.[i] - if wB <> 0 - then + if wB <> 0 then let wF = hist.total - wB - if wF <> 0 - then + if wF <> 0 then sumB <- sumB + i * hist.data.[i] let mB = (float sumB) / (float wB) let mF = (sum - float sumB) / (float wF) let between = (float wB) * (float wF) * (mB - mF) ** 2.; - if between >= maximum - then + if between >= maximum then level <- i maximum <- between