[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Vectorized version of nlfilter

From: Tony Richardson
Subject: Re: Vectorized version of nlfilter
Date: Sat, 18 Jul 2020 13:31:41 -0500

OK.  I've cleaned up my alternate version of colfilt a bit.  It allows for neighborhood processing of only selected pixels instead of all pixels.  Neighbors can be specified by row and column offsets instead of using all neighbors in a rectangular region.  (This can result in less memory usage than colfilt if only a few neighbors of a percentage of the pixels in an image are to be processed.)  I would guess that it could be faster too (although probably not significantly so), but I haven't tried to measure that.


On Sat, Jul 18, 2020 at 12:01 PM Tony Richardson <> wrote:
Well it looks as if my nlfilter2 is essentially the same as colfilt (and is not any faster).  I should have read the nlfilter documentation (which points the user to colfilt) more carefully.  

I haven't found an equivalent for my more general function that allows you to process only selected pixels and allows you to select neighbors by their row and column offsets (instead of  using a rectangular region).  I believe it is a generalization of colfilt.  I'll clean it up a bit and post it here in case anyone is interested.



On Sat, Jul 18, 2020 at 3:19 AM Nicklas SB Karlsson <> wrote:
> I've been working on a vectorized version of nlfilter (which can be used
> for non-linear filtering of pixel neighborhoods).  My version is attached
> (along with a driver).  Depending on the type of processing I've found it
> to be 10 - 1000 times faster than nlfilter.  It gets the speed boost at the
> cost of using more memory.  It is not completely compatible with nlfilter.
> The processing function is different.  For processing an image/matrix with
> P elements over an (m x n) neighborhood, the nlfilter function must accept
> an argument of size (m x n).  The function is called P times by nlfilter.
> The processing function used by nlfilter2 must accept an argument with (m x
> n) rows and P columns.  It is only called once.  Each column is a
> neighborhood of a pixel in left-to-right, top-to-bottom order.

Faster algorithm must always be appreciated, we must be grateful for the work.

Guess it could be added to ordinary nlfilter(...) function, either as a special case which is used automatically then input allow or an extra option to chose algorithm. Or?

> It is not as robust or general as nlfilter, but I expect it can be made
> so.  I have a different version of this function which allows you to
> perform neighborhood processing only over selected pixels (selected by a
> logical index matrix).  It also allows for other types of padding (both
> nlfilter and nlfilter2 only use zero-padding).  Let me know if you are
> interested.  It is currently even in rougher form than nlfilter2 though.

I can't add files to the official repository.

> Anyway, I hope someone finds this useful.  I'd appreciate (constructive)
> feedback.
> Tony

Attachment: col2_test.m
Description: Binary data

Attachment: colfilt2.m
Description: Binary data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]