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

Home » Public Forums » archive » Re: Problem with dist function 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: Problem with dist function in IDL [message #55301] Thu, 16 August 2007 03:13 Go to next message
Paolo Grigis is currently offline  Paolo Grigis
Messages: 171
Registered: December 2003
Senior Member
Gianguido Cianci wrote:
>> A graphical representation is also always useful...
>>
>> loadct,5
>> tvscl,shift(dist(512,512),256,256)
>>
>> Ciao,
>> Paolo
>
>
> Useful, but not sufficient in my case :-(
> In the case of dist(4,1), say, how do you get the values 0.00, 1.00,
> 2.00, 1.00 ?
>
> Never quite got it! :-(
>
> G
>

This program (not optimized) reproduces the functionality of DIST:

---------------------

n=4
m=5

a=dist(n,m)
b=fltarr(n,m)

FOR i=0L,n-1 DO BEGIN
FOR j=0L,m-1 DO BEGIN
i2=min([i,n-i])
j2=min([j,m-j])
b[i,j]=sqrt(i2^2+j2^2)
ENDFOR
ENDFOR


------------------

So dist[i,j] is the shortest distance from the euclidean
point with coordinates (i,j) to one of the points (0,0),
(0,m), (n,0) or (n,m).

Ciao,
Paolo
Re: Problem with dist function in IDL [message #55305 is a reply to message #55301] Wed, 15 August 2007 17:34 Go to previous messageGo to next message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
> Useful, but not sufficient in my case :-(
> In the case of dist(4,1), say, how do you get the values 0.00, 1.00,
> 2.00, 1.00 ?
>
> Never quite got it! :-(
>
> G

Here is a graphical explanation of Mike's answer:

so, let's create an empty row of size 4

[a,b,c,d]

then we want to compute the distance from the top left corner to every
other cell, what the "dist" function does. To do that, let's assume we
have an infinite array: ....,c,d,a,b,c,d,a,b, .....
Then the we can see that from A to B, there is 1 cell (pixel, unit,
whatever), from A to C there is 2 cells and from A to D we have either 1
cell (because the beginning of the array is next to the last element of
it), or 3 cells (through B and C). Dist() will return the smallest
one... so you have dist(4,1) = 0,1,2,1

Now let's make it a tad bigger:
dist(10,10)
The last entry of the array is 1.41. From the first element, one has to
jump UP one cell to get to the last row, and LEFT one cell to get to the
last column... the distance is therefore 1.41

...
jean
Re: Problem with dist function in IDL [message #55308 is a reply to message #55305] Wed, 15 August 2007 16:23 Go to previous messageGo to next message
cgguido is currently offline  cgguido
Messages: 195
Registered: August 2005
Senior Member
>
> A graphical representation is also always useful...
>
> loadct,5
> tvscl,shift(dist(512,512),256,256)
>
> Ciao,
> Paolo


Useful, but not sufficient in my case :-(
In the case of dist(4,1), say, how do you get the values 0.00, 1.00,
2.00, 1.00 ?

Never quite got it! :-(

G
Re: Problem with dist function in IDL [message #55314 is a reply to message #55308] Mon, 13 August 2007 03:06 Go to previous messageGo to next message
Paolo Grigis is currently offline  Paolo Grigis
Messages: 171
Registered: December 2003
Senior Member
ATKT wrote:
> Can somebody tell what exactly dist function is doing in IDL
> e.g x=dist(2,2)
> 0.000000 1.00000
> 1.00000 1.41421
> What is the meaning of this ouput
> x=dist(4,4)
> 0.000000 1.00000 2.00000 1.00000
> 1.00000 1.41421 2.23607 1.41421
> 2.00000 2.23607 2.82843 2.23607
> 1.00000 1.41421 2.23607 1.41421
>
> I am unable to understand the out put which is being generated.
>

A graphical representation is also always useful...

loadct,5
tvscl,shift(dist(512,512),256,256)


Ciao,
Paolo
Re: Problem with dist function in IDL [message #55318 is a reply to message #55314] Sun, 12 August 2007 17:48 Go to previous messageGo to next message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On Aug 12, 8:41 am, ATKT <ankur.trigun...@gmail.com> wrote:
> Can somebody tell what exactly dist function is doing in IDL
> e.g x=dist(2,2)
> 0.000000 1.00000
> 1.00000 1.41421
> What is the meaning of this ouput
> x=dist(4,4)
> 0.000000 1.00000 2.00000 1.00000
> 1.00000 1.41421 2.23607 1.41421
> 2.00000 2.23607 2.82843 2.23607
> 1.00000 1.41421 2.23607 1.41421
>
> I am unable to understand the out put which is being generated.

The online help says this:

"The DIST function creates an array in which each array element value
is proportional to its frequency. This array may be used for a variety
of purposes, including frequency-domain filtering."

But I think about it in terms of plain Euclidean distance. Each array
element's value is the shortest distance to (0, 0) allowing for
wrapping around the edges. This has applications in creating kernels
for image processing filters (and is simple dataset for examples).

Mike
--
www.michaelgalloy.com
Re: Problem with dist function in IDL [message #55659 is a reply to message #55301] Tue, 28 August 2007 11:26 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Paolo_Grigis writes:

> This program (not optimized) reproduces the functionality of DIST:
>
> ---------------------
>
> n=4
> m=5
>
> a=dist(n,m)
> b=fltarr(n,m)
>
> FOR i=0L,n-1 DO BEGIN
> FOR j=0L,m-1 DO BEGIN
> i2=min([i,n-i])
> j2=min([j,m-j])
> b[i,j]=sqrt(i2^2+j2^2)
> ENDFOR
> ENDFOR

I was just having a look at the BUTTERWORTH filter code in the IDL
library, and I notice that the ITTVIS programmer who wrote this
function uses the double FOR loop method to create the distance
function, rather than DIST.

What do you suppose he knows that we don't!?

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: controlling widget layout
Next Topic: xyouts for iPlot?

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

Current Time: Wed Oct 08 17:11:41 PDT 2025

Total time taken to generate the page: 0.00689 seconds