About building a boundary around an object in an image

How can I build a boundary around an object in an image?
I tried setbackgroundpixelcolor and drawpoint.Their performance is not satisfactory.

Hello Tom

... is this something that has to be done by the App because the App Users can import their own images? Can we see a representative image and where the boundary should go?

Maybe try an edge detection and following algorithm to reduce the number of points to test?

1 Like

Around this moneybag there has to be a boundary. Can you please show me the code? I am really stuck.

Not really clear what you are after Tom

Do you want this


or this


or something else ?

Uploading: 9fd73012a2821d9091bfb80f358a0ed753e8748a.jpeg...
This one.
Can you show me the code?
It will be a big help.

I just used a program called Pinta to draw on it freehand, as an example.

It may be possible to do something with imagemagick (you would need an online server with imagemagick installed, and running php:

or have a look through the extensions (some may be paid) to see if there is something that will do it.

Of course it can be done manually using the Canvas.

Have you seen my code block?
My main problem is that the setbackgroundpixelcolor is not working as I expected it to.Same goes for drawpoint method.
Whenever the rgb values goes below 150 the code should draw a point.But it is not doing so.
Can you just help me with that?

No, your upload failed.


My block and the result I am getting.
Just help me fix this block.

Firstly, debug your split value by putting it into a Label.

You should see 4 values, RGBA

I have got as far as selecting all the background, now moving on to drawing the border....

I was going to suggest that:

If pixel colour @ x,y != background colour then plot point @ x, (y-1)

Potentially too slow on a smartphone?

Tom, your image has one end painted over - can you upload the original?

Not practical to go pixel by pixel, takes too long and is unwieldy. Needs a different approach.....

Would be good to understand exactly why this needs to be done, and in what context ?

My main goal was to identify gematric shape of a given object.For that I placed the object on a white background and scanned the image.Whenever the pixel value was less than a certain value it would detect an edge.The number of points at the edge could be used to identify if it was rectangular or circular.This was my approach.
Can you suggest a differemt approach without using any external apps?

Are you able to use image processing software after the scan (any proper program e.g. photoshop/gimp etc...) to do this? (As a minimum to make the background transparent and save image as a png)