Skip to main content
Inspiring
November 4, 2013
Question

Convolve and PF_KernelFlag_REPLICATE_BORDERS

  • November 4, 2013
  • 1 reply
  • 1749 views

I was looking at the convole function in PF_WORLDTRANSFORMSUITE1, and it is *almost* exactly what I am looking for except for the small detail of it does not replicate borders, and the Kernal Flag of PF_KernelFlag_REPLICATE_BORDERS does not seem to be implemented.

Is anyone else able to use convolve with border pixels replicated, and if so how are you achieving that result (convolve or otherwise)?  I have been messing around with manually accessing the pixel neighbors, but I would prefer to use the PF_WORLDTRANSFORMSUITE1's convolve if possible ... although my initial guess is that I will have to go about it another way ...

This topic has been closed for replies.

1 reply

Community Expert
November 4, 2013

as you said, the "replaicate borders" flag is unimplemented. so the other way is the only way.

i also needed a "repeat boarders" behaviour and had to wrtie my own function for that.

however, there are things you should consider:

if what you're doing is some sort of blur, then you have to know that convolve is the slowest possible implementation...

if you use the 2D_KERNEL flag then the render will be as slow as the gaussian blur effect was in AE 3.1 (1997)

that's because each pixel will process based in it's surrounding pixels, within the given size.

so the process time is exponentional to the size:

nunPixels * size * size

you can get a huge improvement by doing two passes one with the HORIZONTAL flag and one with the VERTICAL.

in which case the render time would be:

numPixels * size * 2

obviously faster when size > 2

want to go even faster?

don't use convolve at all. write your own custom and optimized filtering function.

for instance, blurring can be lightning fast when not reading every surrounding pixel in each row, but accumulating the sum of surrounding pixels, while with each advance adding the new pixel and ommitting the last in the row.

that way the blur size doesn't matter. you're always adding one and subtracting one.

this example shows a box blur, which can be changed into a gaussian-like blur by curving the result, or repeating the process a couple of times.

the bottom line is, if you see your plug-in is suffering for convultion size related slugginshness, you don't have to accept the verditct.

thenesAuthor
Inspiring
November 5, 2013

You are spot on about me trying to do a blur, a box blur infact truth be told.

I have been reading a lot about blur kernels (gaussian and box blur) this past weekend looking for how best to handle it.  I was suspecting it would lead to a custom blur function needing to be created but was thinking if adobe already had a function that I did not know about then I could save a little time using it

You mentioned the example showing a box blur, did you mean the description of the "reading every surrounding pixel in each row, but accumulating the sum of surrounding pixels, while with each advance adding the new pixel and ommitting the last in the row" or was there an actual code example that was not attached to the post?  Not that I am trying to be greedy of course, just wanting to make sure I did not miss something intended to be there

I do like the idea of bypassing the convolution altogether if it's going to be producing 1997ish speeds since getting it working is my number one priority and making it work faster is my other number one priority, haha

That said, where would be a good place to start looking for handling the blur in a non convolution way.  In the mean time I will start looking online for references to non convolution blurs, as thus far I have just been seeing a lot of write ups for convolution based kernels, and as well as taking a look at the 1D blurs using horizontal and vertical.

* I am starting to look at accumulators, it seems promising on a row by row operation using something like AEGP_IterateGeneric perhaps.  Which will inevitably lead into another question I will have about the rowbyte sizes when dealing with CS5/CS6/CC as from a test on the last plugin I noticed that the rowbytes coming in on CC looked strange and led to some issues as I recall.  But for now I will see if I can figure out accumulators on a row basis.

Community Expert
November 5, 2013

a quick search of google yielded nothing...

but without solving your need for "repeat edge"s, you can use:

suites.WorldSuite2()->AEGP_FastBlur()

allow me to explain, in the same manner as apple's API documentation:

"the AEGP_FastBlur function is an AEGP call the does a Fast Blur."

it's actually the same function used in AE's fast blur effect, and it's

REALLY fast.

you can solve the "repeat edges" thingie by copying your blur image into a

larger buffer, and expanding it's edge pixels before doing the blur

operation.

even though this function exists, i opted to write my own custom function

for blurring. (i was young and wild back then (4 years ago))