From: Susan Hall on
I'm resurrecting an old question here.

> "Sachitha Obeysekara" <sachitha.obeysek...(a)nospam.nokia.com> wrote:
> > I have a filter formed by:
> > b = fir1(5,0.5)
> > b =
> > -0.0078 0.0645 0.4433 0.4433 0.0645 -0.0078
> > Whats the most efficient way of applying this filter to a 2D
> > image, first in the x-direction, then in the y-direction?
> > ...I've already considered using ftrans2 to form a 2D filter
> > and do it all in one go, but I want to to it the 1D way.

and Peter Boettcher <boettc...(a)ll.mit.edu> replied:
(in message <muy7ibwy1py....(a)G99-Boettcher.llan.ll.mit.edu>)

> That's called a separable filter, and it is indeed much more efficient
> to apply it separately than to form the full 2D kernel.
> "conv2" will do the separable filter for you. Just specify the same
> kernel for both H1 and H2.

My question is, the image data that results from doing the conv2 using
a 1D fir filter on a 2D image now has some negative values. Unlike
audio data that varies above and below zero, the data range for images
is all positive. How do you interpret the negative values in the
filtered image?
Specifically, I'm blurring a simple white (1, or 255) rectangle on a
black background (0). Using this type of filtering, the result has
some negative values. Is there a valid normalization procedure to use?
If you just raise everything up, then the filtered image has ripples
outside the original white box - but maybe that just reflects an
inadequate filter? How can I make a 1D fir filter appropriate for 2D
use? (I don't have the image processing toolbox).
In general, are there things to be aware of when working with time
series (1D) versus images (2D)?
Thanks! - Susan
From: David Young on
This isn't really a question of whether you are using 1D or 2D filters. If the filter has negative values in it, then you may get negative values in the output, especially near edges, whether the filter is applied as two 1D filters or as their 2D combination.

What you do with the output depends what you want your filter to do, and why it has those negative values in the first place. If you are trying to get a sharp cutoff of high spatial frequencies by approximating a sinc function, some "ringing" (the ripples you see, and the excursions into negative values) is inevitable, and is a direct result of sharply cutting off the top part of the spectrum. If you just want to smooth the image, you are probably better off using an all-positive smooth filter such as a truncated Gaussian.