Applications (with code) Matlab- wavelet transform digital image processing in image processing

1.Objectives:

1, the scaling function and wavelet function understanding
2, a learning function with wavelet transform matlab
3, practical application of the wavelet transform

2.Experiment Content:

1, a scaling function and wavelet function
2, recognized wavelet filter
3, and two-dimensional wavelet transform function reconstruction function
4, the wavelet coefficient processing function
5, the image compression and edge detection using wavelet transform

3.Experiment Principle:

See the book.

4.Experiment Steps Result and Conlusion:

1, to understand the nature of various wavelet

Function: waveinfo (wfamily); wavelets show different properties
Here Insert Picture Description
Here Insert Picture DescriptionHere Insert Picture Descriptionthan the wavelet information is obtained waveinfo

2, the various observation wavelet function and scaling function

Function [Phi, PSI, xval is] = wavefun (by wname,, ITER)
; mother wavelet is a wavelet function, the wavelet transform is the basic "group", is the parent wavelet scaling function, obtained by the parent wavelet different scales, different displacements "base" on. Wavelet transform can be obtained by the overview diagram, the abscissa, ordinate, detail view on a diagonal
Here Insert Picture Description

3, to obtain wavelet filter

Function [Lo_D, Hi_D, Lo_R, Hi_R ] = wfilters (wname)
for example: [Lo_D, Hi_D, Lo_R, Hi_R] = wfilters ( 'sym4') to obtain a low-frequency decomposition 'sym4' wavelet decomposition of high-frequency, low-frequency reconstruction, high frequency reconstruction filter.
Here Insert Picture Description
Effect of each filter are written in the title has, we can see a low decomposition and high-frequency decomposition convex, a concave, for the same frequency reconstruction, decomposition, substantially the same shape

4, the two-dimensional wavelet transformation functions and the reconstruction function

Positive transform function: [C, S] = wavedec2 (X-, N, wname)
X = imread ( 'lena256.bmp');
[C, S] = wavedec2 (X,. 3, 'DB4');

Learn C, s meaning of the data
to view a two-dimensional FIG decomposition coefficients: wave2gray (C, S);
a reconstruction function: g = waverec2 (C, S , wname)

For example:
G = waverec2 (C, S, 'DB4');
Figure, imshow (G, []);
Here Insert Picture Description
see the left, only an overview diagram because the profile is an exploded three times before obtained, which size is equal to divided by three quarter of the original image after wavelet ,, reconstructed picture can be obtained, as shown on the right image is an exploded three times, i.e., decomposed into a first profile and three details are a horizontal, vertical, diagonal. After three decomposition, into a total overview, 9 details
Here Insert Picture Description
for s1 is the first line of information inside rgb size of the smallest image is decomposed, the second to fourth are decomposed into each stage to give the size of the image detail, is the last original size is to c1, which is information for each of the decomposition is an exploded diagonal detail in the order of the vertical profile horizontal detail details into the row vector.

5, view and deal with wavelet coefficients

A = appcoef2 (C, S, by wname,);
D = detcoef2 (O, C, S, n-);
NC = wthcoef2 (type, C, S, n-, T, sorth)
Here Insert Picture Description
which is wavelet we see with appcoef2 function information overview image of the decomposed
Here Insert Picture Description
here we see a break down to the details of the third-class with detcoef2 get
Here Insert Picture Description
this information after we wthcoef2 function details are changed to 0 after then detcoef2 get to see, indeed all values have become 0

6, the image compression and edge detection using wavelet transform

Here Insert Picture Description

The left is the original image on the right is that we will have all the details of the results obtained after removal of the reconstruction, and therefore only got an overview image of Here Insert Picture Descriptionthe right is our overview image of the original set after 0, the resulting reconstructed image, in other words only the configuration of FIG detail, the figures also form the gray image portions obvious change, to the effect of edge extraction.

[Appendix] implementation code

A program:

waveinfo('haar');
waveinfo('gaus');
[phi psi xval]=wavefun('db3',4);%迭代2^4次 xval就是返回的坐标轴的一个分度
figure(1);
subplot(211);plot(xval,phi);title('小波函数');
subplot(212);plot(xval,psi);title('尺度函数'); 

[Lo_D,Hi_D,Lo_R,Hi_R]=wfilters('sym4');%获得sym4小波的低频分解,高频分解,低频重构,高频重构滤波器

figure(2);
subplot(221);plot(Lo_D);title('低频分解');
subplot(222);plot(Hi_D);title('高频分解');
subplot(223);plot(Lo_R);title('低频重构');
subplot(224);plot(Hi_R);title('高频重构');

Procedure 2

f=imread('E:\数字图像处理\程序与图像\标准图片\lena256.BMP');
[c s]=wavedec2(f,3,'db4');
%对图像进行了3次分解,也就是说,第一次分解成一个概貌与三个分别是水平,垂直,对角线的细节
%分解三次后,一共变成了一个概貌,9个细节 
%对于s1来说里面的信息是rgb的第一行是分解得到的最小图像的大小 
%第二个到第四个分别是分解到每级得到的细节图像的大小,最后一个是原图的大小%对于c1来说,里面的信息是分解之后的信息是每分解一级按照概貌 水平细节 垂直细节 对角线细节的顺序 变成的行向量。
%并且这种是列的连接比如H(:)'每再分解只改变上一级概貌信息所占位置的数值

figure(1);
subplot(121);
wave2gray(c,s);
%查看分解系数二维图
title('小波分解3次后图像');
g=waverec2(c,s,'db4');%用分解后的概貌与细节图重构原图
subplot(122);
imshow(g,[]);%因为重构后的图像完成后不属于图片信息,因此要加上[]
title('重构后小波图像');

Procedure 3:

%查看及处理小波系数
a=appcoef2(c,s,'db4');%返回的a是位于最低一级的概貌信息
b=detcoef2('h',c,s,3);%这里是返回细节信息,h地表返回的是水平信息,3代表分解到第三级的细节,%用此函数就可以得到任意级的水平 垂直 对角线的细节信息
newc=wthcoef2('h',c,s,3);%这是将c中规定的区域值设为0;比如这里就是分解第“3”级的“水平”分量设为0
newb=detcoef2('h',newc,s,3);%查看改变为0后的结果,验证结论

Program four

%用小波变化进行图像压缩与边沿处理
f=imread('E:\数字图像处理\程序与图像\标准图片\lena256.BMP');
[c,s]=wavedec2(f,3,'haar');%用haar小波进行三级分解
newc1=wthcoef2('t',c,s,[2 1]);%将分解的1-2级的值全部置为0
g1=waverec2(newc1,s,'haar');
figure(1);
subplot(121);imshow(f);title('原图');
subplot(122);imshow(g1,[]);title('舍弃一二级分解后的细节信息后的压缩图');
newc2=wthcoef2('a',c,s);%这里将概貌信息的值全部置为0;
g2=waverec2(newc2,s,'haar');%用新的newc重构
figure(2);
subplot(121);imshow(f);title('原图');
subplot(122);imshow(g2,[]);title('概貌图置为0后压缩后图');

Image: Screenshot above all to show

Published 17 original articles · won praise 12 · views 1660

Guess you like

Origin blog.csdn.net/weixin_42784535/article/details/105123958