X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=Parasitemia%2FParasitemiaCore%2FGranulometry.fs;h=ea5ef67e352720cf4b21434015c4cc434b667787;hb=refs%2Ftags%2F1.0.13;hp=b325534b04c815beab9ac4a1221264fd7c0ef23a;hpb=3f8b0d281b3058faf23dbd0363de440bd04c6574;p=master-thesis.git
diff --git a/Parasitemia/ParasitemiaCore/Granulometry.fs b/Parasitemia/ParasitemiaCore/Granulometry.fs
index b325534..ea5ef67 100644
--- a/Parasitemia/ParasitemiaCore/Granulometry.fs
+++ b/Parasitemia/ParasitemiaCore/Granulometry.fs
@@ -14,8 +14,9 @@ open Utils
///
/// Minimum radius * maximum radius
/// le 1.0, to speed up the process.
-let findRadiusByClosing (img: Image) (range: int * int) (scale: float) (useOctagon: bool) : int =
- use scaledImg = if scale = 1. then img else img.Resize(scale, CvEnum.Inter.Area)
+///
+let findRadiusByClosing (img : Image) (range : int * int) (scale : float) (useOctagon : bool) : int =
+ use scaledImg = if scale = 1. then img else img.Resize (scale, CvEnum.Inter.Area)
let r1, r2 = range
let r1', r2' = roundInt (float r1 * scale), roundInt (float r2 * scale)
@@ -24,32 +25,32 @@ let findRadiusByClosing (img: Image) (range: int * int) (scale: f
let intensityImg = scaledImg.GetSum().Intensity
// 's' must be odd.
- let octagon (s: int) : Mat =
+ let octagon (s : int) : Matrix =
if s % 2 = 0 then failwith "s must be odd"
- let m = new Matrix(Array2D.create s s 1uy)
+ let m = new Matrix (Array2D.create s s 1uy)
let r = (float s) / (Math.Sqrt 2. + 2.) |> roundInt
- for i in 0 .. r - 1 do
- for j in 0 .. r - 1 do
- if i + j < r
- then
+ for i = 0 to r - 1 do
+ for j = 0 to r - 1 do
+ if i + j < r then
m.[i, j] <- 0uy
m.[s - i - 1, j] <- 0uy
m.[i, s - j - 1] <- 0uy
m.[s - i - 1, s - j - 1] <- 0uy
- m.Mat
+ m
let mutable previous_n = Double.NaN
- for r in r1' .. r2' do
- let se = if useOctagon
- then octagon (2 * r - 1) // It doesnd't speed up the process.
- else CvInvoke.GetStructuringElement(CvEnum.ElementShape.Ellipse, Size(2 * r, 2 * r), Point(-1, -1))
+ for r = r1' to r2' do
+ let se =
+ if useOctagon then
+ (octagon (2 * r - 1)).Mat // It doesn't speed up the process.
+ else
+ CvInvoke.GetStructuringElement (CvEnum.ElementShape.Ellipse, Size (2 * r, 2 * r), Point (-1, -1))
- use closed = scaledImg.MorphologyEx(CvEnum.MorphOp.Close, se, Point(-1, -1), 1, CvEnum.BorderType.Replicate, MCvScalar(0.0))
+ use closed = scaledImg.MorphologyEx (CvEnum.MorphOp.Close, se, Point (-1, -1), 1, CvEnum.BorderType.Replicate, MCvScalar (0.0))
let n = closed.GetSum().Intensity
- if not (Double.IsNaN previous_n)
- then
+ if not (Double.IsNaN previous_n) then
patternSpectrum.[r - r1' - 1] <- abs (n - previous_n)
previous_n <- n
@@ -60,21 +61,23 @@ let findRadiusByClosing (img: Image) (range: int * int) (scale: f
///
/// Granulometry by area closing on the image 'img' by testing the circle area into the given radius range.
///
-let findRadiusByAreaClosing (img: Image) (radiusRange: int * int) : int =
+let findRadiusByAreaClosing (img : Image) (radiusRange : int * int) : int =
let r1, r2 = radiusRange
- if r1 > r2
- then failwithf "'radiusRange' invalid : %A" radiusRange
+ if r1 > r2 then
+ failwithf "'radiusRange' invalid : %O" radiusRange
- use imgCopy = img.Copy()
+ use imgCopy = img.Copy ()
let mutable maxDiff = 0.f
let mutable max_r = r1
- Morpho.areaCloseFWithFun imgCopy [ for r in r1 .. r2 -> Math.PI * float r ** 2. |> roundInt, r ] (fun r diff ->
- if r <> r1 && diff > maxDiff
- then
- maxDiff <- diff
- max_r <- r - 1)
+ Morpho.areaCloseFWithFun imgCopy [ for r in r1 .. r2 -> Math.PI * float r ** 2. |> roundInt, r ] (
+ fun r diff ->
+ if r <> r1 && diff > maxDiff then
+ maxDiff <- diff
+ max_r <- r - 1
+ )
+
max_r