[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: beginner: function definition confusion
From: |
Jeff Abrahamson |
Subject: |
Re: beginner: function definition confusion |
Date: |
Fri, 22 Apr 2005 07:36:39 -0400 |
User-agent: |
Mutt/1.5.6+20040907i |
That was it: I didn't understand that I needed to quote the function
name. Thanks!
Can anyone motivate for me why the error message would be "blk
undefined" (from inside avg) rather than "avg not found" or something?
Thanks for the pointer to mean2. In fact, I want to do a more
complicated convolution, but avg was easy to write for testing
purposes. But I'll take a look at mean2 to see how it's written.
Thanks!
-Jeff
On Fri, Apr 22, 2005 at 12:09:32PM +1000, Geordie McBain wrote:
> [81 lines, 320 words, 1896 characters] Top characters: entio\nra
>
> Jeff:
> 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");
> endfunction
>
> which I call like
>
> octave> b = T2 ("black-white.png");
> octave> imshow (b);
>
> Hope this helps.
>
> Geordie McBain
> www.aeromech.usyd.edu.au/~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)
> > endfunction
> >
> >
> > function ret = avg ( blk )
> > ret = 0;
> > for i = 1:3
> > for j = 1:3
> > ret += blk(i,j);
> > endfor
> > endfor
> > ret /= 9;
> > endfunction
> >
> > T1()
> >
> >
> >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
> >to:
> >
> > 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
> > octave:3>
> >
> >Thanks in advance.
> >
> >
> >
>
--
Jeff
Jeff Abrahamson <http://www.purple.com/jeff/> +1 215/837-2287
GPG fingerprint: 1A1A BA95 D082 A558 A276 63C6 16BF 8C4C 0D1D AE4B
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------