Why I do I get different results when I used jaccard Index with png format than with jpg format?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
yasmin ismail
am 8 Okt. 2023
Kommentiert: yasmin ismail
am 10 Okt. 2023
When I applied the following:
A = logical(imread('R7001-21.png'));
BW_groundTruth =logical(imread('gT7001_21.png'));
similarity = jaccard(A, BW_groundTruth)
I got:
>> GT_jac_index
similarity =
0.9952
While when I applied
A = logical(imread('R7001-21.jpg'));
BW_groundTruth =logical(imread('gT7001_21.jpg'));
similarity = jaccard(A, BW_groundTruth)
I got:
>> GT_jac_index
similarity =
0.8843
Why? And is it better to use png format images?
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 8 Okt. 2023
Both sets of code use the PNG versions.
In general you should not use JPG files for image analysis, unless you're specifically doing research on compression and how lousy JPG is compared to other methods.
It is better to use PNG because it is a loasless compression and does not change values or introduce artifacts (such as contouring/posterization, edge blurring, etc.) like JPG does.
7 Kommentare
Image Analyst
am 10 Okt. 2023
The images are different. Not all the pixels are the same so the jaccard index will not be 1.
fileName1 = 'R7001-21.png';
fileName2 = 'gT7001_21.png';
fileName3 = 'R7001-21.jpg';
fileName4 = 'gT7001_21.jpg';
% Read in all files:
image1 = imread(fileName1);
image2 = imread(fileName2);
image3 = imread(fileName3);
image4 = imread(fileName4);
% Take green channel of all of them.
image1 = image1(:, :, 2);
image2 = image2(:, :, 2);
image3 = image3(:, :, 2);
image4 = image4(:, :, 2);
% See how many pixels are different between the two.
diffImage = imabsdiff(image1, image2);
fprintf('Image 1 differs from image2 by %d pixels.\n', nnz(diffImage));
diffImage = imabsdiff(image1, image3);
fprintf('Image 1 differs from image3 by %d pixels.\n', nnz(diffImage));
diffImage = imabsdiff(image1, image4);
fprintf('Image 1 differs from image4 by %d pixels.\n', nnz(diffImage));
diffImage = imabsdiff(image2, image3);
fprintf('Image2 differs from image3 by %d pixels.\n', nnz(diffImage));
diffImage = imabsdiff(image2, image4);
fprintf('Image2 differs from image4 by %d pixels.\n', nnz(diffImage));
diffImage = imabsdiff(image3, image4);
fprintf('Image3 differs from image4 by %d pixels.\n', nnz(diffImage));
% Compare filenames 1 and 2
testImage = logical(image1);
BW_groundTruth = logical(image2);
similarity = jaccard(testImage, BW_groundTruth)
% Compare filenames 3 and 4
testImage = logical(image3);
BW_groundTruth = logical(image4);
similarity = jaccard(testImage, BW_groundTruth)
% Compare filenames 1 and 3
testImage = logical(image1);
BW_groundTruth = logical(image3);
similarity = jaccard(testImage, BW_groundTruth)
% Compare filenames 2 and 4
testImage = logical(image2);
BW_groundTruth = logical(image4);
similarity = jaccard(testImage, BW_groundTruth)
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!