X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;ds=sidebyside;f=Parasitemia%2FParasitemiaCore%2FImgTools%2FImgTools.fs;h=991cb76cc5b1316bf8f2aaa4da9a0e58b4f8aea4;hb=24bfd2ea10b5945100168ad5a1b2545e43d05569;hp=09497133aa03b4316b084bd6b36b89ea4969f5ce;hpb=85adb74195fe7145535d3d36263aec2f7879cd60;p=master-thesis.git
diff --git a/Parasitemia/ParasitemiaCore/ImgTools/ImgTools.fs b/Parasitemia/ParasitemiaCore/ImgTools/ImgTools.fs
index 0949713..991cb76 100644
--- a/Parasitemia/ParasitemiaCore/ImgTools/ImgTools.fs
+++ b/Parasitemia/ParasitemiaCore/ImgTools/ImgTools.fs
@@ -1,6 +1,5 @@
module ParasitemiaCore.ImgTools
-open System
open System.Drawing
open Emgu.CV
@@ -12,44 +11,45 @@ open Emgu.CV.Structure
///
///
///
-let normalize (img: Image) (upperLimit: float) : Image =
+let normalize (img : Image) (upperLimit : float) : Image =
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)
let normalized = (img - (!min).[0]) / ((!max).[0] - (!min).[0])
- if upperLimit = 1.0
- then normalized
- else upperLimit * normalized
+ if upperLimit = 1.0 then
+ normalized
+ else
+ upperLimit * normalized
-let mergeChannels (img: Image) (rgbWeights: float * float * float) : Image =
+let mergeChannels (img : Image) (rgbWeights : float * float * float) : Image =
match rgbWeights with
| 1., 0., 0. -> img.[2]
| 0., 1., 0. -> img.[1]
| 0., 0., 1. -> img.[0]
| redFactor, greenFactor, blueFactor ->
- let result = new Image(img.Size)
- CvInvoke.AddWeighted(result, 1., img.[2], redFactor, 0., result)
- CvInvoke.AddWeighted(result, 1., img.[1], greenFactor, 0., result)
- CvInvoke.AddWeighted(result, 1., img.[0], blueFactor, 0., result)
+ let result = new Image (img.Size)
+ CvInvoke.AddWeighted (result, 1., img.[2], redFactor, 0., result)
+ CvInvoke.AddWeighted (result, 1., img.[1], greenFactor, 0., result)
+ CvInvoke.AddWeighted (result, 1., img.[0], blueFactor, 0., result)
result
-let mergeChannelsWithProjection (img: Image) (v1r: float32, v1g: float32, v1b: float32) (v2r: float32, v2g: float32, v2b: float32) (upperLimit: float) : Image =
+let mergeChannelsWithProjection (img : Image) (v1r : float32, v1g : float32, v1b : float32) (v2r : float32, v2g : float32, v2b : float32) (upperLimit : float) : Image =
let vr, vg, vb = v2r - v1r, v2g - v1g, v2b - v1b
let vMagnitude = sqrt (vr ** 2.f + vg ** 2.f + vb ** 2.f)
- let project (r: float32) (g: float32) (b: float32) = ((r - v1r) * vr + (g - v1g) * vg + (b - v1b) * vb) / vMagnitude
- let result = new Image(img.Size)
+ let project (r : float32) (g : float32) (b : float32) = ((r - v1r) * vr + (g - v1g) * vg + (b - v1b) * vb) / vMagnitude
+ let result = new Image (img.Size)
// TODO: Essayer en bindant Data pour gagner du temps
- 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
result.Data.[i, j, 0] <- project img.Data.[i, j, 2] img.Data.[i, j, 1] img.Data.[i, j, 0]
normalize result upperLimit
// Normalize image values between 0uy and 255uy.
-let normalizeAndConvert (img: Image) : Image =
- (normalize (img.Convert()) 255.).Convert()
+let normalizeAndConvert (img : Image) : Image =
+ (normalize (img.Convert ()) 255.).Convert ()
let gaussianFilter (img : Image<'TColor, 'TDepth>) (standardDeviation : float) : Image<'TColor, 'TDepth> =
let size = 2 * int (ceil (4.0 * standardDeviation)) + 1
- img.SmoothGaussian(size, size, standardDeviation, standardDeviation)
+ img.SmoothGaussian (size, size, standardDeviation, standardDeviation)