comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Gradient of an Image in IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Gradient of an Image in IDL [message #9118] Tue, 03 June 1997 00:00 Go to next message
David Foster is currently offline  David Foster
Messages: 341
Registered: January 1996
Senior Member
Brad Cadle wrote:
>
> HI all,
> I was wondering if someone knows of an optimized IDL routine to
> compute the gradient of an image, I ported one over from C where the
> gradient is generated in fourier space, but I was interested to find
> if one was optimized for IDL.

One alternative is to use CALL_EXTERNAL() to interface to your (already
optimized) C routine, which would require slight modifications to the
routine. I can mail you examples of using this method if you're
interested.

Dave
--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2200
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~

"I have this theory that if we're told we're bad,
then that's the only idea we'll ever have.
But maybe if we are surrounded in beauty,
someday we will become what we see." - Jewel Kilcher
Re: Gradient of an Image in IDL [message #9228 is a reply to message #9118] Thu, 05 June 1997 00:00 Go to previous message
Hermann Mannstein is currently offline  Hermann Mannstein
Messages: 22
Registered: September 1995
Junior Member
David Foster wrote:
>
> Brad Cadle wrote:
>>
>> HI all,
>> I was wondering if someone knows of an optimized IDL routine to
>> compute the gradient of an image, I ported one over from C where the
>> gradient is generated in fourier space, but I was interested to find
>> if one was optimized for IDL.
>
> One alternative is to use CALL_EXTERNAL() to interface to your (already
> optimized) C routine, which would require slight modifications to the
> routine. I can mail you examples of using this method if you're
> interested.
>
> Dave

I'm not shure that it is really optimized, and there are different ways
to
define the gradient, but the following works on 2-d images and gives a
centered
absolute value and the angle in degree - i.e. it uses all surrounding
pixels.
The convolution with an 3X3 array is quite fast.

function sin_kern0
a=[ [
0.7071067812,1.,0.7071067812],[0.,0.,0.],[-0.7071067812,-1., -0.7071067812]
]
return,a
end

function cos_kern0
a = [
[-0.7071067812,0.,0.7071067812],[-1.,0.,1.],[-0.7071067812,0 .,0.7071067812]
]
return,a
end

pro gradient,input,gradient,ang
r2deg = -90./!pi

cu = float(input)
a = sin_kern0()
s = convol(cu,a)
a = cos_kern0()
c = convol(cu,a)
gradient= sqrt(s*s + c*c)
ang = atan(s,c) * r2deg
return
end


--
Regards,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
Hermann Mannstein Tel.: +49 8153 28-2503
Institut fuer Physik der Atmosphaere or -2558
DLR - Oberpfaffenhofen Fax.: +49 8153 28-1841
Postfach 1116 \ mailto:H.Mannstein@dlr.de
D-82230 Wessling \ 0 http://www.op.dlr.de/~pa64
Germany ________\/|________
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`--------\--------'~ ~~~~~~~~~~~~~~~~~~~~
\
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: tvrd failure on v5 on win95
Next Topic: MAP_SET error: linux

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:09:43 PDT 2025

Total time taken to generate the page: 0.00444 seconds