You are on page 1of 2

function bicubic

clc
clear all
close all
I=imread('lena.tif');
figure,imshow(I)
I=rgb2gray(I);
%r and c are no. of. rows and collom
[r c]=size(I)
%this step is shrinking image in its half of size
for i=1:r/2
for j=1:c/2
s(i,j) = I(2*i,2*j);
end
end
imshow(s);title('after changing into half');
% %this step is inserting rows and collom in s for making it in original size
I1=uint8(zeros(r,c));
for i=1:r/2
for j=1:c/2
I1(2*i-1,2*j-1)=s(i,j);
end
end
[m n]=size(I1)
figure,imshow(I1),title('first pass');
for i=1:2:r-1
for j=1:2:c-3
a=[-0.0625 0.5625 0.5625 -0.0625];
if(j==1)
b(1)=3*I1(i,j)-3*I1(i,j+2)+I1(i,j+4);
else
b(1)=I1(i,j-2);
end
if(j==c-3)
b(4)=3*I1(i,j)-3*I1(i,j-2)+I1(i,j-4);
else
b(4)=I1(i,j+4);
end
b(2)=I1(i,j);
b(3)=I1(i,j+2);
b1=im2double(b);
d=a*b1';
d1=im2uint8(d);
I1(i,j+1)=d1;
end
end
figure,imshow(I1),title('after filling odd rows');
for j=1:c-1
for i=1:2:r-3
a=[-0.0625 0.5625 0.5625 -0.0625];
if(i==1)
b(1)=3*I1(i,j)-3*I1(i+2,j)+I1(i+4,j);
else
b(1)=I1(i-2,j);
end
if(i==r-3)

b(4)=3*I1(i,j)-3*I1(i-2,j)+I1(i-4,j);
else
b(4)=I1(i+4,j);
end
b(2)=I1(i,j);
b(3)=I1(i+2,j);
b1=im2double(b);
d=a*b1';
d1=im2uint8(d);
I1(i+1,j)=d1;
end
end
I1(r,:)=I1(r-1,:);
I1(:,c)=I1(:,c-1);
figure,imshow(I1),title('final');
% I = imread('original.jpg');
% Ihat = imread('changed.jpg');
% Read the dimensions of the image.
% [rows columns ~] = size(I);
%
%
%
%
%
%
%
%
%
%
%
%
%
%

Calculate
mseRImage
mseGImage
mseBImage

mean square error of R, G,


= (double(imgexp(:,:,1)) = (double(imgexp(:,:,2)) = (double(imgexp(:,:,3)) -

B.
double(img(:,:,1))) .^ 2;
double(img(:,:,2))) .^ 2;
double(img(:,:,3))) .^ 2;

mseR = sum(sum(mseRImage)) / (r * c);


mseG = sum(sum(mseGImage)) / (r * c);
mseB = sum(sum(mseBImage)) / (r * c);
% Average mean square error of R, G, B.
mse = (mseR + mseG + mseB)/3;

% Calculate PSNR (Peak Signal to noise ratio).


PSNR_Value = 10 * log10( 255^2 / mse);
I3=255*255;
e=imsubtract(I1,I);
se=(sum(e(:).^2));
mse=se/(r*c);
psnr=10*log10(I3/mse)

You might also like