Reputation: 398
what would be the easiest way to programmatically get the rectangles around the objects in the image? looking for a solution in c#
i'm not entirely sure how to approach the search for this. any hints are highly welcome.
*edit: As Bobby guessed correctly, I'm trying to find the surrounding rectangles around the blobs. The spots vary in size and shape and position. They could be star shaped and round for instance. As TaW stated I would need to figure out what pixels are connected to each other. How would you deal with holes?
best wishes
Upvotes: 3
Views: 1248
Reputation: 6591
A simple approach could be
Upvotes: 3
Reputation: 20068
This is simplified question of Find Waldo assuming you can call Wolfram language in C#.net. I do not have Wolfram on this computer, but it should be something like:
img = Import["https://i.sstatic.net/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}]]
Very similar result, what i based my answer on : segmentation analysis
Upvotes: 1