Scene
After the pretreatment of Rice, the two-value image is opened and then canny edge detection is done.
python Code:
1 #kernel = cv2.getstructuringelement (cv2. Morph_ellipse, (3,3)) # The nucleus of the ellipse2 3Kernel = Np.ones ((3,3), np.uint8)#white noise removal, morphological open operation, 3x3 linear core4 5opening = Cv2.morphologyex (Thresh, Cv2. Morph_open, kernel, iterations = 2)6 7Cv2.imshow ("opening", opening)8 9 Ten Oneedges = Cv2. Canny (opening,50,200) A -Cv2.imshow ("edges", edges)
View Code
The resulting image is as follows:
The left side is a structured element of the ellipse core, the right is a linear core, you can see the left side is significantly less than the right loss, for specific image processing benefits, it is recommended to use structured elements to build the morphological transformation parameters.
Effects of morphological structural elements on morphological image processing in opencv_