【发布时间】:2025-12-22 16:35:12
【问题描述】:
我在 matlab 中有一个绘制边界框的程序。它显示了每个 blob 的区域。我按降序排列了这些区域。 现在我想让 verticesX 和 vertixesY 对应于我按降序排列的区域以进一步使用它。你能告诉我如何拥有它吗?
clear all;
close all;
clc
I=imread('image.jpg');
......
bw2=im2bw(J(:,:,2),L);
subplot(2,3,4);
imshow(bw2);
% Label each blob so we can make measurements of it
[labeledImage numberOfBlobs] = bwlabel(bw2, 8);
% Get all the blob properties.
blobMeasurements = regionprops(labeledImage, 'BoundingBox','Area');
allBlobAreas = [blobMeasurements.Area];
% Loop through all blobs, putting up Bounding Box.
hold on;
for k = 1 : numberOfBlobs
boundingBox = blobMeasurements(k).BoundingBox; % Get box.
x1 = boundingBox(1);
y1 = boundingBox(2);
x2 = x1 + boundingBox(3) - 1;
y2 = y1 + boundingBox(4) - 1;
verticesX = [x1 x2 x2 x1 x1];
verticesY = [y1 y1 y2 y2 y1];
% Calculate width/height ratio.
aspectRatio(k) = boundingBox(3) / boundingBox(4);
fprintf('\n For blob #%d, area = %d, aspect ratio = %.2f\n' ,k, allBlobAreas(k), aspectRatio(k));
fprintf('\n VerticesofX=[%.2f %.2f %.2f %.2f %.2f],VerticesofY=[%.2f %.2f %.2f %.2f %.2f]\n',verticesX,verticesY);
%% Loop for having area in descending order
x(k)=allBlobAreas(k);
for i=1:length(x)-1
for j=i+1:length(x)
if x(i)<x(j)
c=x(i);
x(i)=x(j);
x(j)=c;
end
end
end
end
%% Displays area in descending order
disp(x)
【问题讨论】:
-
那不是程序,是几行文字。帮助我们帮助您,将代码块格式化为代码块。写问题(和答案)时,请查看文本区域上方的小图标。对于代码,您通常应该使用带有 {} 字符的图标。
标签: matlab