Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a Flood Fill Algorith to create an Array
    primarykey
    data
    text
    <p>I'm using a flood fill algorithm to sort through an image. If it encounters the same color, I want it copy that pixel over into an identically sized array called filled. The array filled is then transformed back into an image and saved as a jpg. However, when I open the jpg, it appears entirely black. </p> <pre><code>public static void findFace(int[][] image) throws IOException { int height = image.length; int width = image[0].length; Color centerStart = new Color(image[width / 2][height / 2]); int[][] filled = new int[width][height]; floodFill(width / 2, height / 2, centerStart, image, filled); //construct the filled array as image. Show if the face was found. BufferedImage bufferImage2 = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); for (int y = 0; y &lt; height; y++) { for (int x = 0; x &lt; width; x++) { int Pixel = filled[x][y] &lt;&lt; 16 | filled[x][y] &lt;&lt; 8 | filled[x][y]; bufferImage2.setRGB(x, y, Pixel); } } //save filled array as image file File outputfile = new File("/home/lily/Pictures/APicaDay/saved.jpg"); ImageIO.write(bufferImage2, "jpg", outputfile); } public static int[][] floodFill(int x, int y, Color targetColor, int[][] image, int[][] filled) { if (image[x][y] != targetColor.getRGB()) { return filled; } filled[x][y] = image[x][y]; floodFill(x - 1, y, targetColor, image, filled); floodFill(x + 1, y, targetColor, image, filled); floodFill(x, y - 1, targetColor, image, filled); floodFill(x, y + 1, targetColor, image, filled); return filled; } </code></pre> <p>bonus question: I would like the flood fill to also accept colors that are similar, but not the exact same, since I'm dealing with a photograph.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload