Is it possible perform RMSE and SSIM in different size image?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
Hi, I wanna obtain RMSE and SSIM in different size image cause the images I used cannot be equalized in size. I attached those images.
Accepted Answer
Walter Roberson
on 31 Jul 2019
0 votes
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
Diah Junaidi
on 31 Jul 2019
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]) ;
Walter Roberson
on 31 Jul 2019
[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]);
Diah Junaidi
on 31 Jul 2019
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)
Walter Roberson
on 31 Jul 2019
Please show us [ny1, nx1, np1]
Diah Junaidi
on 31 Jul 2019
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)
Diah Junaidi
on 31 Jul 2019

Walter Roberson
on 31 Jul 2019
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.
Diah Junaidi
on 31 Jul 2019
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)
Walter Roberson
on 31 Jul 2019
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.
Diah Junaidi
on 1 Aug 2019
is there any technique to trim the image? I mean is imcrop fits for this problem?
Walter Roberson
on 1 Aug 2019
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,:);
Diah Junaidi
on 1 Aug 2019
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)
More Answers (0)
Categories
Find more on Image Quality in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)