HOW TO CALCULATE THE DICE SIMILARITY OF THE IMAGES SUBPLOT.
12 views (last 30 days)
Show older comments
Hi all, I have 2 data set logical images(binary images). EACH DATA SET HAVE 23 IMAGES. I want to check the dice similarity.
Below is the code for aorigional images.
%% first, read the image data and labelled images
clc
clear all
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,'labelledimages');
imds = imageDatastore(imageDir);
% view data set images origional
figure
for i = 1:23
subplot(5,5,i)
I = readimage(imds,i);
imshow(I)
title('training labels')
end

The the second one images code is below
%% second, read the binary images after segmentation
dataSetDir1 = fullfile('C:\Users\Akmal\Desktop\I-131 256 28.02.2020\I-131 SPECT NEMA VALIDATION 01112019 256X256 26.09.2021 petang');
imageDir1 = fullfile(dataSetDir1,'bnwaftersegmentation');
imds1 = imageDatastore(imageDir1);
% view data set images origional
figure
for ii = 1:23
subplot(5,5,ii)
II = readimage(imds1,ii);
imshow(II)
title('binary labels')
end

Then i used code below to know the dice similarity, but the answer is 0
similarity = dice(I, II)
similarity =
0
But I try test just one image (let say image number 11), its work.
s = imread('11.png');
d = imread('11.png');
similarity = dice(s,d)
similarity =
0.15119
ANYONE CAN HELP ME HOW TO CALCULATE THE TOTAL DICE SIMILSRITY FOR ALL 23 IMAGES
0 Comments
Accepted Answer
yanqi liu
on 26 Oct 2021
sir,please check the follow code to get some information
%% first, read the image data and labelled images
clc
clear all
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,'labelledimages');
imds = imageDatastore(imageDir);
% view data set images origional
Is = [];
figure
for i = 1:23
subplot(5,5,i)
I = readimage(imds,i);
Is{end+1} = I;
imshow(I)
title('training labels')
end
%% second, read the binary images after segmentation
dataSetDir1 = fullfile('C:\Users\Akmal\Desktop\I-131 256 28.02.2020\I-131 SPECT NEMA VALIDATION 01112019 256X256 26.09.2021 petang');
imageDir1 = fullfile(dataSetDir1,'bnwaftersegmentation');
imds1 = imageDatastore(imageDir1);
% view data set images origional
Is2 = [];
figure
for ii = 1:23
subplot(5,5,ii)
II = readimage(imds1,ii);
Is2{end+1} = II;
imshow(II)
title('binary labels')
end
%% compare the dice similarity for every slice, like 1 with 1, 2 with 2, 3 with 3....and so on till 23 with 23..
similarity = [];
for i = 1 : 23
similarity(i) = dice(Is{i}, Is2{i});
fprintf('the dice similarity for %d with %d is %.3f\n', i, i, similarity(i));
end
0 Comments
More Answers (1)
Image Analyst
on 24 Oct 2021
Just read in I before the loop, then put the line
similarity(ii) = dice(I, II)
inside the loop.
3 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!