MATLAB Answers

calculation of TP, FP,TN and FN for the dataset

조회 수: 78(최근 30일)
Srinidhi Gorityala
Srinidhi Gorityala 23 Jan 2020 15:00
댓글: KALYAN ACHARJYA 24 Jan 2020 3:53
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 to calculate the parameters TP,FP,TN,FN for the below code..
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);
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']);
disp('it is not a pothole');
imwrite(img1,[['C:\Users\Admin\Desktop\Major Project\training_output\outputnp_' num2str(j)] '.png']);
thank you in advance

  댓글 수: 0

로그인 to comment.

채택된 답변

KALYAN ACHARJYA 23 Jan 2020 16:53
편집: KALYAN ACHARJYA 23 Jan 2020 16:54
For basic understanding, lets say seg_im is the segmented binary image as per ROI and gold_im is the gold data/ground truth image data (Pixel by Pixel), considering white pixels ROI, black pixels non ROI
TN=sum(~seg_im && ~gold_im)); %Sum all black pixels in seg_im=gold_im
Apply the simmilar logical operators for FP and FN
FP=ROI not there but detected as ROI
FN=ROI there but not detected as ROI

  댓글 수: 2

Srinidhi Gorityala
Srinidhi Gorityala 23 Jan 2020 17:34
@KALYAN ACHARJYA...i want to calculate the total number of TP's, TN's , FP's and FN's from the dataset. But it is giving me the total number of pixels that are TP and TN that is TP = 1x300....
KALYAN ACHARJYA 24 Jan 2020 3:53
Steps: Initialize=TP=0,TN=0....
  1. Call the image
  2. Segment it
  3. Calculate TP,TN...
  4. Select the appropriate, is it TP, or FN based on certain threshold
  5. Say if based on TP pixels value, as compare to other parameters,lets decided image is TP, then
case TP
case FN
so on
See the case statements, or you can do with if elseif also.

로그인 to comment.

추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by