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!