2012-03-09 8 views
0

私は境界ボックスを描画するプログラムをmatlabに持っています。それはすべてのBLOBの領域を表示します。私は降順で領域を配置しました。 私は頂点Xと頂点Yを、それをさらに使用するために降順に並べた領域に対応させたいと思っています。どうやってそれを持っているか教えてください。領域に対応する頂点を持つためのMATLABのヘルプ

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) 
+0

これはプログラムではなく、数行のテキストです。コードブロックをコードブロックとしてフォーマットしてください。あなたが質問(および回答)を書くときに、テキストエリアの上にある小さなアイコンを見てください。コードの場合、一般的に、{}文字を含むアイコンを使用する必要があります。 –

+0

可能な複製[他のリストに依存するリストを注文する必要があります。両方のリストを変更する方法?](http://stackoverflow.com/questions/2512864/i-need-to-order-a-list-that-is-dependant-on-another-list-how-to-change-両方のlis) – Jonas

答えて

0

the sort function built-in to MATLAB

[B,IX]=sort(A)を見てみましょうベクトルをソートし、ソート-AにAを変換インデックスを返します。

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

これにより、ソートアルゴリズムをもっと簡単に置き換えることもできます。

関連する問題