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

Home » Public Forums » archive » Re: efficient kernel or masking algorithm ?
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: efficient kernel or masking algorithm ? [message #22636] Thu, 30 November 2000 00:00 Go to previous message
Struan Gray is currently offline  Struan Gray
Messages: 178
Registered: December 1995
Senior Member
J.D. Smith, jdsmith@astro.cornell.edu writes:

> If you really want the true variance, you're
> probably stuck with for loops,
> preferrably done in C and linked to IDL.

There was a thread back in August called 'Standard Deviation' where we
discussed this a bit. The best i could come up with was to use the SHIFT
function, which for a 3x3 kernal looks like this:

;********************************

function smg_imageSD, image

fimage = float(image)
localmean = smooth(fimage, 3)
sum = (fimage - localmean)^2
sum = temporary(sum) + $
shift((fimage - shift(localmean, 1, 1))^2,-1,-1)
sum = temporary(sum) + $
shift((fimage - shift(localmean, 0, 1))^2, 0,-1)
sum = temporary(sum) + $
shift((fimage - shift(localmean,-1, 1))^2, 1,-1)
sum = temporary(sum) + $
shift((fimage - shift(localmean, 1, 0))^2,-1, 0)
sum = temporary(sum) + $
shift((fimage - shift(localmean,-1, 0))^2, 1, 0)
sum = temporary(sum) + $
shift((fimage - shift(localmean, 1,-1))^2,-1, 1)
sum = temporary(sum) + $
shift((fimage - shift(localmean, 0,-1))^2, 0, 1)
sum = temporary(sum) + $
shift((fimage - shift(localmean,-1,-1))^2, 1, 1)

sum = sqrt(temporary(sum)/8)

dims = size(sum, /dim)
sum[0,*] = 0.0
sum[*,0] = 0.0
sum[dims(0)-1,*] = 0.0
sum[*,dims(1)-1] = 0.0

return, sum
end

;********************************

This handles the edges crudely, but a mixture of padding the original image
and using the right keywords when doing the initial smooth allows more complex
behaviours.

Obviously, it would be possible to generalise the shifting and final sqrt for
other kernal sizes, and to add all sorts of checking for different data types.

It's reasonably fast.


Struan
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Contours driving me mad
Next Topic: How Computers Represent Floats

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

Current Time: Sat Oct 11 03:41:28 PDT 2025

Total time taken to generate the page: 0.24073 seconds