필터 지우기
필터 지우기

Comapre between two images?

조회 수: 1 (최근 30일)
Hadeel H
Hadeel H 2021년 6월 2일
편집: DGM 2024년 2월 15일
I resized my image using
I= imread('my_image.jpg');
J = imresize(I, 2, 'bicubic')
But I want to know how to compare between my original image(I) and the resized image( J), and then display the errors and fix if there is any corrupted pixel?
  댓글 수: 2
Adam Danz
Adam Danz 2021년 6월 2일
편집: Adam Danz 2021년 6월 2일
What do you mean by compare? Their image sizes will differ; they will have a different number of pixels, and depending on the resolution, they will likely have a visually noticeable difference in quality. As noted in the documention, with bicubic interpolation, the output pixel value is a weighted average of pixels in the nearest 4-by-4 neighborhood and can produce pixel values outside the original range.
What would you define as an error or a corrupted pixel? Remember that you will not have a 1:1 correspondence of pixels between the original and resized image.
Seeing the original image and the resized image may help with conveying the goal.
Hadeel H
Hadeel H 2021년 6월 3일
I know there will be differences in number of pixels between the two images (the original and the resized one), but how can I show theses differences in matlab like how to show the number of pixels of each and how to show if there is any error or any corrupted pixel between the original and the resized image?

댓글을 달려면 로그인하십시오.

답변 (1개)

Tejas
Tejas 2024년 2월 15일
Hello Hadeel,
The number of pixels for an image can be found using “size” function of MALTAB. To compare both the images, which are of different dimensions, there is no straight-forward approach for pixel-wise comparison. I would like to suggest a work-around, for comparing two images, one image can be converted to dimensions of the other. Now pixels-wise comparison can be done based on some desired threshold.
I am assuming that by "corrupted pixels," you are referring to whether the pixel values deviate from their expected values after they are resized. In other words, you are inquiring whether the resize function results in any unexpected pixel values. The following solution is based on this assumption.
Below is the solution code snippet and screenshot of desired result.
I = imread('Sample_Image.jpg');
J = imresize(I, 2, 'bicubic');
disp(['Total number of pixels in image I: ', num2str(NumOfPixels(I)) ]);
disp(['Total number of pixels in image J: ', num2str(NumOfPixels(J)) ]);
% Resizing J for comparison
K = imresize(J, 0.5, 'bicubic');
disp(['Total number of pixels in image K: ', num2str(NumOfPixels(K)) ]);
% Give both images and desired threshold as input arguments
threshold = 5;
disp(['Difference in pixels : ', num2str(Compare(I, K, threshold)) ]);
function Total_Pixels = NumOfPixels(img)
[n_rows, n_cols, n_channels] = size(img);
Total_Pixels = n_rows * n_cols * n_channels;
end
function Num_Corrupt_Px = Compare(I, K, threshold)
diff_in_pixels = abs(double(I) - double(K));
Num_Corrupt_Px = diff_in_pixels > threshold;
Num_Corrupt_Px = sum(Num_Corrupt_Px(:));
end
Hope it helps!
  댓글 수: 1
DGM
DGM 2024년 2월 15일
편집: DGM 2024년 2월 15일
Testing a round-trip transformation still doesn't really tell us anything meaningful about the forward operation alone. The result is strongly determined by the second transformation.
inpict = imread('cameraman.tif');
inpict = im2double(inpict); % don't want integer rounding obfuscating things
% downsample with bicubic with antialiasing
k = 5;
outpict = imresize(inpict,k,'bicubic');
outpict = imresize(outpict,1/k,'bicubic');
nnz(inpict ~= outpict)
ans = 65536
% downsample with bicubic without antialiasing
k = 5;
outpict = imresize(inpict,k,'bicubic');
outpict = imresize(outpict,1/k,'bicubic','antialiasing',false);
nnz(inpict ~= outpict)
ans = 0
% downsample with nearest-neighbor with antialiasing
k = 5;
outpict = imresize(inpict,k,'bicubic');
outpict = imresize(outpict,1/k,'nearest');
nnz(inpict ~= outpict)
ans = 0
% just do it without imresize()
k = 5;
os = ceil(k/2);
outpict = imresize(inpict,k,'bicubic');
outpict = outpict(os:k:end,os:k:end);
nnz(inpict ~= outpict)
ans = 0
Now try it with k = 4 and see what happens. Is the image quality actually 60 thousand times worse? No. Our sampling is just off by half a pixel. In other words, the magnitude of observed error is determined largely by our method of observation, not the actual thing we're measuring.
Note that's a count of all pixels which differ. It's not a class-sensitive approach which presumes a uint8 input.
FWIW, I don't really know what OP was after, so I have no idea what would be a better answer.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by