Wavelet image analysis and compression
Written to not use wavelet toolbox, instead using functions
dwt2haar and idwt2haar. Alternate toolbox commands shown in comments.
Contents
Load image
RGB = imread('ngc6543a.jpg');
image(RGB);
size(RGB)
ans =
650 600 3
Crop/pad to 640 x 576 to allow 6-level binary subsampling
pic = RGB(11:650, 12:587,:);
image(pic);
maxlev = 6;
C = dwt2Haar(pic,maxlev);
Plot cumulative wavelet power fraction vs. fraction of wavelets retained
np = length(C(:));
Csq = C(:).^2;
[mCsqsort,Isort] = sort(-Csq);
respowfrac = 1 - cumsum(mCsqsort)/sum(mCsqsort);
semilogy((1:np)/np,respowfrac)
xlabel('Fraction of wavelets retained')
ylabel('Fraction of power not captured')
Plot image filtered by only retaining the largest wavelets
keepfrac = 0.02;
Izero = Isort(round(keepfrac*np):np);
Cfilt = C(:);
Cfilt(Izero) = 0;
Cfilt = reshape(Cfilt,size(C));
picfilt = idwt2Haar(Cfilt,maxlev);
image(uint8(picfilt));