Iam working on a dataset of 150 images for pothole detection. The ouput is a binary image after applying the morphological operations and i want to calculate the number of TP, FP,TN and FN for the dataset.
For example in the output image, the pothole area is covering the black pixels and the background is of white pixels for all set of images. The below image is the original image and the corresponding binary image is the output.
The below is the code for the dataset iam working…….how to calculate the parameters TP,FP,TN,FN for the below code..
clc;clear all;close all;myTrainingFolder = 'C:\Users\Admin\Desktop\New folder (2)';trainingSet = imageDatastore(myTrainingFolder,'IncludeSubfolders', true, 'LabelSource', 'foldernames');imageSize = [300 300];spectra = imageSize;trainingSetLabels = countEachLabel(trainingSet);numImagesTraining = numel(trainingSet.Files);for j = 1 : numImagesTraining I = imread(trainingSet.Files{j}); img = imresize(I,imageSize); spectra = spectralclust(img);% spectral clustering
BW = imbinarize(spectra,1);imagen = bwareaopen(BW,1); se=ones(3,3);img1 = imerode(imagen,se); %final output after applying erosion
numWhitePixels = sum(img1(:)); numBlackPixels = sum(~img1(:)); percentageWhite = nnz(img1) / numel(img1); percentageBlack = nnz(~img1) / numel(img1); if ( percentageBlack <= percentageWhite) disp('it is a pothole'); imwrite(img1,[['C:\Users\Admin\Desktop\Major Project\training_output\outputp_' num2str(j)] '.png']);else disp('it is not a pothole'); imwrite(img1,[['C:\Users\Admin\Desktop\Major Project\training_output\outputnp_' num2str(j)] '.png']); endend
thank you in advance
Best Answer