How do I get rectangles around objects in the image?
What's an easy way to programmatically get rectangles around objects in an image? looking for a solution in c #
I'm not really sure how to approach looking for this. any hints are appreciated.
* Edit: As Bobby correctly understood, I am trying to find the surrounding rectangles around the drops. Items vary in size, shape, and position. For example, they can be star-shaped and round. As TaW stated, I will need to figure out which pixels are related to each other. How would you deal with holes?
best wishes
+3
source to share
2 answers
This is a simplified Find Waldo question , assuming you can name the Wolfram language in C # .net. I don't have Wolfram on this computer, but it should be something like:
img = Import["http://i.stack.imgur.com/qlVlM.png"];
objectshape = SelectComponents[DeleteBorderComponents[Binarize[img, {0, .7}]], "Area"}, 10 < #1 < 1000 && #2 > 0 &];
shapes = ComponentMeasurements[ImageMultiply[img, objectshape], {"BoundingBoxArea"}][[All, 2]];
Show[img, Graphics[{Red, Thick, Rectangle @@ # & /@ shapes}]]
A very similar result that I based my answer on: segmentation analysis
+1
source to share