How to find size of an object inside the bounding box?

5 次查看(过去 30 天)
From the above image I want to find the size of that particular white region? How can we achive that?
i have used the below code
bounding_boxes = bboxes;
s=scores;
% Read the image
image = I;
pixels_per_mm=5;
[max_s,max_idx] =max(s);
selected_box= bounding_boxes(max_idx,:);
selected_object= imcrop(image,selected_box);
num_white_pixels=sum(selected_object(:) ==255);
object_size_mm = num_white_pixels / pixels_per_mm^2;
object_size = size(selected_object);
object_are= numel(selected_object);
i got output. But i dont know wheather it is correct approach or not?

回答(1 个)

Sanju
Sanju 2024-3-11
I understand that you have developed a code to find the size of the white region in the selected object, the approach you have taken seems to be correct.
Here's a breakdown of the steps you have followed,
  1. You have obtained the bounding boxes and scores of the detected objects.
  2. You have selected the bounding box with the highest score.
  3. You have cropped the image using the selected bounding box to isolate the selected object.
  4. You have counted the number of white pixels in the selected object.
  5. You have calculated the size of the object in millimetres by dividing the number of white pixels by the square of the pixels per millimetre.
  6. You have obtained the size of the object in terms of its dimensions using the size function.
  7. You have obtained the area of the object by counting the number of elements in the selected object.
Overall, your approach seems reasonable for finding the size of the white region in the selected object.
Note: it's important to validate it based on the specific requirements of your application and the characteristics of your images.
Hope this Helps!

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by