I'm trying to calculate number of white granules and their diameters in a given image (e.g. below).
import cv2import numpy as npimport matplotlib.pyplot as pltimage = cv2.imread(r'D:\Downloads\IMG_0009.jpg')gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)blur = cv2.GaussianBlur(gray, (11, 11), 0)canny = cv2.Canny(blur, 10, 150)dilated = cv2.dilate(canny, (1, 1), iterations=2)(cnt, _) = cv2.findContours(dilated.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)cv2.drawContours(image, cnt, -1, (0, 0, 255), 2)cv2.imshow('Contours', image)cv2.waitKey(0)cv2.destroyAllWindows()print('image:', len(cnt))