graphics – Overlay BoundingBoxes of detected objects in an image

I have a picture in which I want to detect bright objects and superimpose the bounding boxes measured.


enter the description of the image here

My idea was:

  • binarize the image
  • remove small objects
  • measure all bounding boxes
  • create squares of BoundingBox the coordinates
  • superimpose these squares with the original image (can be of a certain color)

The code up to now:

image = Import[""];

th = FindThreshold[image, Method -> "Entropy"];

binImage = Binarize[image, th];

correctedImage = DeleteSmallComponents[binImage, 1];

objectImage = ImageMultiply[testImage, correctedImage];

objectBoundesBoxes =
Values ​​@ ComponentMeasurements[objectImage, "BoundingBox"];

objectCorners =
objectBoundesBoxes /. {{xmin_, ymin_}, {xmax_, ymax _}}:> {{xmin,
ymin}, {xmax, ymin}, {xmax, ymax}, {xmin, ymax}, {xmin, ymin}};

The rectanagle of the first object would be:


enter the description of the image here

A list of all the squares using Line would be:

allSquares = Line[#] & / @ objectCorners;

How can I superimpose these squares of a certain color in the image