Borrar filtros
Borrar filtros

How to find the true positive and true negative for detected pixels in the image

10 visualizaciones (últimos 30 días)
If I create an model to detect cracks and fthe model based on image processing , I have to evaluate the model based on the precision and recall
can anyone tell me how to calculate the true positive pixel and compare it with ground truth
I attached the original image and the detected by the model so how to evaluate the performace for model to say the output is true positve or false negative , is it based on pixels account or what ,so how to do it ?

Respuestas (1)

Image Analyst
Image Analyst el 27 de Jul. de 2023
You can use dice to compare your segmented image to the ground truth segmentation image.
  2 comentarios
yasmin ismail
yasmin ismail el 30 de Jul. de 2023
Editada: yasmin ismail el 30 de Jul. de 2023
@Image Analyst If i want to use dice for following code for width measure
% Program to compute the mean width of a blob in an image.
clearvars;
close all;
clc;
fontSize = 15;
% Read in original image, with white lightning on black background.
baseFileName = 'check1.png';
fullFileName = fullfile(pwd, baseFileName);
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
% grayImage = rgb2gray(rgbImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
grayImage = grayImage(:, :, 2); % Take green channel.
else
grayImage = grayImage; % It's already gray scale.
end
% Now it's gray scale with range of 0 to 255.
subplot(2, 3, 1);
imshow(grayImage, [])
impixelinfo; % Let user mouse around and see values in the status line at the lower right.
title('Original Image', 'FontSize', fontSize);
% Binarize the image.
% mask = imbinarize(grayImage);
lowThreshold = 0;
highThreshold = 160;
% Interactively and visually set a threshold on a gray scale image.
% https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image?s_tid=srchtitle
[lowThreshold, highThreshold] = threshold(lowThreshold, highThreshold, grayImage);
mask = grayImage >= lowThreshold & grayImage <= highThreshold;
% Fill holes.
mask = imfill(mask, 'holes');
subplot(2, 3, 2);
imshow(mask)
impixelinfo; % Let user mouse around and see values in the status line at the lower right.
title('Mask', 'FontSize', fontSize)
% Take largest blob only.
% mask = bwareafilt(mask, 1);
% Compute the skeleton
skelImage = bwskel(mask);
% Find the areas of all the skeletons.
props = regionprops(skelImage, 'Area');
allAreas = sort([props.Area])
% Extract only skeletons longer than 60 pixels.
skelImage = bwareaopen(skelImage, 60);
subplot(2, 3, 3);
imshow(skelImage)
impixelinfo; % Let user mouse around and see values in the status line at the lower right.
title('Thinned', 'FontSize', fontSize)
% Enlarge figure to full screen.
g = gcf;
g.WindowState = 'maximized';
% Compute the Euclidean distance image.
edtImage = bwdist(~mask);
subplot(2, 3, 4);
imshow(edtImage, [])
title('Distance Transform Image', 'FontSize', fontSize);
impixelinfo; % Let user mouse around and see values in the status line at the lower right.
% Multiply them to get an image where the only pixels in the image
% are along the skeleton and their value is the radius.
% Multiply radius image by 2 to get diameter image.
diameterImage = 2 * edtImage .* single(skelImage);
subplot(2, 3, 5);
imshow(diameterImage, [])
title('Diameter Image', 'FontSize', fontSize);
impixelinfo; % Let user mouse around and see values in the status line at the lower right.
% Get the widths. These will be where the image is not zero.
widths = diameterImage(diameterImage > 0);
% Show histogram of widths.
subplot(2, 3, 6);
histogram(widths);
grid on;
xlabel('Width in Pixels', 'FontSize', fontSize);
ylabel('Count', 'FontSize', fontSize);
% Compute the mean width
meanWidth = mean(widths)
% Put a line on the histogram at the mean width
xline(meanWidth, 'LineWidth', 2, 'Color', 'r');
caption = sprintf('Histogram of Widths. Mean Width = %.1f Pixels', meanWidth);
title(caption, 'FontSize', fontSize);
message = sprintf('Mean Width = %.1f Pixels', meanWidth);
msgbox(message);
The dice function is :
similarity = dice(segmentation result,ground truth)
My question is :
which one from above code is ground truth and segmenation result beacuse mask is repeated many times in the above code?
Image Analyst
Image Analyst el 30 de Jul. de 2023
You did not say how you were going to get the ground truth image. All you've done is to process the image with an algorithm that you think should give you the correct answer. How can you say how accurate it is is you don't have a ground truth image? Maybe you just trust your algorithm and don't worry about how "accurate" it is because you don't have an known, "true" value. I mean who's to say whether your answer is right or wrong? If it meets your needs and you're happy with it, then maybe that's all that is needed.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by