open Histogram
open Otsu
+// Sensibilities of the hysteresis search.
+let sensibilityHigh = 0.1f
+let sensibilityLow = 0.0f
+
/// <summary>
/// Find edges of an image by using the Canny approach.
/// The thresholds are automatically defined with otsu on gradient magnitudes.
let h = img.Height
use sobelKernel =
- new Matrix<float32>(array2D [[ 1.0f; 0.0f; -1.0f ]
- [ 2.0f; 0.0f; -2.0f ]
- [ 1.0f; 0.0f; -1.0f ]])
+ new Matrix<float32>(array2D [[ -1.0f; 0.0f; 1.0f ]
+ [ -2.0f; 0.0f; 2.0f ]
+ [ -1.0f; 0.0f; 1.0f ]])
let xGradient = new Matrix<float32>(img.Size)
let yGradient = new Matrix<float32>(img.Size)
use magnitudes = new Matrix<float32>(xGradient.Size)
use angles = new Matrix<float32>(xGradient.Size)
- CvInvoke.CartToPolar(xGradient, yGradient, magnitudes, angles) // Compute the magnitudes and angles.
+ CvInvoke.CartToPolar(xGradient, yGradient, magnitudes, angles) // Compute the magnitudes and angles. The angles are between 0 and 2 * pi.
let thresholdHigh, thresholdLow =
- let sensibilityHigh = 0.1f
- let sensibilityLow = 0.0f
let threshold, _, _ = otsu (histogramMat magnitudes 300)
threshold + (sensibilityHigh * threshold), threshold - (sensibilityLow * threshold)
let xGradientData = xGradient.Data
let yGradientData = yGradient.Data
- for i in 0 .. h - 1 do
- nmsData.[i, 0] <- 0uy
- nmsData.[i, w - 1] <- 0uy
-
- for j in 0 .. w - 1 do
- nmsData.[0, j] <- 0uy
- nmsData.[h - 1, j] <- 0uy
-
for i in 1 .. h - 2 do
for j in 1 .. w - 2 do
let vx = xGradientData.[i, j]
// suppressMConnections nms // It's not helpful for the rest of the process (ellipse detection).
+ IO.saveMat magnitudes "magnitudes.png"
+ IO.saveMat nms "nms.png"
+
let edges = new Matrix<byte>(xGradient.Size)
let edgesData = edges.Data