how to calculate the area binary if some images have different pattern

조회 수: 1 (최근 30일)
Hi all I have 4 images that all images have 4 area(like circle) as below.
Then, I used this coding below to get the area for all the 4 images that every images have 4 circle
%% TO GET THE VOLUME SEGMENTATION AFTER DEEP LEARNING PERFORM(blob all the sphere binary)
alldice=[]
acc=[]
Ts = [];
Data = [];
for ii=1:4
subplot(1,4,ii)
I = readimage(IMDS,ii);
[C,scores] = semanticseg(I,net1);
outt2=C=="foreground";
st2=strel('disk',5);
outt22=imerode(outt2,st2);
% outt22(:,:,ii) = imerode(outt2,st2);
title('output')
imshow(outt22)
info = regionprops(outt22,'Boundingbox') ;
imshow(outt22)
hold on
allbb=[]
for k = 1 : length(info)
BB = info(k).BoundingBox;
rectangle('Position', [BB(1),BB(2),BB(3),BB(4)],'EdgeColor','r','LineWidth',2) ;
allbb=[allbb; BB]
end
vol = [];
for i=1:4
zz=imcrop(outt22,allbb(i,:));
stats = regionprops('table',zz,'Centroid',...
'MajorAxisLength','MinorAxisLength');
T = regionprops('table', outt22,'Area','Centroid')
m1=stats.MajorAxisLength;
m2=stats.MinorAxisLength;
v1=stats.MinorAxisLength;
vol(i)=m1*m2*(v1/2);
end
ss=sprintf('the volume %d is %6f,%d is %6f,%d is %6f,%d is %6f',1,vol(1),2,vol(2),3,vol(3),4,vol(4));
msgbox(ss);
end
Its work. And the answer like below
T =
4×2 table
Area Centroid
____ ________________
15 105.73 132.53
21 126.52 145.38
64 147.12 108.86
31 147.42 133.9
T =
4×2 table
Area Centroid
____ ________________
15 105.73 132.53
21 126.52 145.38
64 147.12 108.86
31 147.42 133.9
T =
4×2 table
Area Centroid
____ ________________
15 105.73 132.53
21 126.52 145.38
64 147.12 108.86
31 147.42 133.9
T =
4×2 table
Area Centroid
____ ________________
15 105.73 132.53
21 126.52 145.38
64 147.12 108.86
31 147.42 133.9
But when I tried the same code into this images below. It have error.
**NOTE: the first and second image just have 3 circle, the 2 others have 4 circle.
T =
3×2 table
Area Centroid
____ ________________
6 125.67 146.33
92 147.77 109.37
52 147.15 134.06
T =
3×2 table
Area Centroid
____ ________________
6 125.67 146.33
92 147.77 109.37
52 147.15 134.06
T =
3×2 table
Area Centroid
____ ________________
6 125.67 146.33
92 147.77 109.37
52 147.15 134.06
Index in position 1 exceeds array bounds (must not exceed 3).
anyone can help me?

채택된 답변

yanqi liu
yanqi liu 2021년 11월 3일
%% TO GET THE VOLUME SEGMENTATION AFTER DEEP LEARNING PERFORM(blob all the sphere binary)
alldice=[]
acc=[]
Ts = [];
Data = [];
for ii=1:4
subplot(1,4,ii)
I = readimage(IMDS,ii);
[C,scores] = semanticseg(I,net1);
outt2=C=="foreground";
st2=strel('disk',5);
outt22=imerode(outt2,st2);
% outt22(:,:,ii) = imerode(outt2,st2);
title('output')
imshow(outt22)
info = regionprops(outt22,'Boundingbox') ;
imshow(outt22)
hold on
allbb=[]
for k = 1 : length(info)
BB = info(k).BoundingBox;
rectangle('Position', [BB(1),BB(2),BB(3),BB(4)],'EdgeColor','r','LineWidth',2) ;
allbb=[allbb; BB]
end
vol = [];
for i=1:size(allbb,1)
zz=imcrop(outt22,round(allbb(i,:)));
stats = regionprops('table',zz,'Centroid',...
'MajorAxisLength','MinorAxisLength');
T = regionprops('table', outt22,'Area','Centroid')
m1=stats.MajorAxisLength;
m2=stats.MinorAxisLength;
v1=stats.MinorAxisLength;
vol(i)=m1*m2*(v1/2);
end
ss=sprintf('the volume %d is %6f,%d is %6f,%d is %6f,%d is %6f',1,vol(1),2,vol(2),3,vol(3),4,vol(4));
msgbox(ss);
end
  댓글 수: 3
yanqi liu
yanqi liu 2021년 11월 4일
%% TO GET THE VOLUME SEGMENTATION AFTER DEEP LEARNING PERFORM(blob all the sphere binary)
alldice=[]
acc=[]
Ts = [];
Data = [];
for ii=1:4
subplot(1,4,ii)
I = readimage(IMDS,ii);
[C,scores] = semanticseg(I,net1);
outt2=C=="foreground";
st2=strel('disk',5);
outt22=imerode(outt2,st2);
% outt22(:,:,ii) = imerode(outt2,st2);
title('output')
imshow(outt22)
info = regionprops(outt22,'Boundingbox') ;
imshow(outt22)
hold on
allbb=[]
for k = 1 : length(info)
BB = info(k).BoundingBox;
rectangle('Position', [BB(1),BB(2),BB(3),BB(4)],'EdgeColor','r','LineWidth',2) ;
allbb=[allbb; BB]
end
vol = [];
for i=1:size(allbb,1)
zz=imcrop(outt22,round(allbb(i,:)));
stats = regionprops('table',zz,'Centroid',...
'MajorAxisLength','MinorAxisLength');
T = regionprops('table', outt22,'Area','Centroid')
m1=stats.MajorAxisLength;
m2=stats.MinorAxisLength;
v1=stats.MinorAxisLength;
vol(i)=m1*m2*(v1/2);
end
ss = 'the volume';
for i = 1 : length(vol)
ss=sprintf('%s %d is %6f ', ss, i, vol(i));
end
msgbox(ss);
end

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Voss
Voss 2021년 11월 2일
You will have to adjust your code to handle cases when the number of regions in an image is not 4. In particular, the line
for i=1:4
can be changed to
for i = 1:length(info)
You will also need to modify your definition of ss for the same reason.

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by