Android Question Fill color boxes automatically.

Discussion in 'Android Questions' started by vecino, Feb 7, 2015.

  1. vecino

    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
     
  2. DonManfred

    DonManfred Expert Licensed User

    No
     
  3. RandomCoder

    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...
    Code:
    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:
     
  4. DonManfred

    DonManfred Expert Licensed User

    It is NOT off-topic! He asked "Impossible?" and i gave the answer that it is not impossible.

    SO WHAT?
     
    Last edited: Feb 7, 2015
    lemonisdead, Peter Simpson and klaus like this.
  5. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Oh you do seem techy today @DonManfred :D
    You have misunderstood me, I was referring to myself being off topic with regard to your Avatar! That was all I meant by it ;)
     
    lemonisdead and DonManfred like this.
  6. sorex

    sorex Expert Licensed User

    it's possible but it might be slow on cheaper slower devices.
     
    Last edited: Feb 7, 2015
  7. DonManfred

    DonManfred Expert Licensed User

    Sorry then :)

    I like the new avatar too :D
     
  8. vecino

    vecino Well-Known Member Licensed User

    Then, do you have any idea?
     
  9. Troberg

    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.
     
    vecino likes this.
  10. stevel05

    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.
     
    vecino likes this.
  11. vecino

    vecino Well-Known Member Licensed User

    Yes, black and white :)
     
  12. sorex

    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.
     
  13. vecino

    vecino Well-Known Member Licensed User

    Yes, I understand :oops:
     
  14. sorex

    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.
     
  15. vecino

    vecino Well-Known Member Licensed User

    The polygons may be squares, rectangles, triangles, etc.
     
  16. sorex

    sorex Expert Licensed User

    ok, then you can't benefit the fast scanning and plotting methods I had in mind.
     
  17. vecino

    vecino Well-Known Member Licensed User

    Wow, bad luck :(
     
  18. Troberg

    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.
     
  19. sorex

    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.
     
  20. Troberg

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice