X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemia%2FImgTools.fs;fp=Parasitemia%2FParasitemia%2FImgTools.fs;h=096fd94ec7e9736cd73a60200ce95be017ca6c35;hp=23c9aee38e18c6f41bd684ecaeb1ea44a8dabd70;hb=81d1b86719a1ebaf649c1de4c1364603155a53e1;hpb=aaa250fab2ac3227bf45704355d389bc1a4ee7fc diff --git a/Parasitemia/Parasitemia/ImgTools.fs b/Parasitemia/Parasitemia/ImgTools.fs index 23c9aee..096fd94 100644 --- a/Parasitemia/Parasitemia/ImgTools.fs +++ b/Parasitemia/Parasitemia/ImgTools.fs @@ -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) (nbSamples: int) : Histogram = @@ -148,7 +147,6 @@ let otsu (hist: Histogram) : float32 * float32 * float32 = toFloat level, toFloat mean1, toFloat mean2 - let suppressMConnections (img: Matrix) = let w = img.Width let h = img.Height @@ -163,7 +161,6 @@ let suppressMConnections (img: Matrix) = then img.[i, j] <- 0uy - let findEdges (img: Image) : Matrix * Image * Image = let w = img.Width let h = img.Height @@ -283,12 +280,10 @@ let findEdges (img: Image) : Matrix * Image 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 let drawPoints (img: Image) (points: Points) (intensity: 'TDepth) = @@ -363,15 +358,12 @@ let findExtremum (img: Image) (extremumType: ExtremumType) : IEnu result.Select(fun l -> Points(l)) - let findMaxima (img: Image) : IEnumerable = findExtremum img ExtremumType.Maxima - let findMinima (img: Image) : IEnumerable = 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) (area: int) (op: AreaOperatio | _ -> () () - let areaOpen (img: Image) (area: int) = areaOperation img area AreaOperation.Opening @@ -625,7 +615,6 @@ type Island (cmp: IComparer) = member val Level = 0.f with get, set member val Surface = 0 with get, set - let private areaOperationF (img: Image) (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) (areas: (int * 'a) list) | _ -> () () - let areaOpenF (img: Image) (area: int) = areaOperationF img [ area, () ] None AreaOperation.Opening @@ -800,7 +788,6 @@ let areaOpen2 (img: Image) (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) = @@ -851,7 +838,6 @@ let thin (mat: Matrix) = 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) (areaSize: int) = @@ -920,17 +906,13 @@ let connectedComponents (img: Image) (startPoints: List) : Li List(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) (drawCellContent: bool) (c: Types.Cell) = if drawCellContent