X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FImgTools%2FHistogram.fs;fp=Parasitemia%2FParasitemiaCore%2FImgTools%2FHistogram.fs;h=df1ecb651cf4e76be6cef23e07864435c8a92884;hp=e3a9950290f2d5af14a91ea9ba439adcb06c52fe;hb=b87b35b922551f122228df1fd9c530bbb807935a;hpb=2e3cd07dd099944059ef5e7a7f5ef57ffe3d677b diff --git a/Parasitemia/ParasitemiaCore/ImgTools/Histogram.fs b/Parasitemia/ParasitemiaCore/ImgTools/Histogram.fs index e3a9950..df1ecb6 100644 --- a/Parasitemia/ParasitemiaCore/ImgTools/Histogram.fs +++ b/Parasitemia/ParasitemiaCore/ImgTools/Histogram.fs @@ -6,14 +6,16 @@ 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 = @@ -24,7 +26,7 @@ let histogramImg (img: Image) (nbSamples: int) : Histogram = 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,7 +39,7 @@ 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 = @@ -48,7 +50,7 @@ let histogramMat (mat: Matrix) (nbSamples: int) : Histogram = 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