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 
Return to the default flat view Create a new topic Submit Reply
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 ________\/|________
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`--------\--------'~ ~~~~~~~~~~~~~~~~~~~~
\
[Message index]
 
Read Message
Read Message
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: Thu Oct 09 23:07:28 PDT 2025

Total time taken to generate the page: 0.48099 seconds