使用MATLAB的图像边界框 [英] Bounding box using MATLAB for the image
本文介绍了使用MATLAB的图像边界框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在下图中的白色斑点周围绘制一个边界框:
I am trying to draw a bounding box around the white blob in the image below:
我喜欢这样:
bw = imread('box.jpg');
bw=im2bw(bw);
imshow(bw)
L = bwlabel(bw);
s = regionprops(L, 'Area', 'BoundingBox');
s(1);
area_values = [s.Area];
idx = find((100 <= area_values) & (area_values <= 1000)); % list of all the objects
%whose area is between 100 and 1000
bw2 = ismember(L, idx); %construct a binary image containing all the objects whose
%area is between 100 and 1000 by passing L and idx to ismember.
imshow(bw2)
输出bw2,到目前为止是:
The output bw2, so far is:
有人可以一个告诉我如何在这个blob周围绘制一个边界框(白色)?
Can someone one tell me how to draw a bounding box around this blob(white)?
更新
Wajih的回答实际上准确地解决了这个问题。
Update Wajih's answer actually accurately solved the issue.
推荐答案
Pseduo -
Pseduo -
- 选择最大的y,最大的x,最小的x,最小的y与blob。也就是说,斑点上的点。这些是您可以用来构建边界框的坐标。
假设图像的左上角为(0,0)
assuming top left of image as (0,0)
(smallestX,smallestY)-----------------(largestX,smallestY)
| |
| |
| |
| |
(smallestX,largestY)------------------(largestX,largestY)
用于查找最小值/最大值和指数。
And for finding minimum/maximum values and indices.
[r,c]=find(img==min(min(img)))
[r,c]=find(img==max(max(img)))
r,c代表img矩阵中的行和列。
r,c represent row and column in the img matrix.
- 我已在图像上标记了可用于创建边界框的点。
- 缩放图像以获得更好的视图。
这篇关于使用MATLAB的图像边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文