Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rotate filter kernel (convolution)

562 views
Skip to first unread message

Jörg Kugler

unread,
Sep 8, 2009, 9:48:12 AM9/8/09
to
Hi there,

I have an application where I have to find straight lines in an image.
Previously, the lines were pretty horizontally so I was using a simple
5x5 convolution filter like:

-1 -1 -1 -1 -1
0 0 0 0 0
1 1 1 1 1
0 0 0 0 0
-1 -1 -1 -1 -1

How do I rotate this kernel by a random angle, let's say 20deg so it
highlights lines at a 20deg angle in my image? The resulting kernel
should still be 5x5. Rotating the whole image is too time-consuming.

This is my first image processing project, and I can't quite get my
head around this.

Thanks for any help,
Joerg.

Jonathan Campbell

unread,
Sep 8, 2009, 10:19:23 AM9/8/09
to

I hope others come in with greater expertise.

1. I think it is going to be difficult to compute a kernel for an
arbitrary angle.

2. Can you tolerate computing a general edge image, e.g. Sobel (combine
Sobel horizontal and S. vertical) and then detecting lines in that.

Even though they compute horizontal and vertical, the combination gives
a good enhancement of lines of arbitrary orientation.

3. I'm not sure how your kernel above would perform as a general edge
detector, i.e. by combining the horizontal edge image with a vertical
one. If you search on <kernels edge> or look in a book like Pratt,
Digital Image Processing, you may come up with alternative 5 x 5 kernels.

Best regards,

Jon C.

--
Jonathan Campbell www.jgcampbell.com BT48, UK.

Jörg Kugler

unread,
Sep 8, 2009, 10:34:12 AM9/8/09
to
On Sep 8, 10:19 pm, Jonathan Campbell <jg.campbell...@gmail.com>
wrote:

> 2. Can you tolerate computing a general edge image, e.g. Sobel (combine
> Sobel horizontal and S. vertical) and then detecting lines in that.
>
> Even though they compute horizontal and vertical, the combination gives
> a good enhancement of lines of arbitrary orientation.

I am pretty new to image processing I must say.
I have read about Sobel kernels, but I am not sure how I would have to
combine them to highlight lines of random orientation. Maybe you can
give me a pointer there as well.

Sorry for the newbie questions.

Thanks,
Joerg.

Jonathan Campbell

unread,
Sep 8, 2009, 10:43:39 AM9/8/09
to

The best I can suggest is section 4.16 of:

http://www.jgcampbell.com/ip/ip4.txt

though there are likely many better coverages on the web. Just google
<sobel edge detector>.

E.g. http://homepages.inf.ed.ac.uk/rbf/HIPR2/sobel.htm

Are you using an image processing system? Or a programming language?

Jörg Kugler

unread,
Sep 8, 2009, 10:56:43 AM9/8/09
to
Thanks again for your prompt reply and the pointers.
I think I just understood what Sobel vectors are supposed to do - you
learn something new every day ;-).

I am not using a particular image processing system. Just plain C++ on
8bit mono images.

Thanks again,
Joerg.

Nicolas Bonneel

unread,
Sep 8, 2009, 10:51:41 AM9/8/09
to
J�rg Kugler a �crit :

you can use Gabor filter which provide any rotation you want.


--
Nicolas Bonneel
http://www-sop.inria.fr/reves/Nicolas.Bonneel/

aruzinsky

unread,
Sep 8, 2009, 11:30:56 AM9/8/09
to

Are you applying that as a 5x5 kernel? I ask because your kernel is
separable as

[ 1 1 1 1 1][ -1 0 1 0 -1]T

and takes 4 additions and 2 subtractions per pixel whereas convolution
with your 5x5 kernel takes 14 additions. To determine the kernel,
pad it with surrounding zeroes and rotate it as an image. Using a
bilinear interpolation kernel, the support of the resulting kernel
will be 7x7, for bicubic, 9x9, and for Lanczos3, 11x11.

Rotating 20 deg, using a Lanczos3 kernel, I get this:

http://www.general-cathexis.com/images/RotatedKernel.png

There are methods of finding the best fit of a 5x5 to a larger kernel,
but I am no expert on that.


Jonathan Campbell

unread,
Sep 8, 2009, 11:51:17 AM9/8/09
to

Alarm bells ring, but maybe I'm misjudging!

1. If you are using a plain 2D C++ array to hold an image, then I can
imagine that you are always doing two things in you program: developing
an image processing system, developing the specific algorithm, e.g. line
detection.

What you really need is a C++ class or general abstract data type / API,
that holds an image data structure, and has operations (functions) like:
input, output / display (simply outputting to some standard image format
is easier than writing a display), convolve(imageIn, imageOut,
kernelImage), etc.

2. Be very careful on doing arithmetic on 8 bit (unsigned char) images;
better to copy them to float or double and then, finally, when
outputting (if that is necessary) transforming them to [0..255].

There are maybe simple image APIs available, but most of them I find far
to complex with operator overloading and unnecessary complications.

Martin Leese

unread,
Sep 9, 2009, 9:54:46 AM9/9/09
to
Jonathan Campbell wrote:
> J�rg Kugler wrote:
...

>> I am not using a particular image processing system. Just plain C++ on
>> 8bit mono images.
>
> Alarm bells ring, but maybe I'm misjudging!
>
> 1. If you are using a plain 2D C++ array to hold an image, then I can
> imagine that you are always doing two things in you program: developing
> an image processing system, developing the specific algorithm, e.g. line
> detection.
>
> What you really need is a C++ class or general abstract data type / API,
> that holds an image data structure, and has operations (functions) like:
> input, output / display (simply outputting to some standard image format
> is easier than writing a display), convolve(imageIn, imageOut,
> kernelImage), etc.
>
> 2. Be very careful on doing arithmetic on 8 bit (unsigned char) images;
> better to copy them to float or double and then, finally, when
> outputting (if that is necessary) transforming them to [0..255].
>
> There are maybe simple image APIs available, but most of them I find far
> to complex with operator overloading and unnecessary complications.

3. If your images are large then you can
loose control of memory usage. New
instances of a class will allocate a large
chunk of memory, and "new"s can happen
inside a class where you can't see them.

--
Regards,
Martin Leese
E-mail: ple...@see.Web.for.e-mail.INVALID
Web: http://members.tripod.com/martin_leese/

ImageAnalyst

unread,
Sep 9, 2009, 9:45:51 PM9/9/09
to

--------------------------------------------------------------------------------------------
This will find straight lines -- and curved lines and every other kind
of edge or ridge. An edge at 20 degrees will still be an edge if you
look along the columns or along the rows - no need to rotate unless
you want to find only those edges at exactly 20 degrees. Have you
considered the Hough transform to find lines? This is one common line-
finding method.
And by the way, rotating a whole image doesn't take too much time
unless you're trying to do it at video rates. I tried a medium sized
image in MATLAB and it took 0.26 seconds.

-G-

unread,
Sep 11, 2009, 3:19:39 PM9/11/09
to
On Sep 8, 9:48 am, Jörg Kugler <joergkug...@gmail.com> wrote:
> How do I rotate this kernel by a random angle, let's say 20deg so it
> highlights lines at a 20deg angle in my image? The resulting kernel
> should still be 5x5. Rotating the whole image is too time-consuming.

What you want to do is described in:
Chaudhuri et al. Detection of blood vessels in retinal images using two-
dimensional matched filters. IEEE Trans Medical Imaging 1989, 8(3):263-269.

http://www.cs.rpi.edu/research/groups/vision/ken/00034715.pdf

-G-

Filip Rooms

unread,
Sep 16, 2009, 1:34:43 PM9/16/09
to
On 11 sep, 21:19, -G- <-...@goSpamYourself.com> wrote:
> On Sep 8, 9:48 am, Jörg Kugler <joergkug...@gmail.com> wrote:
>
> > How do I rotate this kernel by a random angle, let's say 20deg so it
> > highlights lines at a 20deg angle in my image? The resulting kernel
> > should still be 5x5. Rotating the whole image is too time-consuming.

I think steerable filters are handy in this respect: just check out

W. T. Freeman and E. H. Adelson, "The design and use of steerable
filters", IEEE Trans. Pattern Analysis and Machine Intelligence, vol.
13, no. 9, pp. 891--906, 1991.

PDF available online (just Google it).

There, (separable) filters are described that can be interpolated for
any angle. You just convolve the image with a set of basis filters
once, and then you can just interpolate any angle from the responses
of thos images... Also, the taps of several filters are given in the
paper, so it's straightforward to implement.

Kind regards,

Filip


0 new messages