Discrete Wavelet Transform Matlab

馋奶兔 提交于 2019-12-21 21:25:35

问题


I am trying to use the functions provided in the Matlab Wavelet Toolbox to create a multi-level discrete wavelet decomposition of an image, extracting the coefficients, manipulating them, and recomposing them back into the image.

I tried using a number of functions but none of them seem to do what I need. These are the steps to do this.

  1. Use wavedec2 to decompose the image into [C,S]. [C,S] = wavedec2(X,N,Lo_D,Hi_D)

  2. I then must use detcoef2 to extract the detail coefficients from [C,S]. [C,S] is the 'wavelet decomposition structure', it does not represent the actual coefficients such as cD, cH, cV. [H,V,D] = detcoef2('all',C,S,N)

  3. Manipulate the data

  4. Reconstruct [C,S] ???? no function does this.

  5. Use waverec2 to recompose the original image. X = waverec2(C,S,Lo_R,Hi_R)

The problem is with step 4. There is no function that recreates the [C,S] and I can't call the function waverec2 because it needs the manipulated version of C and S.

Do I not need wavedec2 and waverec2? Perhaps should I just use detcoef2 and upcoef2?

Someone with some experience with DWT could solve this in a minute, I am fairly new to it.

Thanks


回答1:


I'm curious as to why you can't use dwt2 for computing the 2D DWT of images. What you have there is a lot more work than what you should be doing. dwt2 is much more suitable to do what you want. You'd call dwt2 like so:

[LL,LH,HL,HH] = dwt2(X,Lo_D,Hi_D);

X is your image, and Lo_D and Hi_D are your low-pass and high-pass filters you want to apply to the image. LL is the low-passed version of the image, where the horizontal and vertical directions are low-passed, LH is where the vertical direction is low-passed and the horizontal direction is high-passed, HL is the vertical direction is high-passed and the horizontal direction is low-passed, and HH is where both directions are high-passed. As such LH, HL and HH are the detail coefficients while LL contains the structure.

You can also specify the filter you want with a string as the second parameter:

[LL,LH,HL,HH] = dwt2(X,'wname');

'wname' is a string that specifies what filter you want. You can type in help wfilters to see what filters are available.

For example, by doing using cameraman.tif from MATLAB's system path, we can do a one level 2D DWT (using the Haar wavelet) and show all of the components like so:

im = imread('cameraman.tif');
[LL, LH, HL, HH] = dwt2(im2double(im), 'haar');
imshow([LL LH; HL HH], []);

I use im2double to convert the image to double precision to ensure accuracy. We get this image:

Note that the image is subsampled by 2 in order to produce the decompositions of LL, LH, HL and HH.

Once you have these components, you can certainly manipulate them to your heart's content. Once you manipulate them, you can simply use idwt2 like so:

Y = idwt2(LL,LH,HL,HH,Lo_R,Hi_R); %//or
Y = idwt2(LL,LH,HL,HH,'wname');

The four components are assumed to be double, and so you can convert the images back to whatever type that was representing the image. Assuming your image was uint8, you can do: Y = im2uint8(Y); to convert back.

This should hopefully be what you're looking for!



来源:https://stackoverflow.com/questions/29021346/discrete-wavelet-transform-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!