0

In the script based on remove-noise-in-bw-image, I try to fill the object (The equivalent of imfill in Matlab) but without success. Can someone please explain me how to do so.

Script:

import cv2
import numpy as np

#image can be found in https://i.stack.imgur.com/afCDL.jpg
filename = 'E:/afCDL.jpg'

img = cv2.imread(filename)
cv2.imwrite('E:/img.jpg',img)
cv2.imshow("Original Image", img)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.imwrite('E:/gray.jpg',gray)

bi = cv2.bilateralFilter(gray,5,25,25)

cv2.imwrite('E:/bi.jpg',bi)
blur = cv2.GaussianBlur(bi,(25,25),0)
cv2.imwrite('E:/blur.jpg',blur)
dog = blur - bi
cv2.imwrite('E:/DoG.jpg',dog)
cv2.imshow("DOG Image", dog)

kernel = np.ones((3,3),np.uint8)
fill = cv2.morphologyEx(dog, cv2.MORPH_CLOSE, kernel) #Fill holes- DOES NOT WORK
cv2.imshow("Fill", fill)
removeNoise = cv2.morphologyEx(fill, cv2.MORPH_OPEN, kernel) #Remove noise
cv2.imshow("remove Noise ", removeNoise)

cv2.waitKey(0)
cv2.destroyAllWindows()
Harshdeep Sokhey
  • 324
  • 5
  • 15
elyraz
  • 473
  • 5
  • 18

1 Answers1

1

Try reading this link. I think it addresses the question.

This post python-equivalent-to-matlab-funciton-imfill-for-grayscale also has some pointers.

Community
  • 1
  • 1
Harshdeep Sokhey
  • 324
  • 5
  • 15