Flood fill with paint bucket but wrap around image? - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: General questions (https://www.gimp-forum.net/Forum-General-questions) +--- Thread: Flood fill with paint bucket but wrap around image? (/Thread-Flood-fill-with-paint-bucket-but-wrap-around-image) |
Flood fill with paint bucket but wrap around image? - notl - 08-28-2023 I'd like to be able to use the paint bucket tool to flood fill contiguous areas, but in way that treats the image as if it wraps around, such that the left edge connects with right edge and top connects with bottom (effectively a toroidal map). Is there a way to do this in GIMP? I need this because I'm colouring images that are square in proportion with a pattern that tessellates. These images are generated with cellular automaton rules. See example images. First shows a starting image. [attachment=10271] Same image with one connected line flood filled as if with wrap-around: [attachment=10272] Showing how it connects when tessellated. [attachment=10273] Until recently, I've been colouring by hand, using the paint bucket to fill an area, identifying where it reaches an edge, then identifying where it connects on the opposite side, then flood filling that new area, and so on until it returns to the bit that was first filled. More recently I've been using the Cartesian Transform in the Deformations menu of G'MIC, applying a +1 pixel shift to both X and Y after the first flood fill, which pushes the bottom and right edges over to the opposite sides, showing where to continue the flood fill (instead of judging by eye or by measuring X.Y position). Then applying a -1 shift to X and Y and doing a flood fill from there, and so on until it is complete. It's looking like the only way to fully automate it is to re-write the code for the flood fill algorithm, so that instead of stopping at the edges of an image it looks at the adjacent pixels on the opposite connecting edge. I've got some coding experience, mainly with Mathematica which I use to generate these cellular automaton images, but am not really a programmer. So any suggestions for how to implement this would be appreciated. RE: Flood fill with paint bucket but wrap around image? - PixLab - 08-28-2023 (08-28-2023, 04:13 PM)notl Wrote: using the paint bucket to fill an area, identifying where it reaches an edge, then identifying where it connects on the opposite side, then flood filling that new area, and so on until it returns to the bit that was first filled. I'm not going to help you code something, it's way above my head, on the other hand I'll show you how to do it in GIMP without you having the need to search to identify where is where. There is a tool that does not show up in the tool box by default, it's called Offset Go to Edit > Preferences a window opens, go to Interface > Toolbox on the left side scroll-down and tick the eye of the Offset tool, now it appears in the toolbox [attachment=10274] Colore your things, once you have reached the edges, select the Offset tool then click on your image, a window open click on that biggest button w/2 - h/2 >OK Continue to color, once reached the edges, reselect the Offset tool, do it again... once you cannot reach any edge, you're done, no labyrinth to follow, no calculation needed If the black pattern does not look like the original at the end, just put it back to the original pattern with .. -> yes again -> the Offset tool one more time Yes I did colored it with the bucket tool -> line art detection "on", and the offset tool [attachment=10275] RE: Flood fill with paint bucket but wrap around image? - Blighty - 08-28-2023 Another possibility: Use Filters > Map > Tile Change the W and H to 272*3. Image is now 816x816 Set guides to show 3x3 matrix Working on the centre portion, select and bucket fill. When done, crop out the centre 272x272 portion. RE: Flood fill with paint bucket but wrap around image? - notl - 08-28-2023 Thanks. This helps a lot. (08-28-2023, 04:55 PM)PixLab Wrote:After setting the preferences as you described, I used this approach to colour an image. It's essentially the same as the method I'd previously been using that shifts the image by +1/-1 pixel in both X and y. The main difference is that the ends of the lines are to be found along the vertical or horizontal mid point, instead of at the edges of the image. Both Offset and G'MIC Cartesian transform can be set in terms of absolute pixel dimensions or relative to image dimensions, so they do the same job, but this tool is quicker than going through the G'MIC filter menu.(08-28-2023, 04:13 PM)notl Wrote: using the paint bucket to fill an area, identifying where it reaches an edge, then identifying where it connects on the opposite side, then flood filling that new area, and so on until it returns to the bit that was first filled. (08-28-2023, 07:49 PM)Blighty Wrote: Another possibility: Thanks. I've tried this, and it usually works for smaller images but it's not so good for for larger ones. A grid larger than 3x3 may be needed for some of the larger patterns. But making a 2x2 or 3x3 is a good way of checking that the method above has worked or not. |