generic non-linear filtering that support selem and boundary handling

Essentially, this is something similar to scipy.ndimage.filters.generic_filter (which is too slow because of its internal python for-loop), but implemented in cython as with skimage.filter.rank family. Given the diversity within skimage.filter.rank, a generic function would be very useful. For example, I'd like to calculate local variance, which is conceptually similar to skimage.filter.rank.mean, but not supported currently. I guess the absence of such a function must be due to some unresolved technical obstacle? Thanks~ Chencan

Hi Chencan, On Mon, May 26, 2014 at 8:50 AM, Chencan QIAN <qianchencan@gmail.com> wrote:
I guess the absence of such a function must be due to some unresolved technical obstacle?
The main obstacle is: how would you specify such a filter? If you provide it as a function call, then we have to go through Python (not Cython), which slows things down back to the speed that ndimage's generic filter would give you. Regards Stéfan

Funny you should request this. I built a Cython framework do exactly what you want (arbitrary selem, boundary handling [padding], and even arbitrary weighting of the selem in 2D and 3D) for local *weighted *variance. The framework is about as useful as the actual calculation. Replace the innermost loop, change the name, and you get an entirely different non-linear weighted local feature. This requires a somewhat skilled user, but the framework is already done so it isn't as hard as it sounds. Trouble is, I used some features from cython.parallel so those would have to be stripped out, losing over an order of magnitude in speed. I've been kicking around submitting them, but going back and ripping out the parallel features is painful. If interested I can clean up and put them in a Gist or two. Josh On Monday, May 26, 2014 1:50:10 AM UTC-5, Chencan QIAN wrote:
Essentially, this is something similar to scipy.ndimage.filters.generic_filter (which is too slow because of its internal python for-loop), but implemented in cython as with skimage.filter.rank family.
Given the diversity within skimage.filter.rank, a generic function would be very useful. For example, I'd like to calculate local variance, which is conceptually similar to skimage.filter.rank.mean, but not supported currently.
I guess the absence of such a function must be due to some unresolved technical obstacle?
Thanks~
Chencan

Josh, why the parallel stripping out? Is it a Cython version requirement? We can always have this as a "dormant" PR for 1.0, for which we might bump up the version required. It might also be possible to wrap the import around a try-catch clause so that it fails gracefully on an earlier Cython version. Juan. On Tue, May 27, 2014 at 1:07 PM, Josh Warner <silvertrumpet999@gmail.com>wrote:
Funny you should request this. I built a Cython framework do exactly what you want (arbitrary selem, boundary handling [padding], and even arbitrary weighting of the selem in 2D and 3D) for local *weighted *variance.
The framework is about as useful as the actual calculation. Replace the innermost loop, change the name, and you get an entirely different non-linear weighted local feature. This requires a somewhat skilled user, but the framework is already done so it isn't as hard as it sounds.
Trouble is, I used some features from cython.parallel so those would have to be stripped out, losing over an order of magnitude in speed. I've been kicking around submitting them, but going back and ripping out the parallel features is painful.
If interested I can clean up and put them in a Gist or two.
Josh
On Monday, May 26, 2014 1:50:10 AM UTC-5, Chencan QIAN wrote:
Essentially, this is something similar to scipy.ndimage.filters.generic_filter (which is too slow because of its internal python for-loop), but implemented in cython as with skimage.filter.rank family.
Given the diversity within skimage.filter.rank, a generic function would be very useful. For example, I'd like to calculate local variance, which is conceptually similar to skimage.filter.rank.mean, but not supported currently.
I guess the absence of such a function must be due to some unresolved technical obstacle?
Thanks~
Chencan
-- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.

Hi Josh, Your framework sounds really interesting! In my opinion, it would be great to keep the current implementation (with cython.parallel) for the routine that calculates local weighted variance, while at the same time, expose a general purpose interface that accepts arbitrary python function (provided it still offers some performance gain compared with ndimage.filters.generic_filter. Will this be the case?). On Tuesday, May 27, 2014 11:07:43 AM UTC+8, Josh Warner wrote:
Funny you should request this. I built a Cython framework do exactly what you want (arbitrary selem, boundary handling [padding], and even arbitrary weighting of the selem in 2D and 3D) for local *weighted *variance.
The framework is about as useful as the actual calculation. Replace the innermost loop, change the name, and you get an entirely different non-linear weighted local feature. This requires a somewhat skilled user, but the framework is already done so it isn't as hard as it sounds.
Trouble is, I used some features from cython.parallel so those would have to be stripped out, losing over an order of magnitude in speed. I've been kicking around submitting them, but going back and ripping out the parallel features is painful.
If interested I can clean up and put them in a Gist or two.
Josh
On Monday, May 26, 2014 1:50:10 AM UTC-5, Chencan QIAN wrote:
Essentially, this is something similar to scipy.ndimage.filters.generic_filter (which is too slow because of its internal python for-loop), but implemented in cython as with skimage.filter.rank family.
Given the diversity within skimage.filter.rank, a generic function would be very useful. For example, I'd like to calculate local variance, which is conceptually similar to skimage.filter.rank.mean, but not supported currently.
I guess the absence of such a function must be due to some unresolved technical obstacle?
Thanks~
Chencan
participants (4)
-
Chencan QIAN
-
Josh Warner
-
Juan Nunez-Iglesias
-
Stéfan van der Walt