DSPRelated.com
Forums

a question about image filtering: what should be the scaling factor after image filtering?

Started by lucy November 26, 2004
Hi all,

I am facing a headache question in image filtering...

I want to apply a low pass filter to an RGB image... I used Gaussian filter, 
using Matlab "fspecial" command

h=fspecial('gaussian', [31, 31], 5);

... and I am setting the cutoff frequency quite low because I really want to 
blur the images quite heavily...

I applied the filter to each of the RGB planes, using the Matlab "imfilter" 
command.

My input image was made sure to be within [0, 1] for each plane. So for each 
RGB plane, the range is [0, 1], [0, 1], [0, 1]. The mean of each channel 
are: R: 0.2018;  G: 0.2805;  B: 0.2892.

After the filtering, the output image has a reduced dynamic range:

R: [0.0282, 0.2089]
G: [0.0659, 0.2909]
B: [0.0429, 0.2980]

and the mean of each channel are kept almost the untouched: R: 0.1971; G: 
0.2748; B: 0.2825.

The filtered image is definitely too dark...

I have to scale it back to [0, 1]...

but do I just do scaling/normalizing to 1 in each channel individually, or 
do I normalize with respect to the overall maximum in all three channels?

But why does this filter change the relative peak ratio for each plane from 
1:1:1 to 0.2089:0.2909:0.2980? Is there any low pass filter which can 
preserve the relative peak ratio to be still 1:1:1?

And is this scaling factor an arbitrary thing as long as I make the maximum 
value to be 1, or it has some theory behind it and it can be derived 
theoratically?

Thanks a lot!






lucy wrote:

> Hi all, > > I am facing a headache question in image filtering... > > I want to apply a low pass filter to an RGB image... I used Gaussian filter, > using Matlab "fspecial" command > > h=fspecial('gaussian', [31, 31], 5); > > ... and I am setting the cutoff frequency quite low because I really want to > blur the images quite heavily... > > I applied the filter to each of the RGB planes, using the Matlab "imfilter" > command. > > My input image was made sure to be within [0, 1] for each plane. So for each > RGB plane, the range is [0, 1], [0, 1], [0, 1]. The mean of each channel > are: R: 0.2018; G: 0.2805; B: 0.2892. > > After the filtering, the output image has a reduced dynamic range: > > R: [0.0282, 0.2089] > G: [0.0659, 0.2909] > B: [0.0429, 0.2980] > > and the mean of each channel are kept almost the untouched: R: 0.1971; G: > 0.2748; B: 0.2825. > > The filtered image is definitely too dark... > > I have to scale it back to [0, 1]... > > but do I just do scaling/normalizing to 1 in each channel individually, or > do I normalize with respect to the overall maximum in all three channels? >
Do the same thing to all three channels, or your color balance will be out of whack.
> But why does this filter change the relative peak ratio for each plane from > 1:1:1 to 0.2089:0.2909:0.2980?
You should know the answer to this, really you should. If you have a signal that goes 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ... and you low-pass filter it, your filter will take those peaks and spread them out, flattening them in the process. If the filter has a DC gain of 1 the average will be preserved, however.
> Is there any low pass filter which can > preserve the relative peak ratio to be still 1:1:1?
In general no.
> > And is this scaling factor an arbitrary thing as long as I make the maximum > value to be 1, or it has some theory behind it and it can be derived > theoratically?
What happens to the signal when you low-pass filter it depends on the signal and the filter. In general you are removing the high-frequency content from the signal which is what is flattening and spreading out the peaks. I don't know of any general theory, particularly since with some signals and some filters you'd actually see your peaks getting higher (not with video and Gaussian filters, I'm sure). -- Tim Wescott Wescott Design Services http://www.wescottdesign.com