OpenCV floodfill with mask

All zero-valued pixels in the same connected component as the seed point of the mask are replaced by the value you specify. This value must be added to the flags parameter, left-shifted by 8 bits: uchar fillValue = 128; cv::floodFill(img, mask, seed, cv::Scalar(255) ,0, cv::Scalar(), cv::Scalar(), 4 | cv::FLOODFILL_MASK_ONLY | (fillValue << 8)); A simple, … Read more

Flood Fill Algorithms

The Wikipedia article is pretty good. As long as your grids are small, just about anything will work. Earlier this fall I did some flood filling on 10 megapixel scanned images. (The problem was to remove black edges from book pages that had been scanned on a photocopier.) In that case there are only two … Read more

Flood fill using a stack

You can use Queue to remove recursion from floodfill algorithm. Here are some basic ideas: Have a way to mark visited points At the beginning, queue the start point. While the queue is not empty, continue dequeuing its element. And with each element Fill its color and mark just-dequeued point as visited Enqueue unvisited adjacent … Read more

How can I perform flood fill with HTML Canvas?

To create a flood fill you need to be able to look at the pixels that are there already and check they aren’t the color you started with so something like this. const ctx = document.querySelector(“canvas”).getContext(“2d”); ctx.beginPath(); ctx.moveTo(20, 20); ctx.lineTo(250, 70); ctx.lineTo(270, 120); ctx.lineTo(170, 140); ctx.lineTo(190, 80); ctx.lineTo(100, 60); ctx.lineTo(50, 130); ctx.lineTo(20, 20); ctx.stroke(); floodFill(ctx, … Read more