Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使顶点对应于面积的MATLAB帮助_Matlab - Fatal编程技术网

使顶点对应于面积的MATLAB帮助

使顶点对应于面积的MATLAB帮助,matlab,Matlab,我有一个在matlab中绘制边界框的程序。它显示每个blob的区域。我已经按降序排列了区域。 现在我想让verticesX和Verticesy对应于我按降序排列的区域,以便进一步使用它。你能告诉我怎么吃吗 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 m

我有一个在matlab中绘制边界框的程序。它显示每个blob的区域。我已经按降序排列了区域。 现在我想让verticesX和Verticesy对应于我按降序排列的区域,以便进一步使用它。你能告诉我怎么吃吗

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)
全部清除;
全部关闭;
clc
I=imread('image.jpg');
......
bw2=im2bw(J(:,:,2),L);
子批次(2,3,4);
imshow(bw2);
%给每个斑点贴上标签,以便我们可以对其进行测量
[labeledImage numberOfBlobs]=bwlabel(bw2,8);
%获取所有blob属性。
blobMeasurements=regionprops(标签图像,'BoundingBox','Area');
allBlobAreas=[blobMeasurements.Area];
%循环通过所有斑点,建立边界框。
等等
对于k=1:numberOfBlobs
boundingBox=BlobMeasures(k)。boundingBox;%拿箱子。
x1=边界框(1);
y1=边界框(2);
x2=x1+边界框(3)-1;
y2=y1+包围盒(4)-1;
verticesX=[x1x2x2x1];
垂直性=[y1 y1 y2 y2 y1];
%计算宽高比。
aspectRatio(k)=边界框(3)/边界框(4);
fprintf('\n表示blob#%d,面积=%d,纵横比=%.2f\n',k,allBlobAreas(k),aspectRatio(k));
fprintf('\n VerticesofX=[%.2f%.2f%.2f%.2f%.2f],VerticesofY=[%.2f%.2f%.2f%.2f%.2f]\n',verticesX,verticesY);
%%按降序排列区域的循环
x(k)=所有Blobareas(k);
对于i=1:长度(x)-1
对于j=i+1:长度(x)
如果x(i)看看

[B,IX]=sort(A)
将对向量进行排序,并返回将A转换为排序后的A的索引

[B,IX]=sort(allBlobAreas,'descend');
sortedAreas=B; % equivalent to sortedAreas=allBlobAreas(IX);
sortedVerticesX=verticesX(IX);
sortedVerticesY=verticesY(IX);

这还可以让你用更简单的东西来代替排序算法。

那不是程序,只是几行文字。帮助我们帮助您,将代码块格式化为代码块。写问题(和答案)时,请看文本区域上方的小图标。对于代码,通常应该使用带有{}个字符的图标