フィルターのクリア

I have to sort objects based on their areas in regionprops?

8 ビュー (過去 30 日間)
AMIT VERMA
AMIT VERMA 2015 年 4 月 9 日
回答済み: Matt J 2015 年 4 月 9 日
clc
clear
% take data frm xcl and look for selected area
Amp=xlsread('C:\Users\AMIT\Desktop\CB\excel\4\Cast Billet Amp Data-(4-4).xls');
Th=xlsread('C:\Users\AMIT\Desktop\CB\excel\4\Cast Billet Thickness Data-(4-4).xls');
Z=Amp(2:1:514,2:1:256);
T=Th(2:1:514,2:1:256);
for i=1:1:513
for j=1:1:255
if ((Z(i,j)>=40) && (Z(i,j)<=100)) % selecting high amp regions
A(i,j)=Z(i,j);
B(i,j)=T(i,j);
else
A(i,j)=0;
B(i,j)=0;
end
end
end
for i=1:1:513
for j=1:1:255
C(i,j)= A(i,j);
D(i,j)= B(i,j);
end
end
axes('FontSize',20);
image(A');figure
axes('FontSize',20);
imagesc(B');figure
for i=1:1:513
for j=180:1:225
if B(i,j)>=6.5 && B(i,j)<=7
A4(i,j)=C(i,j);
else
A4(i,j)=0;
end
end
end
axes('FontSize',20);
imagesc(A4');figure
ylim([120 225])
imagesc(A4');
background = imopen(A4',strel('disk',15));
I2 = A4'- background;
figure, imshow(I2)
I3 = imadjust(I2);
figure, imshow(I3);
level = graythresh(I3); %Threshold the Image
bw = im2bw(I3,level);
bw2=bwareaopen(bw,3);
figure, imshow(bw2)
cc = bwconncomp(bw2,8) %Identify Objects in the Image
P=cc.NumObjects;
SP=0.64/4;
defectdata = regionprops(cc, 'all') %Compute Area of Each Object
DA = SP*[defectdata.Area];
[min_area, idx] = min(DA) %Compute Area-based Statistics
[max_area, idx] = max(DA)
nbins = 20; %Create Histogram of the Area
figure, hist(DA,nbins)
title('Histogram of defect Area');
xlabel('Area of defect mm2');
ylabel('Number of defects')
Ylim ([0 50])
DA
b=A4';
NUM=numel(DA);
for p=1:NUM
pixlist=defectdata(p).PixelIdxList
pixnum=size(pixlist);
numarray(p)=pixnum(1);
end
minnum=min(numarray);
maxnum=max(numarray);
for defsize=minnum:maxnum
defsize
position=find(numarray==defsize)
a=0;
for k=position
[I J]=ind2sub([225 513],defectdata(k).PixelIdxList);
avg=0;
for w=1:defsize
avg=avg+b(I(w),J(w));
end
avg=avg/defsize
[I J]=ind2sub([225 513],defectdata(k).PixelIdxList);
horzcat(I,J)
end
end
% I just want to arrange defect data in ascending order according to area

回答 (1 件)

Matt J
Matt J 2015 年 4 月 9 日
[~,idx]=sort([defectdata.Area]);
defectdata=defectdata(idx);

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by