Jump to content

Gabor filter alpha 2


zarathoustra
 Share

Recommended Posts

I made a new version of the filter.

I think you'll notice it's much faster.

It was O(n^2) with n = pixel number (w*h).

Now it's O(n*m) with m= number of values in the kernel, ie. (wavelength * (quality+1))^2

It's not feature complete, and things like RGB support is not implemented (it'll leave the img as is).

PS: It's annoying PDN has only RGBA.

Gabor.zip

Link to comment
Share on other sites

:roll: Yes, it's so incredibly annoying. Jeez.

In my case yes, because, my filter isn't so fast, and it's much more work to do rgb 24bits than doing 1bit per pixel.

So i have to ask the user about the input...

Maybe "annoying" isn't the right word.

And if you mean 99% of your user use only 24bits per pixel, i agree with you.

I ment that from a technical point of view, for that particular filter.

Edit: if i want things correct, i have to do it for all 3 channels, ie. 3 more times to preview and render.

(I planned a different quality for preview and render for that purpose,

the quality affects the kernel size, so the smaller the more approximated result, but quality >= 1 seems enough for preview.)

Also now, it uses smaller kernels, but still, it can reach 600x600 kernels, and they can make sense for high resolution pictures...

Link to comment
Share on other sites

This is a great improvement over the last one! A couple of performance notes... Is the filter kernel separable? You might be able to get it down to O(sqrt(n*m)). I recall reading in several places that it can be separated, but perhaps this only applies to the sine and cosine filters. Also, you should probably memoize the kernel...

Thanks for improving this and publishing it here. I'm hoping to add stuff to Segment Image that takes advantage of texture information, and this will be helpful. I assume that reversing and adapting it is OK?

Segment Image : Average Color (HSL) : Eigen Blur : []

Cool, new forum!

Link to comment
Share on other sites

Is the filter kernel separable?

No.

Well, yes, but only for horizontal, vertical, and 45 degree filters. [1]

Also, you should probably memoize the kernel...

It's already done.

class GaborFilterKernel is the real math, and it computes the value for whatever input.

class GaborFilterKernelWithEnvelope uses an envelope and stores the vales in a matrix at contruction.

(The values are computed with GaborFilterKernel).

I assume that reversing and adapting it is OK?

Yes, it's under "feel free to rip it" license.

I can give the piece of code if you want.

Also [1] has other techniques for improving perfs:

1) in the spatial domain: downscaling the input and the kernel by a factor, they explain how to compute the factor such that you don't loose much. (Nyquist related tuffs).

2) using FFT (running in O(n log n)) to apply the transform in the frequency domain.

-----

[1] Fast extraction of multi resolution Gabor-features, Ilonen, 2007

Link to comment
Share on other sites

Whoops! You're correct about the memoization, of course. I should have checked the GaborFilterKernelWithEnvelope class before posting. Sorry about that.

Thanks for the paper reference. I don't think I'll be reading it though, $19 for 6 pages is pretty steep. Are you aware of any literature that discusses applying the horizontally (or vertically, or diagonally) oriented filter to a resampled version of a rotated image? That would seem to be an easy way to take advantage of separability. The resampling might attenuate high frequencies or introduce other artifacts, however. I performed a quick test with bilinear resampling and a 15 degree rotation. Artifacts were quite apparent at wavelength = 2, but I was unable to distinguish the two results at wavelength = 8. Maybe the results at short wavelengths would be better if a superior resampling method were used.

This is conflated with another issue, though. At wavelengths under sqrt(2), since you're sampling only one point for each cell of the filter, the filter itself is aliased for some orientations. In cases where it's not aliased, the sampling may still produce an inaccurate estimate of the integral of the kernel function over the cell, because the curvature can become fairly strong in the direction of the sinusoid near the peaks and troughs. You can obtain a more accurate estimate of the integral by oversampling.

Hope this helps! Thanks again for releasing this update.

Segment Image : Average Color (HSL) : Eigen Blur : []

Cool, new forum!

Link to comment
Share on other sites

Thanks for the paper reference. I don't think I'll be reading it though, $19 for 6 pages is pretty steep.

It's the content that matters, there are excellent 3 pages papers. :)

Also, if you know someone in univerisity, he can probably get it for you.

Are you aware of any literature that discusses applying the horizontally (or vertically, or diagonally) oriented filter to a resampled version of a rotated image? That would seem to be an easy way to take advantage of separability. The resampling might attenuate high frequencies or introduce other artifacts, however. I performed a quick test with bilinear resampling and a 15 degree rotation. Artifacts were quite apparent at wavelength = 2, but I was unable to distinguish the two results at wavelength = 8. Maybe the results at short wavelengths would be better if a superior resampling method were used.

There are 2 things here (both noted in the paper i mentioned):

1) rotating back and forth to take advantage of the separability of the filter at a given angle.

They say it's computationally expensive and don't discuss it anymore.

2) downsampling.

This point is discussed more seriously, it's one of the 2 points they advice for fast extraction in the spatial domain.

I haven't got into this one, but the big picture is:

3.2.3 The highest necessary frequency

...

The frequency above f_high can be discarded. These high frequencies can be removed by the following signal downscaling

a_sf = 0.5/f_high where 0.5 is the Nyquist frequency. After downscaling the filter frequency f must be adjusted.

The only negative effect is the responses are computed more sparsely. Loss of resolution does not matter in practice as the responses do not change rapidly when the spatial location of the filter is slightly changed.

... (an example where this is not true) ...

... (some math for solving f_high) ...

This is conflated with another issue, though. At wavelengths under sqrt(2), since you're sampling only one point for each cell of the filter, the filter itself is aliased for some orientations. In cases where it's not aliased, the sampling may still produce an inaccurate estimate of the integral of the kernel function over the cell, because the curvature can become fairly strong in the direction of the sinusoid near the peaks and troughs. You can obtain a more accurate estimate of the integral by oversampling.

Who needs a wavelength < 2 ?

Link to comment
Share on other sites

my brain hurts from all the too smart for me talk. What does this plugin do? i am not a programmer so i understand -100% of what you guys are talking about.

Can i see some sample pictures or something?

 

"Clearly it's a very serious and literal meaning. If you're not solving physics equations then get off my lawn!-Rick Brewster Paint.net Lead Developer"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...