필터 지우기
필터 지우기

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