- let filteredGreenWhitoutInfectionFloat = filteredGreenWhitoutInfection.Convert<Gray, float32>()
- let filteredGreenWhitoutStainFloat = filteredGreenWhitoutStain.Convert<Gray, float32>()
-
- use sobelKernel =
- new ConvolutionKernelF(array2D [[ 1.0f; 0.0f; -1.0f ]
- [ 2.0f; 0.0f; -2.0f ]
- [ 1.0f; 0.0f; -1.0f ]], Point(0, 0))
-
- use xEdges = filteredGreenWhitoutStainFloat.Convolution(sobelKernel).Convert<Gray, float>()
- use yEdges = filteredGreenWhitoutStainFloat.Convolution(sobelKernel.Transpose()).Convert<Gray, float>()
-
- let xEdgesData = xEdges.Data
- let yEdgesData = yEdges.Data
- for r in 0..xEdges.Rows-1 do
- xEdgesData.[r, 0, 0] <- 0.0
- xEdgesData.[r, xEdges.Cols-1, 0] <- 0.0
- yEdgesData.[r, 0, 0] <- 0.0
- yEdgesData.[r, xEdges.Cols-1, 0] <- 0.0
-
- for c in 0..xEdges.Cols-1 do
- xEdgesData.[0, c, 0] <- 0.0
- xEdgesData.[xEdges.Rows-1, c, 0] <- 0.0
- yEdgesData.[0, c, 0] <- 0.0
- yEdgesData.[xEdges.Rows-1, c, 0] <- 0.0
-
- use magnitudes = new Matrix<float>(xEdges.Size)
- CvInvoke.CartToPolar(xEdges, yEdges, magnitudes, new Mat()) // Compute the magnitudes (without angles).
-
- let min = ref 0.0
- let minLocation = ref <| Point()
- let max = ref 0.0
- let maxLocation = ref <| Point()
- magnitudes.MinMax(min, max, minLocation, maxLocation)
-
- use magnitudesByte = ((magnitudes / !max) * 255.0).Convert<byte>() // Otsu from OpenCV only support 'byte'.
- use edges = new Matrix<byte>(xEdges.Size)
- CvInvoke.Threshold(magnitudesByte, edges, 0.0, 1.0, CvEnum.ThresholdType.Otsu ||| CvEnum.ThresholdType.Binary) |> ignore
-
- logTime "Finding edges" (fun() -> thin edges)
- logTime "Removing small connected components from thinning" (fun () -> removeArea edges 12)