Re: Problem with dist function in IDL [message #55301] |
Thu, 16 August 2007 03:13  |
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   |
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   |
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 #55659 is a reply to message #55301] |
Tue, 28 August 2007 11:26  |
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.")
|
|
|