* Add an exact method to compute an ellipse from three points and two tangents.
[master-thesis.git] / Parasitemia / Parasitemia / ImgTools.fs
index 23c9aee..096fd94 100644 (file)
@@ -31,7 +31,6 @@ let saveMat (mat: Matrix<'TDepth>) (filepath: string) =
     mat.CopyTo(img)
     saveImg img filepath
 
-
 type Histogram = { data: int[]; total: int; sum: int; min: float32; max: float32 }
 
 let histogramImg (img: Image<Gray, float32>) (nbSamples: int) : Histogram =
@@ -148,7 +147,6 @@ let otsu (hist: Histogram) : float32 * float32 * float32 =
 
     toFloat level, toFloat mean1, toFloat mean2
 
-
 let suppressMConnections (img: Matrix<byte>) =
     let w = img.Width
     let h = img.Height
@@ -163,7 +161,6 @@ let suppressMConnections (img: Matrix<byte>) =
             then
                 img.[i, j] <- 0uy
 
-
 let findEdges (img: Image<Gray, float32>) : Matrix<byte> * Image<Gray, float32> * Image<Gray, float32> =
     let w = img.Width
     let h = img.Height
@@ -283,12 +280,10 @@ let findEdges (img: Image<Gray, float32>) : Matrix<byte> * Image<Gray, float32>
 
     edges, xGradient, yGradient
 
-
 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)
 
-
 type Points = HashSet<Point>
 
 let drawPoints (img: Image<Gray, 'TDepth>) (points: Points) (intensity: 'TDepth) =
@@ -363,15 +358,12 @@ let findExtremum (img: Image<Gray, 'TDepth>) (extremumType: ExtremumType) : IEnu
 
     result.Select(fun l -> Points(l))
 
-
 let findMaxima (img: Image<Gray, 'TDepth>) : IEnumerable<Points> =
     findExtremum img ExtremumType.Maxima
 
-
 let findMinima (img: Image<Gray, 'TDepth>) : IEnumerable<Points> =
     findExtremum img ExtremumType.Minima
 
-
 type PriorityQueue () =
     let size = 256
     let q: Points[] = Array.init size (fun i -> Points())
@@ -470,7 +462,6 @@ type PriorityQueue () =
         highest <- -1
         lowest <- size
 
-
 type private AreaState =
     | Removed = 1
     | Unprocessed = 2
@@ -612,7 +603,6 @@ let private areaOperation (img: Image<Gray, byte>) (area: int) (op: AreaOperatio
             | _ -> ()
     ()
 
-
 let areaOpen (img: Image<Gray, byte>) (area: int) =
     areaOperation img area AreaOperation.Opening
 
@@ -625,7 +615,6 @@ type Island (cmp: IComparer<float32>) =
     member val Level = 0.f with get, set
     member val Surface = 0 with get, set
 
-
 let private areaOperationF (img: Image<Gray, float32>) (areas: (int * 'a) list) (f: ('a -> float32 -> unit) option) (op: AreaOperation) =
     let w = img.Width
     let h = img.Height
@@ -732,7 +721,6 @@ let private areaOperationF (img: Image<Gray, float32>) (areas: (int * 'a) list)
         | _ -> ()
     ()
 
-
 let areaOpenF (img: Image<Gray, float32>) (area: int) =
     areaOperationF img [ area, () ] None AreaOperation.Opening
 
@@ -800,7 +788,6 @@ let areaOpen2 (img: Image<Gray, byte>) (area: int) =
                             for p in pointsChecked do
                                 imgData.[p.Y, p.X, 0] <- maxNeighborValue
 
-
 // Zhang and Suen algorithm.
 // Modify 'mat' in place.
 let thin (mat: Matrix<byte>) =
@@ -851,7 +838,6 @@ let thin (mat: Matrix<byte>) =
         data1 <- data2
         data2 <- tmp
 
-
 // Remove all 8-connected pixels with an area equal or greater than 'areaSize'.
 // Modify 'mat' in place.
 let removeArea (mat: Matrix<byte>) (areaSize: int) =
@@ -920,17 +906,13 @@ let connectedComponents (img: Image<Gray, byte>) (startPoints: List<Point>) : Li
 
     List<Point>(pointChecked)
 
-
 let drawLine (img: Image<'TColor, 'TDepth>) (color: 'TColor) (x0: int) (y0: int) (x1: int) (y1: int) (thickness: int) =
     img.Draw(LineSegment2D(Point(x0, y0), Point(x1, y1)), color, thickness);
 
-
 let drawLineF (img: Image<'TColor, 'TDepth>) (color: 'TColor) (x0: float) (y0: float) (x1: float) (y1: float) (thickness: int) =
     img.Draw(LineSegment2DF(PointF(float32 x0, float32 y0), PointF(float32 x1, float32 y1)), color, thickness, CvEnum.LineType.AntiAlias);
 
-
 let drawEllipse (img: Image<'TColor, 'TDepth>) (e: Types.Ellipse) (color: 'TColor) (alpha: float) =
-
     if alpha >= 1.0
     then
         img.Draw(Ellipse(PointF(float32 e.Cx, float32 e.Cy), SizeF(2.f * e.B, 2.f * e.A), e.Alpha / PI * 180.f), color, 1, CvEnum.LineType.AntiAlias)
@@ -951,11 +933,9 @@ let drawEllipse (img: Image<'TColor, 'TDepth>) (e: Types.Ellipse) (color: 'TColo
             CvInvoke.AddWeighted(img, 1.0, i, alpha, 0.0, img)
         img.ROI <- Rectangle.Empty
 
-
 let drawEllipses (img: Image<'TColor, 'TDepth>) (ellipses: Types.Ellipse list) (color: 'TColor) (alpha: float) =
     List.iter (fun e -> drawEllipse img e color alpha) ellipses
 
-
 let rngCell =  System.Random()
 let drawCell (img: Image<Bgr, byte>) (drawCellContent: bool) (c: Types.Cell) =
     if drawCellContent