0

I could not manage to use floodfill function on my image that has several unconnected components. I would like all the holes to be filled with White. To do so, I could have used closing operation . However, since it merged close conductors , I would rather floodfill operation than morphological ones to retain the whole form of the image. https://i.stack.imgur.com/fYuvT.jpg

I am aware that since there are several components , I need to use mask and update it accordingly to get passed the next components. I tried to implement the explanations given below and documentation. OpenCV floodfill with mask

holes = blurred_defective.copy()
holes1 = blurred_golden.copy()

height, width = holes.shape[:2]
seed = (width/2,height/2)
mask = np.zeros((height+2, width+2), np.uint8)  

fillvalue = 255
cv2.floodFill(holes, mask,(0,0),(10,)*3, (10,)*3 ,8 |  cv2.FLOODFILL_MASK_ONLY | (fillvalue << 8))
cv2.floodFill(holes1,mask,(0,0),(10,)*3,(10,)*3 ,8 | cv2.FLOODFILL_MASK_ONLY | (fillvalue << 8))

 holes  = cv2.bitwise_not(holes)     
 holes1 = cv2.bitwise_not(holes1)

 c_defective_ff = blurred_defective | holes     
 c_golden_ff = blurred_golden | holes1

As a result of it , I got totally white image.

Furkan Ülger
  • 13
  • 1
  • 6
  • Possible duplicate of [Python 2.7: Area opening and closing binary image in Python not so accurate](https://stackoverflow.com/questions/45968617/python-2-7-area-opening-and-closing-binary-image-in-python-not-so-accurate). That duplicate should cover your case exactly, but feel free to expand if it doesn't (I wrote the answer there so I can answer any questions with it). – alkasm Dec 21 '18 at 19:57
  • Thanks for your reply. However, I would like learn the way of updating my mask not to lose background , . Your coding is for 1 connected component . I could not modify my coding for several connected components. – Furkan Ülger Dec 23 '18 at 07:33

0 Answers0