This coding will calculate the performance metrics or image quality measures between two images. This code will be very helpful in fields like Digital Image processing, Image Steganography. Copy the codes in matlab and execute main.m.
CONTENTS
Main.m
MaximumDifference.m
MeanSquareError.m
NormalizedAbsoluteError.m
NormalizedCrossCorrelation.m
PeakSignaltoNoiseRatio.m
StructuralContent.m
AverageDifference.m
%Program for Image / Picture Quality Measures Calculation
%Program Description
%This program is the main entry of the application.
%This program calculates the difference Image/Picture Quality Measures
%Clear Memory & Command Window
clc;
clear all;
close all;
%Read Original & Distorted Images
origImg = imread('dc_shift_10.bmp');
distImg = imread('gaussian_noise_50.bmp');
%If the input image is rgb, convert it to gray image
noOfDim = ndims(origImg);
if(noOfDim == 3)
origImg = rgb2gray(origImg);
end
noOfDim = ndims(distImg);
if(noOfDim == 3)
distImg = rgb2gray(distImg);
end
%Size Validation
origSiz = size(origImg);
distSiz = size(distImg);
sizErr = isequal(origSiz, distSiz);
if(sizErr == 0)
disp('Error: Original Image & Distorted Image should be of same dimensions');
return;
end
%Mean Square Error
MSE = MeanSquareError(origImg, distImg);
disp('Mean Square Error = ');
disp(MSE);
%Peak Signal to Noise Ratio
PSNR = PeakSignaltoNoiseRatio(origImg, distImg);
disp('Peak Signal to Noise Ratio = ');
disp(PSNR);
%Normalized Cross-Correlation
NK = NormalizedCrossCorrelation(origImg, distImg);
disp('MNormalized Cross-Correlation = ');
disp(NK);
%Average Difference
AD = AverageDifference(origImg, distImg);
disp('Average Difference = ');
disp(AD);
%Structural Content
SC = StructuralContent(origImg, distImg);
disp('Structural Content = ');
disp(SC);
%Maximum Difference
MD = MaximumDifference(origImg, distImg);
disp('Maximum Difference = ');
disp(MD);
%Normalized Absolute Error
NAE = NormalizedAbsoluteError(origImg, distImg);
disp('Normalized Absolute Error = ');
disp(NAE);
%Program for Peak Signal to Noise Ratio Calculation
function PSNR = PeakSignaltoNoiseRatio(origImg, distImg)
origImg = double(origImg);
distImg = double(distImg);
[M N] = size(origImg);
error = origImg - distImg;
MSE = sum(sum(error .* error)) / (M * N);
if(MSE > 0)
PSNR = 10*log(255*255/MSE) / log(10);
else
PSNR = 99;
end
%Program for Average Difference Calculation
function AD = AverageDifference(origImg, distImg)
origImg = double(origImg);
distImg = double(distImg);
[M N] = size(origImg);
error = origImg - distImg;
AD = sum(sum(error)) / (M * N);
%Program for Maximum Difference Calculation
function MD = MaximumDifference(origImg, distImg)
origImg = double(origImg);
distImg = double(distImg);
error = origImg - distImg;
MD = max(max(error));
%Program for Mean Square Error Calculation
function MSE = MeanSquareError(origImg, distImg)
origImg = double(origImg);
distImg = double(distImg);
[M N] = size(origImg);
error = origImg - distImg;
MSE = sum(sum(error .* error)) / (M * N);
%Program for Normalized Absolute Error Calculation
function NAE = NormalizedAbsoluteError(origImg, distImg)
origImg = double(origImg);
distImg = double(distImg);
error = origImg - distImg;
NAE = sum(sum(abs(error))) / sum(sum(origImg));
%Program for Normalized Cross Correlation Calculation
function NK = NormalizedCrossCorrelation(origImg, distImg)
origImg = double(origImg);
distImg = double(distImg);
NK = sum(sum(origImg .* distImg)) / sum(sum(origImg .* origImg));
%Program for Structural Content Calculation
function SC = StructuralContent(origImg, distImg)
origImg = double(origImg);
distImg = double(distImg);
SC = sum(sum(origImg .* origImg)) / sum(sum(distImg .* distImg));
1 comment:
That was a great code, will you please provide me with other codes such as Human Visual System Based measures, Context Measures, Spectral Distance Measures, Edge Quality Measures and Neural Network Measures. Thank you.
This is my e-mail:
usra7@yahoo.com
Post a Comment