Is it possible perform RMSE and SSIM in different size image?

 Accepted Answer

No, those measurements cannot be computed for images that are different sizes.
You would want to trim out the irrelevant borders and then imresize to have them match sizes. It might make sense to resize to a consistent size rather than to the larger or smaller size.

12 Comments

I used this code sir, but it wouldn't change anyhting. What should I do for easily fitting their different size? Is manually trim the only one the solution?
[nx1,ny1] = size(A) ;
[nx2,ny2] = size(B) ;
nx = max(nx1,nx2) ; ny = max(ny1,ny2) ;
A = imresize(A,[nx,ny]) ;
B = imresize(B,[nx,ny]) ;
[ny1, nx1, np1] = size(A) ;
[ny2, nx2, np2] = size(B) ;
nx = max(nx1,nx2) ; ny = max(ny1,ny2) ;
A = imresize(A, [ny nx]);
B = imresize(B, [ny nx]);
I have an error for this code sir:
MAP must be a m x 3 array.
Error in rgb2gray (line 52)
[X, threeD] = parse_inputs(X);
Error in cobaRMSE (line 9)
grayImageA = rgb2gray(A);
close
A=imread('D:\DIAH\[MATLAB]cv1-fingerspelling-recognition-master\cv1-fingerspelling-recognition-master\Hasil Percobaan Standard\Hasil Citra Ground Truth_1_1.jpg');
B=imread('D:\DIAH\[MATLAB]cv1-fingerspelling-recognition-master\cv1-fingerspelling-recognition-master\Hasil Percobaan HSV\1\Hasil Citra HSV_1a.jpg');
[ny1, nx1, np1] = size(A) ;
[ny2, nx2, np2] = size(B) ;
nx = max(nx1,nx2) ; ny = max(ny1,ny2) ;
A = imresize(A, [ny nx]);
B = imresize(B, [ny nx]);
grayImageA = rgb2gray(A);
grayImageB = rgb2gray(B);
bwA = imbinarize(grayImageA);
bwB = imbinarize(grayImageB);
rmse = sqrt(immse(bwB, bwA));
% [ssimval, ssimmap] = ssim(resize2,resize1);
% fprintf('The SSIM value is %0.4f.\n',ssimval);
fprintf('The RMSE value is %0.4f.\n',rmse);
figure,
imshowpair(A,B)
I got these error:
Error using immse
Expected input number 1, A, to be one of these types:
uint8, int8, uint16, int16, uint32, int32, single, double
Instead its type was logical.
Error in immse (line 28)
validateattributes(x,{'uint8', 'int8', 'uint16', 'int16', 'uint32', 'int32', ...
Error in cobaRMSE (line 11)
rmse = sqrt(immse(bwB, double(A)));
for this code:
close
A=imread('D:\DIAH\[MATLAB]cv1-fingerspelling-recognition-master\cv1-fingerspelling-recognition-master\Hasil Percobaan Standard\Hasil Citra Ground Truth_1_1.jpg');
B=imread('D:\DIAH\[MATLAB]cv1-fingerspelling-recognition-master\cv1-fingerspelling-recognition-master\Hasil Percobaan HSV\1\Hasil Citra HSV_1a.jpg');
[ny1, nx1, np1] = size(A) ;
[ny2, nx2, np2] = size(B) ;
nx = max(nx1,nx2) ; ny = max(ny1,ny2) ;
A = imresize(A, [ny nx]);
B = imresize(B, [ny nx]);
grayImageB = rgb2gray(B);
bwB = imbinarize(grayImageB);
rmse = sqrt(immse(bwB, double(A)));
% [ssimval, ssimmap] = ssim(resize2,resize1);
% fprintf('The SSIM value is %0.4f.\n',ssimval);
fprintf('The RMSE value is %0.4f.\n',rmse);
figure,
imshowpair(A,B)
rmse = sqrt(immse(double(bwB), double(A)));
However you will get terrible results. The output of imbinarize is going to be all 0 and 1 values, black and white, and those are rarely going to match the gray 0 to 255 values in B.
you are right sir, I got 167 of rmse's result. Hmm, anyway, did you know what is the best method of quality metric for those image sir? I mean that those images are have similarity in foreground area. I wanna prove that they were same so what should I do? From attached files:
asl21_a.jpg is Reference Image
set1_a.jpg is Target Image (New Image)
It makes no sense to compare a binary image to a grayscale image.
You could leave both as grayscale, or your could convert both to binary.
But you really need to crop out the backgrounds before going much further.
is there any technique to trim the image? I mean is imcrop fits for this problem?
pix_used = any(YourImage,3);
col_used = any(pix_used,1);
row_used = any(pix_used,2);
first_col = find(col_used,1);
last_col = find(col_used,1,'last');
first_row = find(row_used,1);
last_row = find(row_used,1,'last');
cropped_image = YourImage(first_row:last_row, first_col:last_col,:);
Got this problem:
Index exceeds matrix dimensions.
Error in cobaRMSE (line 26)
cropped_imageB = A(first_rowB:last_rowB, first_colB:last_colB,:);
close
A=imread('D:\DIAH\[MATLAB]cv1-fingerspelling-recognition-master\cv1-fingerspelling-recognition-master\Hasil Percobaan Standard\1.jpg');
B=imread('D:\DIAH\[MATLAB]cv1-fingerspelling-recognition-master\cv1-fingerspelling-recognition-master\Hasil Percobaan HSV\1\Hasil Citra HSV_1a.jpg');
pix_used = any(A,3);
col_used = any(pix_used,1);
row_used = any(pix_used,2);
first_col = find(col_used,1);
last_col = find(col_used,1,'last');
first_row = find(row_used,1);
last_row = find(row_used,1,'last');
cropped_image = A(first_row:last_row, first_col:last_col,:);
pix_usedB = any(B,3);
col_usedB = any(pix_usedB,1);
row_usedB = any(pix_usedB,2);
first_colB = find(col_usedB,1);
last_colB = find(col_usedB,1,'last');
first_rowB = find(row_usedB,1);
last_rowB = find(row_usedB,1,'last');
cropped_imageB = B(first_rowB:last_rowB, first_colB:last_colB,:);
figure,
imshowpair(cropped_image,cropped_imageB)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!