3 point Z filter in Import3d

Anything that doesn't fit elsewhere.
Post Reply
darrenmyatt

3 point Z filter in Import3d

Post by darrenmyatt »

Hello :)

Does anyone know offhand how the Z filtering process in the import3d tool works - is it simply a uniform moving average e.g.

z_i = 1/3*(z_{i-1} + z_i + z_{i+1})

or is it weighted differently?

Thanks in advance
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

How to figure out how the GUI's tools work

Post by ted »

Almost all of the GUI tools are implemented in hoc (the Print & File Window Manager is an
exception, perhaps the only exception), and you get all of that hoc code when you install
NEURON--it's in
nrn/share/nrn/lib/hoc for UNIX/Linux/OS X
and
c:\nrnxx\lib\hoc for MSWin.
So any time you want to discover how things work, just examine the appropriate file.

"How do I figure out what file to look in?"
The files have suggestive names. Alternatively, if there is a particular variable or procedure
that you want to find, you can do a text search with grep or some other tool (hint to MSWin
users: grep.exe is located in c:\nrnxx\bin !).

"How does z axis filtering work in the import3d tool?"
c:\nrnxx\lib\hoc contains import3d.hoc
This just xopens a bunch of hoc files in
c:\nrnxx\lib\hoc/import3d
I wanted to find the code that makes the xpanel that includes the string
3 point filter
because this would tell me what happens when one clicks on that checkbox.
So this file
import3d_gui.hoc
seemed most promising.

Bingo! Opening that file in a text editor and searching for
filter
found this line of code
xcheckbox("3 point filter of all z values (no undo)", &dummy_, "edit3()"
which tells me that the filiter is probably implemented by proc edit3().

Sure enough, in that very same file there is a proc edit3(), and that proc contains this
block of code:

Code: Select all

        for i=0, swc.sections.count-1 {
                sec = swc.sections.object(i)
                sec.raw.setrow(2, sec.raw.getrow(2).medfltr)
        }
So is medfltr just the Vector class's medfltr (median filter), or is it something else? If the
latter, there would have to be a proc medfltr() somewhere. So search all fhe files in
c:\nrnxx\lib\hoc
for occurrences of medfltr and . . . lucky us, medfltr appears only once, and we don't
have to try to decipher what some proc medfltr() does. It's almost certainly just the
Vector class's medfltr.

How could we confirm this hypothesis? This
sec.raw.setrow(2, sec.raw.getrow(2).medfltr)
suggests that sec.raw is a Matrix. We could verify this by reading our way through the
code that sets up the swc object, or we could be smart and change the above cited
for loop to

Code: Select all

        for i=0, swc.sections.count-1 {
                sec = swc.sections.object(i)
                sec.raw.setrow(2, sec.raw.getrow(2).medfltr)
if (i==0) print sec.raw // diagnostic test
        }
Then when we click on the z filter checkbox, the name of the object class of which
sec.raw is an instance will be printed in NEURON's xterm. If we discover that sec.raw
is a Matrix, the z axis filter is just a median filter.

As the authors of one of my favorite math books would say,
"This is left to the reader as an exercise."
darrenmyatt

Post by darrenmyatt »

Thanks for the help, Ted :)

I suspected that it would be possible to find the info somewhere within the Neuron code, but as a non-user of Neuron I figured it would take an age to locate it.

Ah, I had assumed incorrectly that it was a moving average rather than median filter. That seems to indicate that the main reason for the use of the filter is one of noise reduction rather than an attempt at interpolation.

In case you're wondering, the reason I asked was just because I am currently investigating different methods for interpolating Z values in reconstructions and wanted to include the one used by Neuron for comparison.
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Post by ted »

If moving average turns out to be advantageous, it could be added. Of course, now that
you see where the source code is, there's no reason why you or somebody else couldn't
add it to their own copy of NEURON.
Post Reply