X = imread('africasculpt.jpg'); Xapp = X; Xapp(X<=100) = 1; [psnr,mse,maxerr,L2rat] = measerr (X,Xapp) figure; subplot(1,2,1); image(X); subplot(1,2,2); image(Xapp);
There are psnr() and ssim() functions for image quality in the Image Processing Toolbox. If you don't have a recent version, I have some code you can use in older versions in the file.
% Demo to calculate MSE and PSNR of a gray scale image. % http://en.wikipedia.org/wiki/PSNR % Clean up. clc; % Clear the command window. close all; % Close all figures (except those of imtool.) clear; % Erase all existing variables. Or clearvars if you want. workspace; % Make sure the workspace panel is showing. format long g; format compact; fontSize = 20; %------ GET DEMO IMAGES ---------------------------------------------------------- % Read in a standard MATLAB gray scale demo image. grayImage = imread('cameraman.tif'); [rows columns] = size(grayImage); % Display the first image. subplot(2, 2, 1); imshow(grayImage, []); title('Original Gray Scale Image', 'FontSize', fontSize); set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. % Get a second image by adding noise to the first image. noisyImage = imnoise(grayImage, 'gaussian', 0, 0.003); % Display the second image. subplot(2, 2, 2); imshow(noisyImage, []); title('Noisy Image', 'FontSize', fontSize); %------ PSNR CALCULATION ---------------------------------------------------------- % Now we have our two images and we can calculate the PSNR. % First, calculate the "square error" image. % Make sure they're cast to floating point so that we can get negative differences. % Otherwise two uint8's that should subtract to give a negative number % would get clipped to zero and not be negative. squaredErrorImage = (double(grayImage) - double(noisyImage)) .^ 2; % Display the squared error image. subplot(2, 2, 3); imshow(squaredErrorImage, []); title('Squared Error Image', 'FontSize', fontSize); % Sum the Squared Image and divide by the number of elements % to get the Mean Squared Error. It will be a scalar (a single number). mse = sum(sum(squaredErrorImage)) / (rows * columns); % Calculate PSNR (Peak Signal to Noise Ratio) from the MSE according to the formula. PSNR = 10 * log10( 256^2 / mse); % Alert user of the answer. message = sprintf('The mean square error is %.2f.\nThe PSNR = %.2f', mse, PSNR); msgbox(message);
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.