Skip to content

Edge detection

Cristel Chandre edited this page Jul 1, 2024 · 17 revisions

Edge detection aims at identifying edges, defined as curves in an image at which the image brightness changes sharply or has discontinuities. The purpose of detecting sharp changes in image brightness is to capture important events and changes in properties of the image, such as cell boundaries and contours.

The activation of the edge detection creates a new tab `Edge detection` in the right panel of the PyPOLAR app, in which the parameters of the edge detection can be tuned. The button becomes blue when activated.

The edges are displayed as blue lines on the thresholded image.


Method

To compute the edges, the Canny edge detector cv2.Canny is used with two parameters low threshold and high threshold (see Edge Detection tab) after a first Gaussian blur cv2.GaussianBlur of the image (with (5, 5) as width and height of the kernel - the standard deviations are calculated from the kernel size, see OpenCV for more details). The contours are determined from the edges using cv2.findContours (with the contour retrieval mode cv2.RETR_TREE and contour approximation algorithm cv2.CHAIN_APPROX_NONE). The contours shorter than Length defined in the Edge Detection tab are discarded.

The obtained contours are smoothed out using a Savitzky-Golay filter scipy.savgol_filter with third-order polynomials and a window length defined by Smoothing window (in pixels) in the Edge Detection tab.

From these smooth contours, the angles and the normal to the contours are computed. The angles ρ with respect to the contours are computed in a layer around the contours defined by Layer width (in pixels) in the Edge Detection tab. There is the possibility to slightly move away from the contour by changing Distance from contour in the Edge Detection tab. All the selected figures involving ρ are duplicated using the relative values of ρ with respect to the contours.

To close the edge detection module, click the (blue) button . The button goes back to orange.

For more information on the Canny edge detection, click here and here


Parameters

  • Low threshold: integer between 0 and 255 - hysteresis thresholding value used in the Canny edge detector: edges with intensity gradients below this value are not edges and discarded
  • High threshold: integer between 0 and 255 - hysteresis thresholding value used in the Canny edge detector: edges with intensity gradients larger than this value are sure to be edges
  • Length: minimum length of a contour (in pixels)
  • Smoothing window: length in pixels of the window used for the smoothing (using a Savitzky-Golay filter scipy.savgol_filter)

Layer

  • Distance from contour: number of pixels separating the contour from the layer
  • Layer width: width of the layer in the neighborhood of the contour (in pixels)