Polymorphic floodfill boundary test
I do not know how the floodfill decide if it comes to a boundary or not, but
I guess that it always sampels information from the point where I clicked.
However, sometimes another test would be more useful. This piece of code is
polymorphic in boundary check:
class Graymap
{
public:
Graymap(unsigned int width,unsigned int height)
{
data=new unsigned char[width*height];
memset(data,0,width*height);
p_matrix=new unsigned char*[height];
for(unsigned int i=0;i Q;
FloodfillNode node={x,y};
// 2. Add node to Q.
Q.push_back(node);
// 3. For each element n in Q:
while(!Q.empty())
{
FloodfillNode n=Q.front();
Q.pop_front();
// 3a Set w and e equal to n.
FloodfillNode w=n;
FloodfillNode e=n;
assert(!w.x
{
// 3c2 If we have not been at the pixel one line above before
// And this pixel does not lie on the boundary
if(!dirty(e.x,e.y+1) && !boundaryAt(e.x,e.y+1))
{Q.push_back((FloodfillNode){e.x,e.y+1});}
}
e.x++;
}
}
}
One way to implement FloodfillConditionBoundary besides the traditional one
is to check the magnitude of the gradient vector at current pixel. This
would be useful if one has a picture with a smooth gradient surrounded by a
sharp edge and want to replace the smooth gradient with one solid color. If
I want to add the feature myself, where do I start?