MATLAB help for having the vertices corresponding to area -


i have program in matlab draws bounding box. displays area of every blob.i have arranged areas in descending order. want have verticesx , vertixesy corresponding area have arranged in descending order use further. can u please tell how have it?

clear all;  close all;  clc  i=imread('image.jpg'); ...... bw2=im2bw(j(:,:,2),l);  subplot(2,3,4); imshow(bw2);  % label each blob can make measurements of  [labeledimage numberofblobs] = bwlabel(bw2, 8);  % blob properties.  blobmeasurements = regionprops(labeledimage, 'boundingbox','area');  allblobareas = [blobmeasurements.area];  % loop through blobs, putting bounding box. hold on;   k = 1 : numberofblobs  boundingbox = blobmeasurements(k).boundingbox;   % 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 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 having area in descending order x(k)=allblobareas(k);  i=1:length(x)-1  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) 

take @ the sort function built-in matlab

[b,ix]=sort(a) sort vector , return indices convert sorted-a.

[b,ix]=sort(allblobareas,'descend'); sortedareas=b; % equivalent sortedareas=allblobareas(ix); sortedverticesx=verticesx(ix); sortedverticesy=verticesy(ix); 

this let replace sorting algorithm simpler.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -