5ba15db43be2b12c538e2accf6c77be949d9f410
[master-thesis.git] / Parasitemia / Parasitemia / KMedians.fs
1 module KMedians
2
3 open Emgu.CV
4 open Emgu.CV.Structure
5
6 open System.Drawing
7
8 let kmedians (mat: Matrix<float32>) (fgFactor: float) : Matrix<byte> =
9 let nbIteration = 3
10
11 let min = ref 0.0
12 let minLocation = ref <| Point()
13 let max = ref 0.0
14 let maxLocation = ref <| Point()
15 mat.MinMax(min, max, minLocation, maxLocation)
16
17 let mutable bgValue = !max - (!max - !min) / 4.0
18 let mutable fgValue = !min + (!max - !min) / 4.0
19 let mutable d_bg = new Matrix<float32>(mat.Size)
20 let mutable d_fg = new Matrix<float32>(mat.Size)
21
22 for i in 1..3 do
23 CvInvoke.Pow(mat - bgValue, 2.0, d_bg)
24 CvInvoke.Pow(mat - fgValue, 2.0, d_fg)
25 let fg = (d_fg * fgFactor).Cmp(d_bg, CvEnum.CmpType.LessThan)
26
27 printfn "test"
28
29
30 (*d_bg = (imgFloat - color_bg) .^ 2.0;
31 d_fg = (imgFloat - color_fg) .^ 2.0;
32 fg = d_fg * Background_weight < d_bg;
33 imgFilteredFg = imgFloat;
34 imgFilteredFg(~fg) = nan;
35 color_fg = median(reshape(imgFilteredFg, [], 1), 'omitnan');
36 imgFilteredBg = imgFloat;
37 imgFilteredBg(fg) = nan;
38 color_bg = median(reshape(imgFilteredBg, [], 1), 'omitnan');
39 *)
40
41
42 new Matrix<byte>(mat.Size)
43
44
45
46