How to Crop and get SSIM Value apply on two images
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
shubham kumar gupta
le 21 Fév 2022
Commenté : shubham kumar gupta
le 27 Fév 2022
I was struggling to get ssim value with two images of coins, as the placement position of coin is different little bit
like I have two coin images, 1st image 401x401,2nd image 441x441, on comparision
due to positions of images at different positions ssim(img1,img2) is giving incorrect output, I tried cropping but that didnot worked
Thank You
2 commentaires
DGM
le 21 Fév 2022
Modifié(e) : DGM
le 21 Fév 2022
If you were to register the two images as best you could, what value would the error metric retain? How do you propose to separate the influence of the spatial transformations from the differences in the unregistered images? Why would SSIM be a particularly relevant error metric?
I should add that the fact that the data range of the two images varies by a few orders of magnitude means that everything you do to try to put them on the same scale will become another inseparable component of the useless number you get out of ssim().
Réponse acceptée
DGM
le 21 Fév 2022
Modifié(e) : DGM
le 21 Fév 2022
If it's assumed that there is no scale or rotation transformation, then you can go ahead and try to align the images.
load coin_ssim.mat
% pad reference image since object is so close to edges
refpict = padarray(mat2gray(clean_img),[20 20],'replicate','both');
% crop test image down to extract the object alone
badpict = imcrop(mat2gray(img2),[2.5 61.5 357 363]);
% maximize normalized cross-correlation to find offset
szb = size(badpict);
c = normxcorr2(badpict,refpict);
[idxy idxx] = find(c == max(c(:)));
osy = idxy-szb(1);
osx = idxx-szb(2);
% crop the reference pict to the ROI
refpict = refpict(osy:idxy-1,osx:idxx-1);
imshow(imfuse(badpict,refpict,'checkerboard'));
ssim(badpict,refpict) % a number
7 commentaires
DGM
le 27 Fév 2022
You're not going to get significantly higher (e.g. 80%) SSIM through any amount of extra registration tweaking. As I've said already, there's little meaning to the SSIM when you cannot know the error contribution. If your goal is to measure the quality of your denoising, then you can't isolate that information from the error caused by the transformations required for registration. Neither is that number independent of the accuracy of the registration estimation itself. Overfitting the registration (e.g. trying to remove scale/rotation/skew when none was originally applied) only makes the number less meaningful.
The SSIM you get describes the end-to-end fidelity of the entire transformation -> noising -> denoising -> registration -> transformation process. If that's what you want, then I guess that the number would be appropriate.
I imagine the vast majority of the error has nothing to do with the remaining registration error. It has to do with the fact that the denoised image is so much darker and blurrier than the source. If that's the image you need to measure, then measuring it is what you get. If it needs to yet be adjusted, then maybe you can play with levels to get closer, or you can apply the filtering suggested in prior threads. I recall @yanqi liu posted a good noise masking example.
load coin_ssim.mat
load coin_ssim_reg.mat
refpict = mat2gray(clean_img);
badpict = regobj.RegisteredImage;
% adjust levels
badpict = imadjust(badpict,[0.15 0.55],[0 1],0.30);
imshow([badpict refpict])
ssim(badpict,refpict)
Plus de réponses (1)
yanqi liu
le 22 Fév 2022
yes,sir,may be make them to same size,and then compare
load coin_ssim.mat
% get location
bw1 = im2bw(mat2gray(clean_img));
bw2 = imclose(im2bw(mat2gray(img2),0.3),strel('disk',9));
bw2 = bwareafilt(bw2,1);
% make same size
[r,c] = find(bw1);
clean_img = clean_img(min(r):max(r),min(c):max(c));
[r,c] = find(bw2);
img2 = img2(min(r):max(r),min(c):max(c));
img2 = imresize(img2, size(clean_img),'bilinear');
ssim(mat2gray(clean_img),mat2gray(img2))
% compare
figure; imshowpair(clean_img,img2);
figure; montage({mat2gray(clean_img),mat2gray(img2)}, 'Size', [1 2], 'BackgroundColor', 'w', 'BorderSize', [2 2]);
6 commentaires
Voir également
Catégories
En savoir plus sur Geometric Transformation and Image Registration dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!