X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FImgTools%2FHistogram.fs;h=718a9de62254f3c8c4186aa39ef102fc068b1531;hp=e3a9950290f2d5af14a91ea9ba439adcb06c52fe;hb=2d712781def419c9acc98368f7102b19b064f16d;hpb=1b8e45987bde692ab5602c281f878707f70459b7 diff --git a/Parasitemia/ParasitemiaCore/ImgTools/Histogram.fs b/Parasitemia/ParasitemiaCore/ImgTools/Histogram.fs index e3a9950..718a9de 100644 --- a/Parasitemia/ParasitemiaCore/ImgTools/Histogram.fs +++ b/Parasitemia/ParasitemiaCore/ImgTools/Histogram.fs @@ -6,25 +6,27 @@ open System.Drawing open Emgu.CV open Emgu.CV.Structure -type Histogram = { - data: int[] - total: int // Number of elements. - sum: int // Sum of all intensity. - min: float32 - max: float32 } - -let histogramImg (img: Image) (nbSamples: int) : Histogram = +type Histogram = + { + data : int[] + total : int // Number of elements. + sum : int // Sum of all intensity. + min : float32 + max : float32 + } + +let histogramImg (img : Image) (nbSamples : int) : Histogram = let imgData = img.Data let min, max = let min = ref [| 0.0 |] - let minLocation = ref <| [| Point() |] + let minLocation = ref <| [| Point () |] let max = ref [| 0.0 |] - let maxLocation = ref <| [| Point() |] - img.MinMax(min, max, minLocation, maxLocation) + let maxLocation = ref <| [| Point () |] + img.MinMax (min, max, minLocation, maxLocation) float32 (!min).[0], float32 (!max).[0] - let inline bin (x: float32) : int = + let inline bin (x : float32) : int = let p = int ((x - min) / (max - min) * float32 nbSamples) if p >= nbSamples then nbSamples - 1 else p @@ -37,18 +39,18 @@ let histogramImg (img: Image) (nbSamples: int) : Histogram = { data = data; total = img.Height * img.Width; sum = Array.sum data; min = min; max = max } -let histogramMat (mat: Matrix) (nbSamples: int) : Histogram = +let histogramMat (mat : Matrix) (nbSamples : int) : Histogram = let matData = mat.Data let min, max = let min = ref 0.0 - let minLocation = ref <| Point() + let minLocation = ref <| Point () let max = ref 0.0 - let maxLocation = ref <| Point() - mat.MinMax(min, max, minLocation, maxLocation) + let maxLocation = ref <| Point () + mat.MinMax (min, max, minLocation, maxLocation) float32 !min, float32 !max - let inline bin (x: float32) : int = + let inline bin (x : float32) : int = let p = int ((x - min) / (max - min) * float32 nbSamples) if p >= nbSamples then nbSamples - 1 else p @@ -61,7 +63,7 @@ let histogramMat (mat: Matrix) (nbSamples: int) : Histogram = { data = data; total = mat.Height * mat.Width; sum = Array.sum data; min = min; max = max } -let histogram (values: float32 seq) (nbSamples: int) : Histogram = +let histogram (values : float32 seq) (nbSamples : int) : Histogram = let mutable min = Single.MaxValue let mutable max = Single.MinValue let mutable n = 0 @@ -71,7 +73,7 @@ let histogram (values: float32 seq) (nbSamples: int) : Histogram = if v < min then min <- v if v > max then max <- v - let inline bin (x: float32) : int = + let inline bin (x : float32) : int = let p = int ((x - min) / (max - min) * float32 nbSamples) if p >= nbSamples then nbSamples - 1 else p