help-octave
[Top][All Lists]
Advanced

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

Re: computation speed and coding style


From: Stefan van der Walt
Subject: Re: computation speed and coding style
Date: Thu, 5 May 2005 12:59:06 +0200
User-agent: Mutt/1.5.6+20040907i

If you want speed (and not accuracy), you should also consider
`fftconv2' from octave-forge:

FFTCONV2 Convolve 2 dimensional signals using the FFT.

usage: fftconv2(a, b[, shape])
       fftconv2(v1, v2, a, shape)

This method is faster but less accurate for large a,b.  It
also uses more memory. A small complex component will be
introduced even if both a and b are real.


While `fftconv2' provides increased convolution speed, using the
technique described in "Numerical Recipes in C++" (Press
et. al.) will provide an even greater increase.

Regards
Stfan

On Tue, May 03, 2005 at 08:45:19PM +0200, S?ren Hauberg wrote:
> Hi Jeff
> I never used nlfilter, so I don't have any experience with that. Usualy 
> function calls are pretty slow in Octave, so I guess a function like 
> nlfilter that calls a user suplied function over and over will be slow. 
> Since you have nlfilter, I asume you have octave-forge, so you'll also 
> have conv2 (2-dimensional convolution).
> 
> Here's how I've implemented the Sobel edge detector (im is the 
> gray-scale image):
> 
> Mx = [-1, 0, 1; -2, 0, 2; -1, 0, 1];
> My = Mx';
> strength = sqrt( conv2(im, Mx, "same").^2 + ...
>                  conv2(im, My, "same").^2 );
> bw = (strength > threshold);
> 
> It's not quite what you do, but the moral is that conv2 is your friend.
> If you want a complete implemtation (with simple thinning), you can see 
> an implementation of several edge detectors I did a while back at
> http://hauberg.org/share/edge.m
> (the auxilary functions are at http://hauberg.org/share)
> 
> Hope that helps,
> S?ren
> 
> 
> Jeff Abrahamson wrote:
> >For a course I'm teaching I assigned a problem to code an edge
> >detector.  I coded my solution in octave because it was easy to code,
> >but I was appalled that it ran orders of magnitude slower than any
> >student solution, including the python and perl submissions.
> >
> >I'm wondering if I just did something really dumb in my octave coding.
> >Here's what I did:
> >
> >I call edge_detect with the name of the edge detector to use.  That
> >edge detector calls nlfilter with the appropriate convolution filter.
> >So most everything probably happens inside nlfilter.  Here's the
> >important code:
> >
> >    # smooth is the smoothed image (as an array)
> >    edge_detect( img_name, smooth, "roberts_detect")
> >
> >
> >    function edge_detect ( img_name, smooth, detector_name )
> >
> >         edges = feval(detector_name, smooth);
> >         # then output the edge-detected image "edges"
> >
> >    endfunction
> >
> >
> >    function ret = sobel_detect ( image )
> >
> >         ret = nlfilter(image, [3,3], "sobel_kernel");
> >
> >    endfunction
> >
> >
> >    function ret = sobel_kernel ( B )
> >
> >         Mx = [-1, 0, 1; -2, 0, 2; -1, 0, 1];
> >         My = Mx';
> >
> >         fx = sum((B .* Mx)(:));
> >         fy = sum((B .* My)(:));
> >
> >         magnitude = fx + fy;
> >         if(fx == 0)
> >                 ret = 0;
> >         else
> >                 dirn = atan(fy / fx);
> >                 if(magnitude > dirn)
> >                         ret = 255;
> >                 else
> >                         ret = 0;
> >                 endif
> >         endif
> >
> >    endfunction
> >
> >Thanks for any tips.
> >
> 
> 
> 
> -------------------------------------------------------------
> 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
> -------------------------------------------------------------
> 



-------------------------------------------------------------
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
-------------------------------------------------------------



reply via email to

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