X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FImgTools%2FHistogram.fs;h=df1ecb651cf4e76be6cef23e07864435c8a92884;hb=b87b35b922551f122228df1fd9c530bbb807935a;hp=92b73f613b13751cbbae2855d4b63f23145e7752;hpb=3f8b0d281b3058faf23dbd0363de440bd04c6574;p=master-thesis.git diff --git a/Parasitemia/ParasitemiaCore/ImgTools/Histogram.fs b/Parasitemia/ParasitemiaCore/ImgTools/Histogram.fs index 92b73f6..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,20 +26,20 @@ 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 let data = Array.zeroCreate nbSamples - for i in 0 .. img.Height - 1 do - for j in 0 .. img.Width - 1 do + for i = 0 to img.Height - 1 do + for j = 0 to img.Width - 1 do let p = bin imgData.[i, j, 0] data.[p] <- data.[p] + 1 { 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,20 +50,20 @@ 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 let data = Array.zeroCreate nbSamples - for i in 0 .. mat.Height - 1 do - for j in 0 .. mat.Width - 1 do + for i = 0 to mat.Height - 1 do + for j = 0 to mat.Width - 1 do let p = bin matData.[i, j] data.[p] <- data.[p] + 1 { 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