Android Question Fill color boxes automatically.

vecino

Well-Known Member
Licensed User
Hello, is it possible or not possible?

The user uploads an image.
The software "finds" the boxes and filled with color.
The software saves the new image.

Impossible?

User image:
vacio.png


Generated image:
lleno.png
 

RandomCoder

Well-Known Member
Licensed User
Very helpful @DonManfred (and completely off-topic but I like the new Avatar :)).

So it's got me thinking, how would someone go about doing this?
I'm thinking that maybe create a Type called box...
B4X:
Type Box(Num As Int, x1 As Int, y1 As Int, x2 As Int, y2 As Int, Colour As Int)
Then create a canvas containing the image and scan from to left to right getting each individual pixel. Black pixels denote the edge of a box. Move down to the next row of pixels and repeat also checking for the bottom edge of the boxes.
Or, would it be easier to find the first box edge and bottom then move to finding the next box edge and bottom :confused:
 

sorex

Expert
Licensed User
it's possible but it might be slow on cheaper slower devices.
 
Last edited:

Troberg

Well-Known Member
Licensed User
Here's how I'd do it:

1. Find a white pixel.
2. Do a floodfill from that pixel in another color.
3. Repeat until there are no white pixels left.
 

stevel05

Expert
Licensed User
This is tricky, it will depend on the quality of the image. Flood fill would be good (is there a library that implements this?) if boundaries are all solid, and the background is white, not grey, or off white. I did a quick scan of the internet and there are a few links to java code that may do it. Try searching for one that looks promising and see if it can be ported. I'm sure there is a 'proper' way to do it and you may just stumble across a quick or at least accurate method.
 

sorex

Expert
Licensed User
the problem here is that you need to start over again after every fill since you don't know where the fills have drawn already.

so the more polygons you have the slower it will become.

this is not the case if the fill only occurs on an offset based on a press/touch on the picture.
 

sorex

Expert
Licensed User
can they only upload poly pictures like the one in the example or are they free?

if it is only squares you can make it really fast.
 

sorex

Expert
Licensed User
ok, then you can't benefit the fast scanning and plotting methods I had in mind.
 

Troberg

Well-Known Member
Licensed User
How many polygons can you expect? If it's few, my floodfil method will be plenty fast, but if it's thousands, you might want to reconsider.
 

sorex

Expert
Licensed User
if you know in advance where they are it can be fast but you need to rescan the image after every fill again to find and do the next none filled area.

you can store the last position then you can skip some of it.
 

Troberg

Well-Known Member
Licensed User
You can also do the scanning smarter. Remember how far you scanned last time before finding a white pixel, and resume from that point the next time. It's not like non-white pixels are going to turn white, so no need to re-scan.

Smart scanning like this, combined with flood fill, is probably as close to optimal as you can get with a reasonably simple algoritm.
 
Top