[Top][All Lists]

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

Re: beginner: function definition confusion

From: Geordie McBain
Subject: Re: beginner: function definition confusion
Date: Fri, 22 Apr 2005 12:09:32 +1000
User-agent: Debian Thunderbird 1.0.2 (X11/20050331)

I don't know much about digital image processing, but I think I can get this going. First, the function name passed to nlfilter should be quoted; i.e. nlfilter (img, [3,3], "avg"). Also, in octave-forge there's a function mean2 you can use which does the same thing as avg.m; as it avoids for-loops it might be quicker. Third, you might want to restructure T1 a bit to return blur instead of writing it to the standard output. I put this together as

   function blur = T2 (pngf)
     img = imread("black-white.png");
     blur = nlfilter(img,[3,3],"mean2");

which I call like

   octave> b = T2 ("black-white.png");
   octave> imshow (b);

Hope this helps.

Geordie McBain

Jeff Abrahamson wrote:

I'm confused trying to use nlfilter.  (The ultimate goal is to do
convolutions on images.)  I'm not sure if I'm misunderstanding
nlfilter or if I'm even maybe just defining the function avg
incorrectly.  Here's what I wrote

   function T1 ( )
     img = imread("black-white.png");
     blur = nlfilter(img,[3,3],avg)

   function ret = avg ( blk )
     ret = 0;
     for i = 1:3
        for j = 1:3
          ret += blk(i,j);
     ret /= 9;


The error is this:
 octave:1> T1()
 error: `blk' undefined near line 22 column 14
 error: evaluating assignment expression near line 22, column 11
 error: evaluating for command near line 21, column 5
 error: evaluating for command near line 20, column 3

Anyone see what I'm doing wrong?

Note, by contrast, that avg works in the form I thought I needed it

 octave:1> m=rand(3)
 m =

   0.30486  0.74804  0.28817
   0.54096  0.62247  0.70384
   0.67811  0.58588  0.38752

 octave:2> avg(m)
 ans = 0.53998
Thanks in advance.

Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

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