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 #

enter image description here

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


A simple approach could be



  • scan image for red pixel
  • do a FloodFill , keeping track of the minutes / max x and y for a successful color change ... when the fill ends you have one bounding box. Also, you have removed all red pixels for this blob
  • go 1 and continue scanning
+3


source


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







All Articles