Penn State Harrisburg
Digital Image Processing
Image Compression using DCT
Chad RyanWeiss
4/25/2016
Abstract:
Image compressionhasbecome the mostimportant,energyefficiencymethodfortransferringvideos
and imagesviaany communicationsystem. Before some of the veryfirstimage compressiontechniques
were everestablished,itwouldtake hourstoupload,download,file share andtransmitmediafiles
because the file sizeswere toobig. Evenwiththe 4G technologythatwe have today, these tremendous
file sizeswouldstillpose amajorproblemtomemorystorage systems. Since the dawnof the early
digital image processingdays,scientistsandmathematicianshave beencomingupwithcleverwaysto
compressimagesandframes foreasystorage and data transfer. Methodslike the discrete cosine
transformuse highlyadvancedmathematical principlestorepresentimagesthatallow formodification
and cleversize manipulationof the overall image. Byimplementingdigital image processingtechniques
like the discrete cosine transform,one wouldessentiallymake the packetof informationalotlighterfor
transportand storage.
Theory:
The discrete cosine transform(DCT) isa methodthatrepresentsanimage asa sum of sinusoidsof
varyingmagnitudesandfrequencies. Itisthisrepresentationof the image asa sumof sinusoidsthat
allowsforthe fact that mostof the visuallysignificantinformationaboutthe image isconcentratedin
the DCT coefficients. Forthisreason,DCT hasbecome a well-known,popularimage compression
standardfor lossyimage compression. Animportantqualityaboutthe DCTisthat it isinvertible,which
isconvenientforthe realmof image compressionbecause itissometimesnecessaryandrecoverthe
original image forthe sake of acquiringthe primarysource of information.
Whencompressinganimage usingDCT,the image inputisfirstdividedinto8by 8 or 16 by16 blocks
and thenthe DCT is computedforeachblockof information. The coefficientsof the DCTtransformare
thenobtained,quantized,codedandtransmitted. Once the transmitterhasessentiallytransferredall of
the informationandthe receiverhaspickedupthe signal,the receiverbeginstodecode the quantized
coefficients,computesthe inverse DCTof eachblockand thenreconstructsthe original image.
The reasonthe DCT iscalleda lossymethodforcompressingimagesisdue tothe fact that many of
these coefficientsare nearlyzeroandholdnot-so-importantinformationinregardstothe bigpicture.
These valuesare simple thrownoutbecause theycanbe andthe image becomessmaller. Usually,the
userhas no ideathatthese have been thrownoutbecause of how small orinsignificantthese partsof
the image were tothe overall whole.
Example Code:
clear all; close all; clc;
I = imread('NASA.jpg');
I=double(I(:,:,1))/255;
T = dctmtx(8);
B = blkproc(I,[8 8],'P1*x*P2',T,T');
mask = [1 1 1 0 0 0 0 0
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0];
B2 = blkproc(B,[8 8],'P1.*x',mask);
I2 = blkproc(B2,[8 8],'P1*x*P2',T',T);
imtool(I);
imtool(I2);
The code seenatleftwill compressa
two-dimensional imageusingthe DCT.
We start byreadinginan image using
the imreadfunction. Followingthis
immediate actionwe thenconvertthe
image to data type double andscale it
downto account forthisdata shift.
Next,we create a DCT coefficient
matrix usingthe dctmtx function,which
will be usedinthe precedinglinesof
code to pre andpost multiply the 8-by-
8 blocksof data of ourimage.The
blkprocfunctioncreatesthe 8-by-8
chunksof data andallowsusto throw
inthe pre and postmultiplicationas
part of the function’sinputarguments.
Finallywe decide whichcoefficientsto
keepbyapplyingthe maskandthen
applyingthe inverseDCTto recoverthe
image anddisplaythe outputs.(NEXT)
Figure 1 representsthe original image. Aftersavingthisimage tothe desktop,the size of thisoriginal
file wasfoundtocontain 33.8 kb of data. Now we will determinethe compressionratioof this
particularexample byreferringtothe nextimage.
Figure 1: Original Image
Figure 2 representsthe compressedimage. Itcan be seenthatsome of the finerdetailshave been
blurredor leftoutentirely. Aftersavingthisfile tothe desktop,the file sizewasfoundtobe only13 kb!
The DCT yieldedacompressionratioof aboutC = 33.8 kb/ 13 kb= 2.6!
Figure 2: Compressed Image
Conclusion:
In summary,we talkedabouthowthe DCT isusedin digital image processingaswell as the implications
of image compression. We brieflytalkedaboutsome of the theory behind the DCT and found that a lot
of itis basedonhighlyadvancedmathematical andscientificconcepts. Lastly, we provided an example
of the DCT image compression techniques sing MatLab. The results were displayed and we found for
our particularexample thatthe outputimage was compressed by a factor of 2.6 without any major loss
of information as to what the big picture actual represents.

Project004

  • 1.
    Penn State Harrisburg DigitalImage Processing Image Compression using DCT Chad RyanWeiss 4/25/2016
  • 2.
    Abstract: Image compressionhasbecome themostimportant,energyefficiencymethodfortransferringvideos and imagesviaany communicationsystem. Before some of the veryfirstimage compressiontechniques were everestablished,itwouldtake hourstoupload,download,file share andtransmitmediafiles because the file sizeswere toobig. Evenwiththe 4G technologythatwe have today, these tremendous file sizeswouldstillpose amajorproblemtomemorystorage systems. Since the dawnof the early digital image processingdays,scientistsandmathematicianshave beencomingupwithcleverwaysto compressimagesandframes foreasystorage and data transfer. Methodslike the discrete cosine transformuse highlyadvancedmathematical principlestorepresentimagesthatallow formodification and cleversize manipulationof the overall image. Byimplementingdigital image processingtechniques like the discrete cosine transform,one wouldessentiallymake the packetof informationalotlighterfor transportand storage.
  • 3.
    Theory: The discrete cosinetransform(DCT) isa methodthatrepresentsanimage asa sum of sinusoidsof varyingmagnitudesandfrequencies. Itisthisrepresentationof the image asa sumof sinusoidsthat allowsforthe fact that mostof the visuallysignificantinformationaboutthe image isconcentratedin the DCT coefficients. Forthisreason,DCT hasbecome a well-known,popularimage compression standardfor lossyimage compression. Animportantqualityaboutthe DCTisthat it isinvertible,which isconvenientforthe realmof image compressionbecause itissometimesnecessaryandrecoverthe original image forthe sake of acquiringthe primarysource of information. Whencompressinganimage usingDCT,the image inputisfirstdividedinto8by 8 or 16 by16 blocks and thenthe DCT is computedforeachblockof information. The coefficientsof the DCTtransformare thenobtained,quantized,codedandtransmitted. Once the transmitterhasessentiallytransferredall of the informationandthe receiverhaspickedupthe signal,the receiverbeginstodecode the quantized coefficients,computesthe inverse DCTof eachblockand thenreconstructsthe original image. The reasonthe DCT iscalleda lossymethodforcompressingimagesisdue tothe fact that many of these coefficientsare nearlyzeroandholdnot-so-importantinformationinregardstothe bigpicture. These valuesare simple thrownoutbecause theycanbe andthe image becomessmaller. Usually,the userhas no ideathatthese have been thrownoutbecause of how small orinsignificantthese partsof the image were tothe overall whole. Example Code: clear all; close all; clc; I = imread('NASA.jpg'); I=double(I(:,:,1))/255; T = dctmtx(8); B = blkproc(I,[8 8],'P1*x*P2',T,T'); mask = [1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; B2 = blkproc(B,[8 8],'P1.*x',mask); I2 = blkproc(B2,[8 8],'P1*x*P2',T',T); imtool(I); imtool(I2); The code seenatleftwill compressa two-dimensional imageusingthe DCT. We start byreadinginan image using the imreadfunction. Followingthis immediate actionwe thenconvertthe image to data type double andscale it downto account forthisdata shift. Next,we create a DCT coefficient matrix usingthe dctmtx function,which will be usedinthe precedinglinesof code to pre andpost multiply the 8-by- 8 blocksof data of ourimage.The blkprocfunctioncreatesthe 8-by-8 chunksof data andallowsusto throw inthe pre and postmultiplicationas part of the function’sinputarguments. Finallywe decide whichcoefficientsto keepbyapplyingthe maskandthen applyingthe inverseDCTto recoverthe image anddisplaythe outputs.(NEXT)
  • 4.
    Figure 1 representstheoriginal image. Aftersavingthisimage tothe desktop,the size of thisoriginal file wasfoundtocontain 33.8 kb of data. Now we will determinethe compressionratioof this particularexample byreferringtothe nextimage. Figure 1: Original Image
  • 5.
    Figure 2 representsthecompressedimage. Itcan be seenthatsome of the finerdetailshave been blurredor leftoutentirely. Aftersavingthisfile tothe desktop,the file sizewasfoundtobe only13 kb! The DCT yieldedacompressionratioof aboutC = 33.8 kb/ 13 kb= 2.6! Figure 2: Compressed Image
  • 6.
    Conclusion: In summary,we talkedabouthowtheDCT isusedin digital image processingaswell as the implications of image compression. We brieflytalkedaboutsome of the theory behind the DCT and found that a lot of itis basedonhighlyadvancedmathematical andscientificconcepts. Lastly, we provided an example of the DCT image compression techniques sing MatLab. The results were displayed and we found for our particularexample thatthe outputimage was compressed by a factor of 2.6 without any major loss of information as to what the big picture actual represents.