5ba15db43be2b12c538e2accf6c77be949d9f410
8 let kmedians (mat
: Matrix<float32
>) (fgFactor
: float) : Matrix<byte
> =
12 let minLocation = ref <| Point()
14 let maxLocation = ref <| Point()
15 mat
.MinMax(min, max, minLocation, maxLocation)
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)
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)
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');
42 new Matrix<byte
>(mat
.Size)