X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemia%2FKMedians.fs;fp=Parasitemia%2FParasitemia%2FKMedians.fs;h=5ba15db43be2b12c538e2accf6c77be949d9f410;hp=0000000000000000000000000000000000000000;hb=ba64921fb9a0c36cd8cf802cbf1b2c0f79bc25f6;hpb=0ff8fb82457bd5a858b2218ab07f69c81323537e diff --git a/Parasitemia/Parasitemia/KMedians.fs b/Parasitemia/Parasitemia/KMedians.fs new file mode 100644 index 0000000..5ba15db --- /dev/null +++ b/Parasitemia/Parasitemia/KMedians.fs @@ -0,0 +1,46 @@ +module KMedians + +open Emgu.CV +open Emgu.CV.Structure + +open System.Drawing + +let kmedians (mat: Matrix) (fgFactor: float) : Matrix = + let nbIteration = 3 + + let min = ref 0.0 + let minLocation = ref <| Point() + let max = ref 0.0 + let maxLocation = ref <| Point() + mat.MinMax(min, max, minLocation, maxLocation) + + let mutable bgValue = !max - (!max - !min) / 4.0 + let mutable fgValue = !min + (!max - !min) / 4.0 + let mutable d_bg = new Matrix(mat.Size) + let mutable d_fg = new Matrix(mat.Size) + + for i in 1..3 do + CvInvoke.Pow(mat - bgValue, 2.0, d_bg) + CvInvoke.Pow(mat - fgValue, 2.0, d_fg) + let fg = (d_fg * fgFactor).Cmp(d_bg, CvEnum.CmpType.LessThan) + + printfn "test" + + + (*d_bg = (imgFloat - color_bg) .^ 2.0; + d_fg = (imgFloat - color_fg) .^ 2.0; + fg = d_fg * Background_weight < d_bg; + imgFilteredFg = imgFloat; + imgFilteredFg(~fg) = nan; + color_fg = median(reshape(imgFilteredFg, [], 1), 'omitnan'); + imgFilteredBg = imgFloat; + imgFilteredBg(fg) = nan; + color_bg = median(reshape(imgFilteredBg, [], 1), 'omitnan'); + *) + + + new Matrix(mat.Size) + + + +