I'd like to find an edge strength value for each of the objects in a greyscale image using python. I'm detecting objects via thresholding to create a binary image and then opencv findContours to give me the edges. Some of these objects I detect in each image are blurry and I would like to exclude them based on the magnitude of the edge gradient for the contour (See image below for an example of an in focus object and a blurry object). What's the best way to go about processing the edge strength of each contour to give a value for the edge strength of each object such that I can exclude blurry ones based on some threshold I can work out?
contours, hierarchy = cv2.findContours(binary_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
edges = cv2.drawContours(original_image, contours, -1, (255, 255, 255), 1)
I use the above code on a binary image generated via thresholding to plot edges on the original image. The next step is to send the objects detected for processing, but I wish to exclude the blurry ones as they don't require further analysis. The pictures below show an image with the edges drawn on, I would like to find some value describing the average edge gradient from each edge pixel for each object I find, and only further process those who's edge magnitude is above some threshold, aka are in focus.
Original image:
With edges: