I don't get how to set the fuzz(y) parameter for flood fill:

The fuzz member of image defines how much tolerance is acceptable to consider two colors as the same.

This code is working, changing all pixels from red to green, but only if it is exactly red:

ImageInfo imageInfo = new ImageInfo();
DrawInfo drawInfo = new DrawInfo(imageInfo);
PixelPacket targetColor = PixelPacket.queryColorDatabase("red");
PixelPacket greenColor = PixelPacket.queryColorDatabase("green");
drawInfo.setFill(greenColor);
int method = PaintMethod.FloodfillMethod;
boolean success = magickImage.colorFloodfillImage(drawInfo, targetColor, 0, 0, method);

I'm using android-lib-magick, but can also switch to any other solution that works.

Basically I am trying to do what this image magick console example does:

convert cyclops.png -bordercolor white -border 1x1 \
-alpha set -channel RGBA -fuzz 20% \
-fill none -floodfill +0+0 white \
-shave 1x1 cyclops_flood_3.png

So maybe there is a way to add arbitrary parameters to the image calculation?

有帮助吗?

解决方案

An own flood fill function in Java (with boolean[] visited, ..) lets you implement any color comparison algorithm! *self-high-five*

Accepted answer will be changed as soon as someone finds a better solution..

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top