We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello!
I'm somewhat of a newcomer to Processing. I would like to be able to take an image say of a red square on any contrasting background background, detect the edge of this square and use the resulting edge coordinates to deposit a series rectangles next to each other around the outside of the perimeter. I have playing around with some sobel and canny edge detection examples with not much luck, they just pick up darker pixels in the background.
Does anyone have any ideas? Thanks in advance!!
I've included the image I want to use for this task below: red_object
Answers
For this concrete example you could iterate over image pixels looking for minimum and maximum X-coordinate and Y-coordinate of the red pixels. This way you have the coordinates of the rectangle vertices. If the shape is different (but convex as a rectangle, a circle or an hexagon) you could try a Sobel convolution, but filtering the image before to denoise the background. Then you have to a apply an algorithm called 'convex hull'. I think Lee Byron's mesh library have a convex hull implementation. But it's an advanced topic. And finally, the more intelligent approach is to create the image by yourself so you don't have to extract information, that is always a tricky matter. You have a background image on which you draw the shapes with its exact coordinates. If you want the shapes to be more integrated with the background image you could use a blend mode as multiply.
I would use the Processing blobDetection libraries for this. http://www.v3ga.net/processing/BlobDetection/index-page-documentation.html
It will detect blobs depending on a set threshold. Each blob object it detects returns a set of sorted outline coordinates, which is what you need to draw the rectangles outside of the perimeter.
You might have to do some image processing to make sure the red is thresholded well. (maybe blurring to remove the noise, and some color filter for the red)