16 Nov 2010

Image compression using Wavelet

Image compression using Wavelet


%Image compression for color images

clc;clear all;close all;


% Reading an image file

input_image=imread('Winter.jpg');

X=input_image;


% inputting the decomposition level and name of the wavelet

n=input('Enter the decomposition level:');

x = double(X);

TotalColors = 255;

map = gray(TotalColors);

x = uint8(x);


%Conversion of RGB to Grayscale

x = double(X);

xrgb=rgb2gray(X);

x = wcodemat(xrgb,TotalColors);

map = pink(TotalColors);

x = uint8(x);


% A wavelet decomposition of the image

[c,s] = wavedec2(x,n,'haar');

% wdcbm2 for selecting level dependent thresholds

alpha = 1.5;

[thr,nkeep] = wdcbm2(c,s,alpha)


% Compression

[xd,cxd,sxd,perf0,perfl2] = wdencmp('lvd',c,s,'haar',n,thr,'h');

disp('Compression Ratio:');disp(perf0);


% Plot original and compressed images.

subplot(211), image(x);

colormap(map);title('Original image');

subplot(212), image(xd);

colormap(map);title('Compressed image')


%Computing the image size

disp('Original Image');

imwrite(x,'original.tif');

imfinfo('original.tif')

disp('Compressed Image');

imwrite(xd,'compressed.tif');

imfinfo('compressed.tif')

No comments: