小波的定义和原理随便找本书都有讲解,简言之,小波就是将信号X
分解为近似信号A(Approximate signal)和细节信号D(Details signal)的
过程.matlab中的小波工具箱内置了丰富的函数,让复杂的小波处理
变得非常简单.(鉴于数字图像都是2维,只记录下2维相关的函数)
分解过程如:
wfilters: 指定小波函数,有很多.具体help
wavedec2: N级二维小波分解
appcoef2: 获得指定级别的近似信号A
detcoef2: 获得指定级别的细节(高频)信号h,v,或者d.具体与第一个参数有关. (得到某个高频分量,注意和下一个函数区别)
wrcoef2: 利用某个高频分量重建图像(与原图像图等大小)
测试如下:
%% wavelet study demo % xenoszhATgmail.com % 2010-05-06 function waveletTest() % get input image [filename,pathname] = uigetfile('testPics\*.jpg;*.jpeg;*.bmp;*.png','Please pick up a picture:'); if ~filename disp('No input file.'); return; end img = imread(strcat(pathname,filename)); % get grayscale image img = rgb2gray(img); size(img) % get wavelet decomposition filter coefficients, using haar function [lod,hid] = wfilters('haar','d'); % 2 level wavelet decomposition [c,s] = wavedec2(img,2,lod,hid); % get 2nd level approximate signal a2 = appcoef2(c,s,'haar',2); % convert it convert it to uint8 image in [0 255] a2 = double2uint8(a2); % get 2nd level horizontal high frequency signal h2 = detcoef2('h',c,s,2); h2 = double2uint8(h2); % get 2nd level vertical high frequency signal v2 = detcoef2('v',c,s,2); v2 = double2uint8(v2); % get 2nd level digonal high frequency signal d2 = detcoef2('d',c,s,2); d2 = double2uint8(d2); % compose 2nd level wave2 = [a2,h2;v2,d2]; % get 1st lavel horizontal high frequency signal h1 = detcoef2('h',c,s,1); h1 = double2uint8(h1); % get 1st level vertical high frequency signal v1 = detcoef2('v',c,s,1); v1 = double2uint8(v1); % get 1st level digonal high frequency signal d1 = detcoef2('d',c,s,1); d1 = double2uint8(d1); % make sure they have the same size wave2 = imresize(wave2,size(h1)); % compose 1st level (original size) wave1 = [wave2, h1; v1, d1]; % show image figure; imshow(img); % show wavelet decomposition figure; imshow(wave1); end %% sub function to convert double image to uint8 image function uint8image = double2uint8(dblimage) if nargin==1 && isa(dblimage,'double') uint8image = 255*(dblimage-min(min(dblimage)))/(max(max(dblimage))-min(min(dblimage))); uint8image = uint8(uint8image); else error('input image must be double'); end end
结果为:
No comments :
Post a Comment