MATLAB Newsgroup

thank you in advance actually i am studying in btech electronics and communication and have undertaken a project to use wavelets to compress images, i searched a lot of codes online in an attempt to understand how to build a software to compress images . one of the code i am interested in is given below and i would like the help of brilliant ppl who visit this forum . i hope some one would help me on this .

below is the code and i have put in my problems with it in comments . thank u again in advance

any explanation would be helpful as i am a rookie in the field of matlab and wavelets

clear all;

close all;

image = imread('rice.png');

input_image_used = im2double(image); % why do we need double ????

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 .

[c,s]=wavedec2(input_image_used,n,Lo_D,Hi_D);

disp('The decomposition vector output is');

disp(c);

disp('Size : ');

disp(s);

[thr,nkeep] = wdcbm2(c,s,1.5,3*prod(s(1,:)));

[xd,cxd,sxd,perf0,perfl2] = wdencmp('lvd',c,s,'haar',n,thr,'s');

disp('Compression ratio in percentage : ');

disp(perfl2);

subplot(1,2,1);

imshow(input_image_used);

title('Input image');

subplot(1,2,2);

imshow(xd);

title('Compressed image');

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 FFT-Convolve 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.

"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 FFT-Convolve 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.

> 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 FFT-Convolve 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.

You're welcome, chetan. Good luck :)

hi sir

every thing is understadable.

And i have done my project upto that.

I dont know how the classification step is done.

please send the code for classification using neural networks.

On Apr 30, 1:43 am, "Thomas Clark" <t.cl...@remove.spamcantab.net>

wrote:

> 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 FFT-Convolve 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.

Hello,

I think you've got the wrong thread- this one is about wavelet compression, not classification using neural networks - that's an entirely different subject.

Also, your requests are likely to get a better response if you give a thorough explanation of the problem.

Tom Clark

sirishasrinivas.m@gmail.com wrote in message <237a0c21-f5e9-4be8-a62b-b31189cdf624@21g2000vbk.googlegroups.com>...

>

> hi sir

> every thing is understadable.

> And i have done my project upto that.

> I dont know how the classification step is done.

> please send the code for classification using neural networks.

>

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 FFT-Convolve 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.

"chetan sood" <chetan_mastnath@yahoo.com> wrote in message <gt9sk1$jph$1@fred.mathworks.com>...

> thank you in advance actually i am studying in btech electronics and communication and have undertaken a project to use wavelets to compress images, i searched a lot of codes online in an attempt to understand how to build a software to compress images . one of the code i am interested in is given below and i would like the help of brilliant ppl who visit this forum . i hope some one would help me on this .

>

> below is the code and i have put in my problems with it in comments . thank u again in advance

>

> any explanation would be helpful as i am a rookie in the field of matlab and wavelets

>

>

>

> clear all;

> close all;

> image = imread('rice.png');

> input_image_used = im2double(image); % why do we need double ????

> 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 .

> [c,s]=wavedec2(input_image_used,n,Lo_D,Hi_D);

> disp('The decomposition vector output is');

> disp(c);

> disp('Size : ');

> disp(s);

> [thr,nkeep] = wdcbm2(c,s,1.5,3*prod(s(1,:)));

> [xd,cxd,sxd,perf0,perfl2] = wdencmp('lvd',c,s,'haar',n,thr,'s');

> disp('Compression ratio in percentage : ');

> disp(perfl2);

> subplot(1,2,1);

> imshow(input_image_used);

> title('Input image');

> subplot(1,2,2);

Hi , Have you tried using wcompress()?

Wayne

> imshow(xd);

> title('Compressed image');

Hi Wayne

I am using the following code for my project work,

im=cellstr(im1); %%% im1 is an array with 15 images.

[r,c]=size(im);

close all;

for row=1:r

img=char(im(row));

img1=imread(img);

img1=im2double(img1); %% should i convert the image to double

[c,s] = wavedec2(img1,2,'haar');

%%second level detail coefficients %%%

[cH1,cV1,cD1] = detcoef2('all',c,s,2);

%%% converting 2d to 1d array horizontal

rk1 = reshape(cH1, 1, prod(size(cH1))) ;

t=numel(rk1);

y=1;

for j=1:t

if(rk1(1,j)~=0)

ckH1(row,y)=rk1(1,j); %% eliminating zero's

y=y+1;

end

end

%%% converting 2d to 1d array vertical

rk1 = reshape(cV1, 1, prod(size(cV1))) ;

t=numel(rk1);

y=1;

for j=1:t

if(rk1(1,j)~=0)

ckV1(row,y)=rk1(1,j); %% eliminating zero's

y=y+1;

end

end

%%% converting 2d to 1d array diagonal

rk1 = reshape(cD1, 1, prod(size(cD1))) ;

t=numel(rk1);

y=1;

for j=1:t

if(rk1(1,j)~=0)

ckD1(row,y)=rk1(1,j);

y=y+1;

end

end

end

meanckH1=mean(ckH1(:));

meanckV1=mean(ckV1(:));

meanckD1=mean(ckD1(:));

1. I am getting different decomposed coefficent values when i convert the image to double and then call wavedec2 function, compared to when i dont convert and use the image directly. Which is right should i convert the image to double or directly use it.

2. The values which i get are few negative values

3. The decomposed values are also decimal values

4. Can i go for 4th level of decomposition using haar wavelet.

Thanks in advance

Meena

You can think of your watch list as threads that you have bookmarked.

You can add tags, authors, threads, and even search results to your watch list. This way you can easily keep track of topics that you're interested in. To view your watch list, click on the "My Newsreader" link.

To add items to your watch list, click the "add to watch list" link at the bottom of any page.

To add search criteria to your watch list, search for the desired term in the search box. Click on the "Add this search to my watch list" link on the search results page.

You can also add a tag to your watch list by searching for the tag with the directive "tag:tag_name" where tag_name is the name of the tag you would like to watch.

To add an author to your watch list, go to the author's profile page and click on the "Add this author to my watch list" link at the top of the page. You can also add an author to your watch list by going to a thread that the author has posted to and clicking on the "Add this author to my watch list" link. You will be notified whenever the author makes a post.

To add a thread to your watch list, go to the thread page and click the "Add this thread to my watch list" link at the top of the page.

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Got questions?

Get answers.

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreDiscover what MATLAB ^{®} can do for your career.

Opportunities for recent engineering grads.

Apply TodayThe newsgroups are a worldwide forum that is open to everyone. Newsgroups are used to discuss a huge range of topics, make announcements, and trade files.

Discussions are threaded, or grouped in a way that allows you to read a posted message and all of its replies in chronological order. This makes it easy to follow the thread of the conversation, and to see what’s already been said before you post your own reply or make a new posting.

Newsgroup content is distributed by servers hosted by various organizations on the Internet. Messages are exchanged and managed using open-standard protocols. No single entity “owns” the newsgroups.

There are thousands of newsgroups, each addressing a single topic or area of interest. The MATLAB Central Newsreader posts and displays messages in the comp.soft-sys.matlab newsgroup.

**MATLAB Central**

You can use the integrated newsreader at the MATLAB Central website to read and post messages in this newsgroup. MATLAB Central is hosted by MathWorks.

Messages posted through the MATLAB Central Newsreader are seen by everyone using the newsgroups, regardless of how they access the newsgroups. There are several advantages to using MATLAB Central.

**One Account**

Your MATLAB Central account is tied to your MathWorks Account for easy access.

**Use the Email Address of Your Choice**

The MATLAB Central Newsreader allows you to define an alternative email address as your posting address, avoiding clutter in your primary mailbox and reducing spam.

**Spam Control**

Most newsgroup spam is filtered out by the MATLAB Central Newsreader.

**Tagging**

Messages can be tagged with a relevant label by any signed-in user. Tags can be used as keywords to find particular files of interest, or as a way to categorize your bookmarked postings. You may choose to allow others to view your tags, and you can view or search others’ tags as well as those of the community at large. Tagging provides a way to see both the big trends and the smaller, more obscure ideas and applications.

**Watch lists**

Setting up watch lists allows you to be notified of updates made to postings selected by author, thread, or any search variable. Your watch list notifications can be sent by email (daily digest or immediate), displayed in My Newsreader, or sent via RSS feed.

- Use a newsreader through your school, employer, or internet service provider
- Pay for newsgroup access from a commercial provider
- Use Google Groups
- Mathforum.org provides a newsreader with access to the comp.soft sys.matlab newsgroup
- Run your own server. For typical instructions, see: http://www.slyck.com/ng.php?page=2