PaulM1985
November 24th, 2009, 07:09 PM
Hi
I am using Java to write a program that will perform flood filling.
The code I am using at the moment is:
private static void floodFill(BufferedImage aGreyImage, BufferedImage aColourImage, BufferedImage aEdgeImage, int aX, int aY)
{
tester++;
System.out.println("tester is " + tester);
if (tester > 10000)
return;
if (aX < 2 || aX > aEdgeImage.getWidth() - 1 || aY < 2 || aY > aEdgeImage.getHeight() - 1)
return;
Color colour = new Color(aEdgeImage.getRGB(aX, aY));
if (colour.getRed() < 25 && aGreyImage.getRGB(aX, aY) != aColourImage.getRGB(aX, aY))
{
aGreyImage.setRGB(aX, aY, aColourImage.getRGB(aX, aY));
if (aX > 2 && aX < aEdgeImage.getWidth() - 2 && aY > 2 && aY < aEdgeImage.getHeight() - 2)
{
floodFill(aGreyImage, aColourImage, aEdgeImage, aX, aY - 1);
floodFill(aGreyImage, aColourImage, aEdgeImage, aX - 1, aY);
floodFill(aGreyImage, aColourImage, aEdgeImage, aX, aY + 1);
floodFill(aGreyImage, aColourImage, aEdgeImage, aX + 1, aY);
}
}
}
It seems that I am getting an error. Because I seem to be unable to catch the error, I think it is because I am calling floodFill and going too deep into the stack.
Would anyone else be able to comfirm whether this may be the case and know of some work around?
The only bit of the errors I am able to get are the ones that point to the lines where flood fill is called again.
Paul
I am using Java to write a program that will perform flood filling.
The code I am using at the moment is:
private static void floodFill(BufferedImage aGreyImage, BufferedImage aColourImage, BufferedImage aEdgeImage, int aX, int aY)
{
tester++;
System.out.println("tester is " + tester);
if (tester > 10000)
return;
if (aX < 2 || aX > aEdgeImage.getWidth() - 1 || aY < 2 || aY > aEdgeImage.getHeight() - 1)
return;
Color colour = new Color(aEdgeImage.getRGB(aX, aY));
if (colour.getRed() < 25 && aGreyImage.getRGB(aX, aY) != aColourImage.getRGB(aX, aY))
{
aGreyImage.setRGB(aX, aY, aColourImage.getRGB(aX, aY));
if (aX > 2 && aX < aEdgeImage.getWidth() - 2 && aY > 2 && aY < aEdgeImage.getHeight() - 2)
{
floodFill(aGreyImage, aColourImage, aEdgeImage, aX, aY - 1);
floodFill(aGreyImage, aColourImage, aEdgeImage, aX - 1, aY);
floodFill(aGreyImage, aColourImage, aEdgeImage, aX, aY + 1);
floodFill(aGreyImage, aColourImage, aEdgeImage, aX + 1, aY);
}
}
}
It seems that I am getting an error. Because I seem to be unable to catch the error, I think it is because I am calling floodFill and going too deep into the stack.
Would anyone else be able to comfirm whether this may be the case and know of some work around?
The only bit of the errors I am able to get are the ones that point to the lines where flood fill is called again.
Paul