Why I do I get different results when I used jaccard Index with png format than with jpg format?

1 次查看(过去 30 天)
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?

采纳的回答

Image Analyst
Image Analyst 2023-10-8
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 个评论
Image Analyst
Image Analyst 2023-10-10
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));
Image 1 differs from image2 by 133 pixels.
diffImage = imabsdiff(image1, image3);
fprintf('Image 1 differs from image3 by %d pixels.\n', nnz(diffImage));
Image 1 differs from image3 by 133 pixels.
diffImage = imabsdiff(image1, image4);
fprintf('Image 1 differs from image4 by %d pixels.\n', nnz(diffImage));
Image 1 differs from image4 by 3238 pixels.
diffImage = imabsdiff(image2, image3);
fprintf('Image2 differs from image3 by %d pixels.\n', nnz(diffImage));
Image2 differs from image3 by 0 pixels.
diffImage = imabsdiff(image2, image4);
fprintf('Image2 differs from image4 by %d pixels.\n', nnz(diffImage));
Image2 differs from image4 by 3263 pixels.
diffImage = imabsdiff(image3, image4);
fprintf('Image3 differs from image4 by %d pixels.\n', nnz(diffImage));
Image3 differs from image4 by 3263 pixels.
% Compare filenames 1 and 2
testImage = logical(image1);
BW_groundTruth = logical(image2);
similarity = jaccard(testImage, BW_groundTruth)
similarity = 0.9952
% Compare filenames 3 and 4
testImage = logical(image3);
BW_groundTruth = logical(image4);
similarity = jaccard(testImage, BW_groundTruth)
similarity = 0.8843
% Compare filenames 1 and 3
testImage = logical(image1);
BW_groundTruth = logical(image3);
similarity = jaccard(testImage, BW_groundTruth)
similarity = 0.9952
% Compare filenames 2 and 4
testImage = logical(image2);
BW_groundTruth = logical(image4);
similarity = jaccard(testImage, BW_groundTruth)
similarity = 0.8843

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by