How can I calculate the iou and dice for each slices in a CT volume to obtain the mean for all the volume?
1 次查看(过去 30 天)
显示 更早的评论
This is my code:
load("25_1_50epochs.mat")
destinationSkullTest11 = "C:\Users\User\Documents\SEM 7\FYP\Dataset\U-net\Image Test";
destinationMasksTest11 = "C:\Users\User\Documents\SEM 7\FYP\Dataset\U-net\Mask Test";
destinationPredictionFolder = "C:\Users\User\Documents\SEM 7\Deep Learning\Predicted Test";
pixelLabelID = [1 0];
classNames = ["fracture" "background"];
SkullFiles = dir(destinationSkullTest11);
SkullDirectoryNames = {SkullFiles([SkullFiles.isdir]).name};
SkullDirectoryNames = SkullDirectoryNames(~ismember(SkullDirectoryNames,{'.','..'}));
MaskFiles = dir(destinationMasksTest11);
MaskDirectoryNames = {MaskFiles([MaskFiles.isdir]).name};
MaskDirectoryNames = MaskDirectoryNames(~ismember(MaskDirectoryNames,{'.','..'}));
for z = 1:length(SkullDirectoryNames)
fullfileSkull = fullfile(destinationSkullTest11,SkullDirectoryNames(z));
fullfileMask = fullfile(destinationMasksTest11,MaskDirectoryNames(z));
imdstest11 = imageDatastore(fullfileSkull,"FileExtensions",".png","LabelSource","foldernames");
pxdstest11 = pixelLabelDatastore(fullfileMask,classNames,pixelLabelID,"FileExtensions",".png");
mkdir(fullfile(destinationPredictionFolder, MaskDirectoryNames{z}));
targetFolder = fullfile(destinationPredictionFolder, MaskDirectoryNames(z));
pxdsResults11 = semanticseg(imdstest11,net,"WriteLocation",targetFolder);
for t = 1:length(pxdsResults11.Files)
gt = readimage(pxdstest11,t);
pr = readimage(pxdsResults11,t);
confmat = segmentationConfusionMatrix(pr,gt);
% IoU = TP / (TP + FP + FN)
numeiou(t,:) = confmat(1,1);
denoiou(t,:) = confmat(1,1) + confmat(1,2) + confmat(2,1);
numeiouall = sum(numeiou);
denoiouall = sum(denoiou);
% Dice = 2TP / (2TP + FP + FN)
numedice(t,:) = 2*confmat(1,1);
denodice(t,:) = 2*confmat(1,1) + confmat(1,2) + confmat(2,1);
numediceall = sum(numedice);
denodiceall = sum(denodice);
end
miou(z,:) = sum(numeiouall)/sum(denoiouall);
mdice(z,:) = sum(numediceall)/sum(denodiceall);
end
meaniou = mean(miou);
meandice = mean(mdice);
3 个评论
Image Analyst
2022-5-29
Can you use your MATLAb drive? See the 9 spot menu item on the right of your icon in the upper right corner of this page.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!