I am having a 16 bit image from which I am trying to detect edges. I converted the image to 8 bit and then applied edge detection. I am getting edges using Sobel, however, Canny doesn't detect edges.
Why does this happen ?
The original image is attached here.(https://i.stack.imgur.com/uY0KI.png)
The code is given below:
from skimage import feature
from skimage import filters
#Read image
image = cv2.imread("Path_to_img",0)
edge_sobel = filters.sobel(image)
edges_canny = feature.canny(image, sigma=0)
The issue with the Canny edge detector is related to the fact that the original image has a very low "dynamic range".
image.min()=9image.max()=15The dynamic range is only 15-9 =
6(up to 7 levels of gray).The Canny has two optional threshold arguments, described here:
According to the documentation, defaults for
uint8type are:low_threshold = 255*0.1=25.5andhigh_threshold= 255*0.2=51.Since the pixel levels range of the
imageis only 6 (and not 255), none of the edges passes the threshold, and no edge is detected.We may compute
drangeand setlow_threshold=drange*0.1andhigh_threshold=drange*0.2:An alternative solution is applying
cv2.normalizebefore Canny (linear "stretching" the image to range [0, 255]):Code sample:
Result: