Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
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
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
> > 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
> 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
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
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.")