0

I am using the following code to read an image and comparing the image with 13 images inside a folder and finding errors and exporting it to Excel.

clear all;
clc;
workspace;              % Make sure the workspace panel is showing.

ReferenceImage = imread('F:\R\CS\0.8\0.6\6.jpg'); 
[rows columns] = size(ReferenceImage);

fpath = fullfile('F:\R\CT\0.0\0.2\','*.jpg');
img_dir = dir(fpath);
for k=1:length(img_dir)
input_image=strcat('F:\R\CT\0.0\0.2\',img_dir(k).name);
noisyImage = imread(input_image);

squaredErrorImage = (double(ReferenceImage) - double(noisyImage)) .^ 2;

mse = sum(sum(squaredErrorImage)) / (rows * columns);
xlswrite('F:\R\DataX.xls',mse,'A1:A13');
PSNR = 10 * log10( 256^2 / mse);
xlswrite('F:\R\DataX.xls',PSNR,'B1:B15');

end

I am expecting the Excel sheet to have One Column for MSE and One Column for PSNR where the calculated errors of each are displayed.

For example Lets Say,

Image Ref and Image 1, MSE =2; PSNR = 3
Image Ref and Image 2, MSE =3; PSNR = 3
Image Ref and Image 3, MSE =2; PSNR = 4
Image Ref and Image 4, MSE =5; PSNR = 8

I want the excel sheet to look like

2 3
3 3
2 4
5 8

But Instead the sheet I am creating is repeating the numbers. Please help.

Image Check
  • 91
  • 2
  • 14
  • 2
    Without the images your error cant be reproduced, but let me take a guess: only the first number is repeated? try `xlswrite('F:\R\DataX.xls',mse','A1:A13');` (that little `'` behind `mse` so you dont have an 1x13 but an 13x1 vector – Finn Jan 18 '18 at 09:35
  • @Finn Ha ... was about to answer from random vectors (i.e. without loading images), but yes this is it. – CitizenInsane Jan 18 '18 at 09:37
  • Actually it looks like `mse` and `PSNR` would be sized 1x1x3 here (assuming these jpg files have 3 channels, i.e. RGB images). That's what `sum(sum(I))` would do to an image sized HxWx3. The loop should store the MSE etc. for each image in a vector and `xlswrite` should be called after the loop. – buzjwa Jan 18 '18 at 12:49
  • Thanks. If I generate them one image after the other I get values like, 69.7939 2.14E+03 2.54E+03 2.56E+03 2.53E+03 2.52E+03 2.49E+03 2.48E+03 2.52E+03 But If I use the above code with xlswrite('F:\R\DataX.xls',mse','A1:A13'); I get a repeating number of 2492.08613481424 – Image Check Jan 18 '18 at 14:08

0 Answers0