HOW TO CALCULATE THE DICE SIMILARITY OF THE IMAGES SUBPLOT.

조회 수: 10 (최근 30일)
mohd akmal masud
mohd akmal masud 2021년 10월 24일
답변: yanqi liu 2021년 10월 26일
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

채택된 답변

yanqi liu
yanqi liu 2021년 10월 26일
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

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 10월 24일
Just read in I before the loop, then put the line
similarity(ii) = dice(I, II)
inside the loop.
  댓글 수: 3
Image Analyst
Image Analyst 2021년 10월 24일
Try this:
imds = imageDatastore(imageDir)
numFiles = length(imds.Files);
fprintf('Found %d image files.\n', numFiles);
% Read in first image.
thisFullFileName = imds.Files{1};
fprintf('Reading image #%d of %d : "%s" ...\n', ...
1, numFiles, thisFullFileName);
firstImage = imread(thisFullFileName);
imshow(firstImage);
% Read in and view subsequent images.
for k = 2 : numFiles
% Get the file name.
thisFullFileName = imds.Files{k};
fprintf('Reading image #%d of %d : "%s" ...\n', ...
k, numFiles, thisFullFileName);
thisImage = imread(thisFullFileName);
imshow(thisImage);
% similarity(k) = dice(firstImage, thisImage);
end
mohd akmal masud
mohd akmal masud 2021년 10월 25일
편집: mohd akmal masud 2021년 10월 25일
sir, What I mean is, I want compare all the image for set images
this one is expected (we known the area of the slice), have 23 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
this one is what I get after did some segmentation technique.
%% 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 want compare the dice similarity for every slice, like 1 with 1, 2 with 2, 3 with 3....and so on till 23 with 23..
I used this code for combine all the 23 images similarity, but the answer is 0.
similarity = dice(I, II)
similarity =
0
But when i test just one pair of image only, (let say image number 11 with 11), its can show the similarity coefficient.
I11 = imread('11.png'); %read from folder expected labelled
II11 = imread('11.png'); %read from folder after segmentation
similarity = dice(I11,II11)
similarity =
0.15119
can you got my point sir?

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

Community Treasure Hunt

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

Start Hunting!

Translated by