SlideShare a Scribd company logo
t=cputime;
o = imread('aerialview.jpg');
w = size (o, 2);        %identify no of columns in image

samplesEighth = floor(w / 8);     % divide column by 8 and round off

ci8 = [];
[x,y,z]=size(o);        % identify the dimensions of image
if z==1                 % checking z coordinates; if z=1, image is gray
% scale; if z=3,image is rgb
    k=1;
    for i=1:size(o,1)   % all rows

rowDCT = dct(double(o(i,:,k)));

ci8(i,:,k) = idct(rowDCT(1:samplesEighth), w);

    end
elseif z==3
for k=1:3               % all color layers: RGB
    for i=1:size(o,1)   % all rows

rowDCT = dct(double(o(i,:,k)));    %picking every row and applying dct on
% every element of the row,after converting it into double for better
% precision
% dct(k)==dct(k,1)--> gives element of 1st row after DCT
% dct(k,2)--> gives element of 2nd row after DCT & so on thus K correspond to
% input matrix and 1 or 2 tells the respective rows on which DCT is to be
applied
% DCT(K(1,3))--> element at 1st row 3rd column of matric K DCT(K(2,5))--
>element at 2nd row 5th column of matric K
ci8(i,:,k) = idct(rowDCT(1:samplesEighth), w);
% row elements from   1:samplesEighth are taken into consideration, rest
% other elements are ignored and using those elements(1:samplesEighth), all
% the possible values of desired row is predicted and placed, thus the no of
% row elements remains same but it is being influenced by lower elements of
% row.
%%%% Each row is Transformed using the DCT, then high-order samples are
%%%% discarded, and the low-order samples are reverse-transformed using IDCT.

end
end
h = size(o, 1);                         % identify no of rows in image

samplesEighth = floor(h / 8);

ci8f = [];
[x,y,z]=size(o);
if z==1      % check for z coordinate of image i.e rgb component, if image is
% colored, z==3 else z==1 if image is gray
    k=1;
    for i=1:size(o, 2)                          % all columns

columnDCT8=dct(double(ci8(:,i,k)));
ci8f(:,i,k) = idct(columnDCT8(1:samplesEighth), h);

    end
elseif z==3

for k=1:3% all color layers: RGB

for i=1:size(o, 2)% all columns

columnDCT8=dct(double(ci8(:,i,k)));

ci8f(:,i,k) = idct(columnDCT8(1:samplesEighth), h);

end

end
end
k=uint8(ci8f);
figure, imshow(o), title('Original Image');
figure,imshow(k),title('Compression factor 8*8');

out1=uint8(k);


 %calculate the peak signal to noise ratio.

input_ima1=double(o);

       out2=double(out1);

       error=0;

  for y=1:191

       for x=1:159

             MSE=((input_ima1(x,y))-(out2(x,y)))^2;

             error=MSE+error;

         %    error_sbw1=error_sbw+MSE2;

       end

 end

 MSE_WO=(1/(159*191))*error




 disp('PSNR value for decompression image using DCT compression ');
PSNR_WO=20*log10(255/sqrt(MSE_WO))

%Display the PSNR value.

 disp(PSNR_WO);
 disp('value for BER ');
 BER= 1/PSNR_WO
 disp('the time need to execute this program only');
 cputime-t

More Related Content

What's hot

2.5
2.52.5
Lsn 10-9
Lsn 10-9Lsn 10-9
Lsn 10-9
Kate Nowak
 
Oops Paper
Oops PaperOops Paper
Oops Paper
prabhatjon
 
Ma economics entrance syllabus
Ma economics entrance syllabusMa economics entrance syllabus
Ma economics entrance syllabus
MAeconomicsentrance
 
Digital Differential Analyzer Line Drawing Algorithm in C
Digital Differential Analyzer Line Drawing Algorithm in CDigital Differential Analyzer Line Drawing Algorithm in C
Digital Differential Analyzer Line Drawing Algorithm in C
Kasun Ranga Wijeweera
 
12 - Scala. Empty and unit types
12 - Scala. Empty and unit types12 - Scala. Empty and unit types
12 - Scala. Empty and unit types
Roman Brovko
 
2) quadratics gral form
2) quadratics gral form2) quadratics gral form
2) quadratics gral form
estelav
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
Priya Goyal
 
Pre-Cal 30S January 19, 2009
Pre-Cal 30S January 19, 2009Pre-Cal 30S January 19, 2009
Pre-Cal 30S January 19, 2009
Darren Kuropatwa
 
Trytten computergraphics(1)
Trytten computergraphics(1)Trytten computergraphics(1)
Trytten computergraphics(1)
nriaz469
 
AP Calculus Slides December 13, 2007
AP Calculus Slides December 13, 2007AP Calculus Slides December 13, 2007
AP Calculus Slides December 13, 2007
Darren Kuropatwa
 
Py9 3
Py9 3Py9 3
Test
TestTest
Test
Kinni MEW
 
Thesis PPT
Thesis PPTThesis PPT
Thesis PPT
Drew Ferkin
 
Towards Well Planned Code Cities
Towards Well Planned Code CitiesTowards Well Planned Code Cities
Towards Well Planned Code Cities
ESUG
 
Tutorials--Rational Expressions
Tutorials--Rational ExpressionsTutorials--Rational Expressions
Tutorials--Rational Expressions
Media4math
 
Nrtl activity coefficient for mixture1
Nrtl activity coefficient for mixture1Nrtl activity coefficient for mixture1
Nrtl activity coefficient for mixture1
ESSID Abou Hligha
 

What's hot (17)

2.5
2.52.5
2.5
 
Lsn 10-9
Lsn 10-9Lsn 10-9
Lsn 10-9
 
Oops Paper
Oops PaperOops Paper
Oops Paper
 
Ma economics entrance syllabus
Ma economics entrance syllabusMa economics entrance syllabus
Ma economics entrance syllabus
 
Digital Differential Analyzer Line Drawing Algorithm in C
Digital Differential Analyzer Line Drawing Algorithm in CDigital Differential Analyzer Line Drawing Algorithm in C
Digital Differential Analyzer Line Drawing Algorithm in C
 
12 - Scala. Empty and unit types
12 - Scala. Empty and unit types12 - Scala. Empty and unit types
12 - Scala. Empty and unit types
 
2) quadratics gral form
2) quadratics gral form2) quadratics gral form
2) quadratics gral form
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
Pre-Cal 30S January 19, 2009
Pre-Cal 30S January 19, 2009Pre-Cal 30S January 19, 2009
Pre-Cal 30S January 19, 2009
 
Trytten computergraphics(1)
Trytten computergraphics(1)Trytten computergraphics(1)
Trytten computergraphics(1)
 
AP Calculus Slides December 13, 2007
AP Calculus Slides December 13, 2007AP Calculus Slides December 13, 2007
AP Calculus Slides December 13, 2007
 
Py9 3
Py9 3Py9 3
Py9 3
 
Test
TestTest
Test
 
Thesis PPT
Thesis PPTThesis PPT
Thesis PPT
 
Towards Well Planned Code Cities
Towards Well Planned Code CitiesTowards Well Planned Code Cities
Towards Well Planned Code Cities
 
Tutorials--Rational Expressions
Tutorials--Rational ExpressionsTutorials--Rational Expressions
Tutorials--Rational Expressions
 
Nrtl activity coefficient for mixture1
Nrtl activity coefficient for mixture1Nrtl activity coefficient for mixture1
Nrtl activity coefficient for mixture1
 

Similar to Dct compressionfactor8.doc

ECE 565 Project1
ECE 565 Project1ECE 565 Project1
ECE 565 Project1
?? ?
 
Plotting position and velocity
Plotting position and velocityPlotting position and velocity
Plotting position and velocity
abidraza88
 
matlab.docx
matlab.docxmatlab.docx
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)
Austin Benson
 
Section6 stochastic
Section6 stochasticSection6 stochastic
Section6 stochastic
cairo university
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
Abi finni
 
Solution Manual Image Processing for Engineers by Yagle and Ulaby
Solution Manual Image Processing for Engineers by Yagle and UlabySolution Manual Image Processing for Engineers by Yagle and Ulaby
Solution Manual Image Processing for Engineers by Yagle and Ulaby
spaceradar35
 
Control assignment#2
Control assignment#2Control assignment#2
Control assignment#2
cairo university
 
DCT
DCTDCT
DCT
DCTDCT
DCT
DCTDCT
E251014
E251014E251014
E251014
jcbp_peru
 
Revision1schema C programming
Revision1schema C programmingRevision1schema C programming
Revision1schema C programming
Kho コー。イエー。イエン
 
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
meerobertsonheyde608
 
SlidesPartII_digital_control_power_electronics.pdf
SlidesPartII_digital_control_power_electronics.pdfSlidesPartII_digital_control_power_electronics.pdf
SlidesPartII_digital_control_power_electronics.pdf
ssuserb5b5f7
 
Project2
Project2Project2
Project2
?? ?
 
Demodulation bpsk up
Demodulation bpsk upDemodulation bpsk up
Demodulation bpsk up
Huma Chaudhry
 
Demodulate bpsk up
Demodulate bpsk upDemodulate bpsk up
Demodulate bpsk up
Huma Chaudhry
 
R scatter plots
R scatter plotsR scatter plots
R scatter plots
Abhik Seal
 
Analysis of an E-plane waveguide T-junction with a quarter-wave transformer u...
Analysis of an E-plane waveguide T-junction with a quarter-wave transformer u...Analysis of an E-plane waveguide T-junction with a quarter-wave transformer u...
Analysis of an E-plane waveguide T-junction with a quarter-wave transformer u...
Yong Heui Cho
 

Similar to Dct compressionfactor8.doc (20)

ECE 565 Project1
ECE 565 Project1ECE 565 Project1
ECE 565 Project1
 
Plotting position and velocity
Plotting position and velocityPlotting position and velocity
Plotting position and velocity
 
matlab.docx
matlab.docxmatlab.docx
matlab.docx
 
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)
Tall-and-skinny Matrix Computations in MapReduce (ICME MR 2013)
 
Section6 stochastic
Section6 stochasticSection6 stochastic
Section6 stochastic
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
 
Solution Manual Image Processing for Engineers by Yagle and Ulaby
Solution Manual Image Processing for Engineers by Yagle and UlabySolution Manual Image Processing for Engineers by Yagle and Ulaby
Solution Manual Image Processing for Engineers by Yagle and Ulaby
 
Control assignment#2
Control assignment#2Control assignment#2
Control assignment#2
 
DCT
DCTDCT
DCT
 
DCT
DCTDCT
DCT
 
DCT
DCTDCT
DCT
 
E251014
E251014E251014
E251014
 
Revision1schema C programming
Revision1schema C programmingRevision1schema C programming
Revision1schema C programming
 
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
 
SlidesPartII_digital_control_power_electronics.pdf
SlidesPartII_digital_control_power_electronics.pdfSlidesPartII_digital_control_power_electronics.pdf
SlidesPartII_digital_control_power_electronics.pdf
 
Project2
Project2Project2
Project2
 
Demodulation bpsk up
Demodulation bpsk upDemodulation bpsk up
Demodulation bpsk up
 
Demodulate bpsk up
Demodulate bpsk upDemodulate bpsk up
Demodulate bpsk up
 
R scatter plots
R scatter plotsR scatter plots
R scatter plots
 
Analysis of an E-plane waveguide T-junction with a quarter-wave transformer u...
Analysis of an E-plane waveguide T-junction with a quarter-wave transformer u...Analysis of an E-plane waveguide T-junction with a quarter-wave transformer u...
Analysis of an E-plane waveguide T-junction with a quarter-wave transformer u...
 

Dct compressionfactor8.doc

  • 1. t=cputime; o = imread('aerialview.jpg'); w = size (o, 2); %identify no of columns in image samplesEighth = floor(w / 8); % divide column by 8 and round off ci8 = []; [x,y,z]=size(o); % identify the dimensions of image if z==1 % checking z coordinates; if z=1, image is gray % scale; if z=3,image is rgb k=1; for i=1:size(o,1) % all rows rowDCT = dct(double(o(i,:,k))); ci8(i,:,k) = idct(rowDCT(1:samplesEighth), w); end elseif z==3 for k=1:3 % all color layers: RGB for i=1:size(o,1) % all rows rowDCT = dct(double(o(i,:,k))); %picking every row and applying dct on % every element of the row,after converting it into double for better % precision % dct(k)==dct(k,1)--> gives element of 1st row after DCT % dct(k,2)--> gives element of 2nd row after DCT & so on thus K correspond to % input matrix and 1 or 2 tells the respective rows on which DCT is to be applied % DCT(K(1,3))--> element at 1st row 3rd column of matric K DCT(K(2,5))-- >element at 2nd row 5th column of matric K ci8(i,:,k) = idct(rowDCT(1:samplesEighth), w); % row elements from 1:samplesEighth are taken into consideration, rest % other elements are ignored and using those elements(1:samplesEighth), all % the possible values of desired row is predicted and placed, thus the no of % row elements remains same but it is being influenced by lower elements of % row. %%%% Each row is Transformed using the DCT, then high-order samples are %%%% discarded, and the low-order samples are reverse-transformed using IDCT. end end h = size(o, 1); % identify no of rows in image samplesEighth = floor(h / 8); ci8f = []; [x,y,z]=size(o); if z==1 % check for z coordinate of image i.e rgb component, if image is % colored, z==3 else z==1 if image is gray k=1; for i=1:size(o, 2) % all columns columnDCT8=dct(double(ci8(:,i,k)));
  • 2. ci8f(:,i,k) = idct(columnDCT8(1:samplesEighth), h); end elseif z==3 for k=1:3% all color layers: RGB for i=1:size(o, 2)% all columns columnDCT8=dct(double(ci8(:,i,k))); ci8f(:,i,k) = idct(columnDCT8(1:samplesEighth), h); end end end k=uint8(ci8f); figure, imshow(o), title('Original Image'); figure,imshow(k),title('Compression factor 8*8'); out1=uint8(k); %calculate the peak signal to noise ratio. input_ima1=double(o); out2=double(out1); error=0; for y=1:191 for x=1:159 MSE=((input_ima1(x,y))-(out2(x,y)))^2; error=MSE+error; % error_sbw1=error_sbw+MSE2; end end MSE_WO=(1/(159*191))*error disp('PSNR value for decompression image using DCT compression ');
  • 3. PSNR_WO=20*log10(255/sqrt(MSE_WO)) %Display the PSNR value. disp(PSNR_WO); disp('value for BER '); BER= 1/PSNR_WO disp('the time need to execute this program only'); cputime-t