Search code examples
edge-detectioncanny-operator

calculate area of an image occupied by edges - canny edge detection


New to using the algorithm, and wondering is it possible to calculate the ratio of edges to non edges using the Canny Edge Detection Metric? if its not possible, how else would this be done?

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('icon3.jpg',0)
edges = cv2.Canny(img,100,200)

plt.subplot(121),plt.imshow(img,cmap = 'gray')
plt.title('Original Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(edges,cmap = 'gray')
plt.title('Edge Image'), plt.xticks([]), plt.yticks([])

plt.show()

The result of the code does detect the edges, however i would like to calculate area of the image that comprises of edges enter image description here


Solution

  • This was done by calculating the area of white divided by the area of black and multiply by 100 to get the percentage