Ask Your Question

Revision history [back]

floodFill loDiff/hiDiff not working?

I have been trying to implement floodFill to segment a image based on color. However it seems like no matter the values I use for loDiff/hiDiff the results remain the same. I tried everything between 0, and 10 000 as values on loDiff and hiDiff but the results remain the same. I had imagined a very high hiDiff and loDiff would result in the entire image being marked by floodFill.

I attached my code below.

#Load file
image = cv2.imread(inputfile)

#Pre process image
blob_image = image.copy()
blob_image = cv2.medianBlur(blob_image, 55) #Set high for demonstration purpose

#Watershed to segment by color
h, w = blob_image.shape[:2]
seedPoint = (0, 0)#(int(h/2), int(w/2))
mask = np.zeros((h+2, w+2), np.uint8)
newVal = 10
rect = 0
diff = 250
maskVal = 255
flags = 4 | ( maskVal << 8 ) | cv2.FLOODFILL_MASK_ONLY
newmask = cv2.floodFill(image = blob_image, mask = mask, seedPoint = seedPoint,
                        newVal = newVal, loDiff = diff, upDiff = diff, flags = flags)
#Visualize results
cv2.imshow("Original", image)
cv2.imshow("Blurred", blob_image)
cv2.imshow("Mask", mask)
cv2.waitKey(0)
cv2.destroyAllWindows()

floodFill loDiff/hiDiff not working?

I have been trying to implement floodFill to segment a image based on color. However it seems like no matter the values I use for loDiff/hiDiff the results remain the same. I tried everything between 0, and 10 000 as values on loDiff and hiDiff but the results remain the same. I had imagined a very high hiDiff and loDiff would result in the entire image being marked by floodFill.

I attached my code below.

#Load file
image = cv2.imread(inputfile)

#Pre process image
blob_image = image.copy()
blob_image = cv2.medianBlur(blob_image, 55) #Set high for demonstration purpose

#Watershed to segment by color
h, w = blob_image.shape[:2]
seedPoint = (0, 0)#(int(h/2), int(w/2))
mask = np.zeros((h+2, w+2), np.uint8)
newVal = 10
rect = 0
diff = 250
maskVal = 255
flags = 4 | ( maskVal << 8 ) | cv2.FLOODFILL_MASK_ONLY
newmask = cv2.floodFill(image = blob_image, mask = mask, seedPoint = seedPoint,
                        newVal = newVal, loDiff = diff, upDiff = diff, flags = flags)
#Visualize results
cv2.imshow("Original", image)
cv2.imshow("Blurred", blob_image)
cv2.imshow("Mask", mask)
cv2.waitKey(0)
cv2.destroyAllWindows()

floodFill loDiff/hiDiff not working?

I have been trying to implement floodFill to segment a image based on color. However it seems like no matter the values I use for loDiff/hiDiff the results remain the same. I tried everything between 0, and 10 000 as values on loDiff and hiDiff but the results remain the same. I had imagined a very high hiDiff and loDiff would result in the entire image being marked by floodFill.

Results below:

Original:

Original image

Pre processed:

Pre-processed image

Mask after floodFill:

Mask after flood fill

I attached my code below.below. I am using OpenCV version 3.2.0.

#Load file
image = cv2.imread(inputfile)

#Pre process image
blob_image = image.copy()
blob_image = cv2.medianBlur(blob_image, 55) #Set high for demonstration purpose

#Watershed to segment by color
h, w = blob_image.shape[:2]
seedPoint = (0, 0)#(int(h/2), int(w/2))
mask = np.zeros((h+2, w+2), np.uint8)
newVal = 10
rect = 0
diff = 250
maskVal = 255
flags = 4 | ( maskVal << 8 ) | cv2.FLOODFILL_MASK_ONLY
newmask = cv2.floodFill(image = blob_image, mask = mask, seedPoint = seedPoint,
                        newVal = newVal, loDiff = diff, upDiff = diff, flags = flags)
#Visualize results
cv2.imshow("Original", image)
cv2.imshow("Blurred", blob_image)
cv2.imshow("Mask", mask)
cv2.waitKey(0)
cv2.destroyAllWindows()