Hi
Got lot of information about wavelets from your reply to chetan.
I used the wavedec2 function to perform wavelet decomposition on the image, and i had used haar wavelet. Since i have used the built in function to perform wavelet decomposition, i justed wanted to know whether i can get the basis function for haar wavelet and how it works when applied to images.
I just wanted to know whether can i get the horizontal, vertical and diagonal decomposition matrix by using the basis function rather then using the wavedec2 builtin function.
Thanks
meena
"chetan sood" <chetan_mastnath@yahoo.com> wrote in message <gtf8fd$qid$1@fred.mathworks.com>...
> "Thomas Clark" <t.clark@remove.spamcantab.net> wrote in message <gtae4l$dll$1@fred.mathworks.com>...
> > Hi Chetan.
> >
> > Firstly, you'll find a number of toolboxes for wavelet compression here on the mathworks file exchange.
> > So, I started off going through your code below, but it's basically ended up as an explanation of wavelets! Bear in mind that I'm a diehard Matlab user  so given that you're new, I'll insert some (hopefully useful) comments on coding style at the same time.
> >
> > > clear all;
> > > close all;
> >
> > You're killing us. If you clear all and close all, you'll lose any work currently in the Matlab environment. Consider putting the following code into a function, then you don't have to worry about it affecting other work, and functions have their own 'variable workspace'
> >
> > > image = imread('rice.png');
> > 'image' is a function name, so don't use it as a variable name as well  sooner or later things will get confusing!
> >
> > > input_image_used = im2double(image); % why do we need double ????
> > Depending on the file read in, the imread function can read in arrays which are of the wrong data type  often an integer (do some research about variable type and class if you're unsure what this means). Converting to double (which is MATLAB's default variable type) means you are able to use this variable in subsequent analysis codes.
> >
> > > n=input('Enter the decomposition level : ');
> > > [Lo_D,Hi_D,Lo_R,Hi_R] = wfilters('haar'); % what is the physical significance of the 4 filters?
> >
> > Wow, this is a really hard one to answer in brief. I'd recommend you get a copy of Ingrid Daubechies' book 'Ten Lectures On Wavelets' to fully understand the issue. However, I have a simple explanation.
> > *CAVEAT#1* This will get the mathematicians really screeching, because there are many subtleties  but might help you to understand whats going on.
> > *CAVEAT#2* Don't actually try taking a wavelet transform using the procedure below. Again, hidden nasties  so always use a proper wavelet transform code.
> > 1. Take an FFT of a signal (say an image)
> > 2. Take the FFT of a different signal, let's call that signal W
> > 3. Convolve the two signals (multiply in the fourier domain)
> > 4. Take the IFFT
> > What this does is extract particular features of the image  so any features within the image which resemble the signal W will be accentuated; any features which don't will be suppressed.
> > NB hopefully this stuff should be familiar to you  if it isn't, don't even think about wavelets until you've learned at least the basics of fourier transforms.
> > We call this signal W a 'filter', as convolving the image with it filters out aspects of the image which are not similar to the filter signal.
> >
> > A wavelet is a filter just like that; but there is an additional step. You may have heard of a multiresolution analysis (MRA)  if not, you are now! Imagine repeating the process above many times  each time you halve the size of your filter signal W, keeping it the same shape. Comparing the output images (after the several different IFFTs) you'd notice something: Large basic shapes would be represented where the larger filters are used; and smaller details of the image would come out in the results where smaller filters are used. Make sense?
> >
> > A wavelet transform is a multiresolution analysis, using the shape of the wavelet as the filter  thereby separating the input signal into different scale components. Once you've taken the forward wavelet transform you end up with, a signal which contains position and 'energy' (magnitude) of the components of your signal, for each different scale. **
> >
> > So, you want to try this? if your signal W is some general or arbitrary signal, you'll get garbage. However, nice mathematicians come along and define particular shapes which don't give garbage. These shapes are 'wavelets'.
> >
> > Different types of wavelet have different characteristics. A few keywords describing wavelet characteristics you might hear are 'compact support' and 'biorthogonal'. Wavelets often come in familes (similar shapes/derivations)  you'll hear about 'mexican hats', 'haar', 'daubechies', 'interpolets'... a great one to start with is Daubechies 4th order wavelets  they're good for image processing (I *think i remember* they have compact support, and good aliasing characteristics).
> >
> > In the case of a haar type (if I remember correctly) the shape of the wavelet is a square pulse (someone please correct me if I'm wrong). So these wavelets are good at capturing sharp edges in input signals. I *think* that haar wavelets are second order (I'm remembering this stuff from ages ago!).
> >
> > Picking up from the ** earlier on, it's worth mentioning the reason why wavelets are so good for compression  if you look at the magnitude of your signal, then lots of it is actually close to zero at any given scale. A full transform takes up the same space in memory as the original image  so get rid of the components which are close to zero and store only the 'energetic' components. This takes up much less memory, but you can reconstruct the image very well as you've only got rid of bits which barely contributed anyway. You'll probably know by now that this is how JPEG images work  and store pictures in such little memory.
> >
> > Getting back to the original question, the 4 filters are: 2 for decomposition, 2 for reconstruction.
> > I think that you only do two resolution levels using the haar wavelet  so I infer (not familiar with the toolbox you're using either, as I write my own codes) that Lo_D is the filter for the lower resolution and Hi_D is the one for (surprise!) higher resolution.
> >
> > Note that I've been using the word filter very generally here; so we need to be a little careful. The reason filters are used to perform a wavelet transform is that the FFT introduces nasties (as sines and cosines are the basis functions, they are infinite functions therefor don't have compact support  you can get some strange effects). It was found (I think by the mathematician Meyer) that instead of applying the FFTConvolve type approach I stated above, that you could do to wavelet transforms by directly deriving the filters associated with the wavelet shapes you want and operating with them  not requiring an FFT. This is faster and eliminates problems of compact support. These are the types of filters represeneted by the variables Hi_D and Lo_D. (I.e. those variables don't directly contain the wavelet, just the filter associated with it).
> >
> >
> > > [c,s]=wavedec2(input_image_used,n,Lo_D,Hi_D);
> > I'm sorry, pal  I'm lost from here on in, because I'm not familiar with the toolbox so couldn't explain the individual commands. Hopefully in the light of what I've said above, the toolbox documentation will be a little clearer so you can make your own way.
>
>
>
>
>
>
> THANKS A LOT,
> first of all i would really thank you for taking a minute (actually i believe it would have been more than that) to reply to my query. your reply was of utmost help, and yes i am familiar with MRA and ffts and convolution. your answer was very helpful. again heartiest thanks.
>
> and may god bless you.
