You are on page 1of 6

AIM: to implement the concept of wavelet based compression to gray scale images using SOFM.

APPARATUS REQUIRED: A Personal Computer. MATLAB 7.4 THEORY: Wavelet Transform is a superior approach to other time frequency analysis tools because its time scale width of the window can be stretched to match the original signal especially for image analysis.By using SOFM technique,we have made an attempt in employing lossy technique i.e., Vector Quantisation to encode the sub bands formed by the application of wavelet Transform.We have also used a clustering property of self organizing Feature Map of Kohonen,an unsupervised training algorithm formulated by Kohonen.Sofm serves as a tool for selecting the best vectors as they are being trained and the codebooks are formed using the trained vectors.Instead of storing the grayscale image,we store only the codebook and their corresponding index values.This reduces the space required to store the image,hence the compression of the image is achieved ALGORITHM: 1. Initialization: Choose random values for the initial weight vector c j(0). c j(0) must be different for j=1,2,3k. 2. Sampling: Draw a sample c from the input distribution with a certain probability. 3. Similarity Matching: 4. The best-matching criterion is equivalent to the minimum Euclidean distance between vectors. 5. Mapping q(c) identifies the neuron that best matches the input vector c: 6. Updating:


7. Continuation: Continue until noticeable changes are observed

Program: %wavelet based compression using Sofm clear all; % CLOSE ALL closes all the open figure windows. close all; %read the image % Load original image. load woman; % X contains the loaded image. % map contains the loaded colormap. c=input('enter the codebook size'); b=input('enter the block size b='); if b==4 imshow(uint8(X)); else imshow('invalid'); end nbcol = size(map,1); imshow(uint8(X)); figure;

% Perform single-level decomposition % of X using haar. [cA1,cH1,cV1,cD1] = dwt2(X,'haar'); % Images coding. cod_X = wcodemat(X,nbcol); cod_cA1 = wcodemat(cA1,nbcol); cod_cH1 = wcodemat(cH1,nbcol); cod_cV1 = wcodemat(cV1,nbcol); cod_cD1 = wcodemat(cD1,nbcol); dec2d = [cod_cA1, imshow(uint8(dec2d)); %A5 = idwt2(cod_cA1, %imshow(uint8(A5)); %disp('dfds'); [cA2,cH2,cV2,cD2] = dwt2(cA1,'haar'); % Images coding. cod_cA1 = wcodemat(cA1,nbcol); cod_cA2 = wcodemat(cA2,nbcol); cod_cH2 = wcodemat(cH2,nbcol); cod_cV2 = wcodemat(cV2,nbcol); cod_cD2 = wcodemat(cD2,nbcol); dec2d = [cod_cA2, cod_cH2; cod_cV2, cod_cD2 ]; cod_cH1, cod_cV1, cod_cD1,'db1'); cod_cH1; cod_cV1, cod_cD1 ];

imshow(uint8(dec2d)); figure; % disp('dfds'); [cA3,cH3,cV3,cD3] = dwt2(cA2,'haar'); % Images coding. cod_cA2 = wcodemat(cA2,nbcol); cod_cA3 = wcodemat(cA3,nbcol); cod_cH3 = wcodemat(cH3,nbcol); cod_cV3 = wcodemat(cV3,nbcol); cod_cD3 = wcodemat(cD3,nbcol); dec2d = [cod_cA3, cod_cH3; cod_cV3, cod_cD3 ];

% imshow(uint8(dec2d)); %disp('dfds'); [cA4,cH4,cV4,cD4] = dwt2(cA3,'haar'); % Images coding. cod_cA3 = wcodemat(cA3,nbcol); cod_cA4 = wcodemat(cA4,nbcol); cod_cH4 = wcodemat(cH4,nbcol); cod_cV4 = wcodemat(cV4,nbcol); cod_cD4 = wcodemat(cD4,nbcol); dec2d = [cod_cA4, cod_cH4; cod_cV4, cod_cD4 ];


%disp('dfds'); % Using some plotting commands, % the following figure is generated. %n=input('enter the decomposition level'); %[Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('haar'); %[c,s]=wavedec2(uint8(dec2d),1,Lo_D,Hi_D); %[thr,nkeep] = wdcbm2(uint8(dec2d),1.5,prod(s(1,:))); %disp('level-dependent thresholds'); %disp(thr); %disp(' numbers of coefficients to be'); %disp(nkeep); comp_image = IMNOISE(uint8(X),'gaussian',0,.1); [compressed_image,TREED,PERF0,PERFL2] =WPDENCMP(148,'s',1,'haar','threshold',2,1); subplot(2,1,1); imshow(uint8(X)); title('original image'); subplot(2,1,2); imshow(comp_image); title('compressed_image');

%disp(PERF0); % disp('compression ratio=');


Thus the implementation of wavelet based compression to gray scale images using SOFM is verified and tested successfully.