how to place the rectangle for all the blob

2 views (last 30 days)
Hi all,
I have 7 binary images.
anyone know how to place the rectangle for all the blob in the subplot binary images?
I used below coding, but only one binary image (the last images) have the rectangle
%% TEST IMAGES
DATASetDir = fullfile('C:\Users\Akmal\Desktop\I-131 256 28.02.2020\I-131 SPECT NEMA VALIDATION 01112019 256X256 26.09.2021 petang');
IMAGEDir = fullfile(DATASetDir,'Test');
IMDS = imageDatastore(IMAGEDir);
%% TO GET THE VOLUME SEGMENTATION AFTER DEEP LEARNING PERFORM
alldice=[]
acc=[]
Ts = [];
Ts2 = [];
for ii=1:7
subplot(3,3,ii)
I = readimage(IMDS,ii);
[C,scores] = semanticseg(I,net1);
outt2=C=="foreground";
st2=strel('disk',5);
outt22 = imopen(outt2,st2);
figure
title('output')
imshow(outt22)
fprintf('\nprocess %d image\n', ii);
T = regionprops('table', outt22,'Area','Centroid');
info = regionprops(outt22,'Boundingbox') ;
Ts{ii} = T;
Ts2 = [Ts2; T];
end
allbb=[]
for k = 1 : length(info)
BB = info(k).BoundingBox;
rectangle('Position', [BB(1),BB(2),BB(3),BB(4)],'EdgeColor','r','LineWidth',1) ;
allbb=[allbb; BB]
end

Accepted Answer

DGM
DGM on 11 Oct 2021
The second loop needs to be inside the first one, otherwise it's only going to plot the bounding boxes for the blobs in the last subplot.
  7 Comments
mohd akmal masud
mohd akmal masud on 12 Oct 2021
sorry sir, can you write more details. what is T.Area?
Star Strider
Star Strider on 12 Oct 2021
‘T’ is a table, and the ‘T.Area’ reference returns the values in the ‘Area’ variable as a column vector.
.

Sign in to comment.

More Answers (1)

yanqi liu
yanqi liu on 12 Oct 2021
%% TEST IMAGES
DATASetDir = fullfile('C:\Users\Akmal\Desktop\I-131 256 28.02.2020\I-131 SPECT NEMA VALIDATION 01112019 256X256 26.09.2021 petang');
IMAGEDir = fullfile(DATASetDir,'Test');
IMDS = imageDatastore(IMAGEDir);
%% TO GET THE VOLUME SEGMENTATION AFTER DEEP LEARNING PERFORM
alldice=[]
acc=[]
Ts = [];
Ts2 = [];
for ii=1:7
I = readimage(IMDS,ii);
[C,scores] = semanticseg(I,net1);
outt2=C=="foreground";
st2=strel('disk',5);
outt22 = imopen(outt2,st2);
figure(ii)
title('output')
imshow(outt22)
fprintf('\nprocess %d image\n', ii);
T = regionprops('table', outt22,'Area','Centroid');
info = regionprops(outt22,'Boundingbox') ;
Ts{ii} = T;
Ts2 = [Ts2; T];
end
allbb=[]
for ii=1:7
figure(ii);
hold on;
for k = 1 : length(info)
BB = info(k).BoundingBox;
rectangle('Position', [BB(1),BB(2),BB(3),BB(4)],'EdgeColor','r','LineWidth',1) ;
allbb=[allbb; BB]
end
end

Community Treasure Hunt

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

Start Hunting!