Dist function details

Source: Internet
Author: User

1. The Dist function algorithm is as follows (obviously, the essence of this algorithm is the commonly known Euclidean Distance Algorithm)

R (I, j) = SQRT (f (I) ^ 2 + g (j) ^ 2) where:

F (I) = I if 0 <= I <= n/2

= N-I if I> n/2

G (I) = I if 0 <= I <= m/2

= M-I if I> M/2

Illustration: tvscl, dist (200)

Extended: surface, dist (20),/save

IDL implementation source code:

; $Id: //depot/Release/ENVI51_IDL83/idl/idldir/lib/dist.pro#1 $;; Copyright (c) 1982-2013, Exelis Visual Information Solutions, Inc. All;       rights reserved. Unauthorized reproduction is prohibited.;;+; NAME:;    DIST;; PURPOSE:;    Create a rectangular array in which each element is proportional;    to its frequency.  This array may be used for a variety;    of purposes, including frequency-domain filtering and;    making pretty pictures.;; CATEGORY:;    Signal Processing.;; CALLING SEQUENCE:;    Result = DIST(N [, M]);; INPUTS:;    N = number of columns in result.;    M = number of rows in result.  If omitted, N is used to return;        a square array.;; OUTPUTS:;    Returns an (N,M) floating array in which:;;    R(i,j) = SQRT(F(i)^2 + G(j)^2)   where:;         F(i) = i  IF 0 <= i <= n/2;              = n-i  IF i > n/2;         G(i) = i  IF 0 <= i <= m/2;              = m-i  IF i > m/2;; SIDE EFFECTS:;    None.;; RESTRICTIONS:;    None.;; PROCEDURE:;    Straightforward.  The computation is done a row at a time.;; MODIFICATION HISTORY:;    Very Old.;     SMR, March 27, 1991 - Added the NOZERO keyword to increase efficiency.;                (Recomended by Wayne Landsman);    DMS, July, 1992.  - Added M parameter to make non-square arrays.;   CT, RSI, March 2000: Changed i^2 to i^2. to avoid overflow.;-function dist,n,m  ;Return a rectangular array in which each pixel = euclidian        ;distance from the origin.compile_opt idl2on_error,2              ;Return to caller if an error occursn1 = n[0]m1 = (n_elements(m) le 0) ? n1 : m[0]x=findgen(n1)        ;Make a rowx = (x < (n1-x)) ^ 2    ;column squaresa = FLTARR(n1,m1,/NOZERO)    ;Make arrayfor i=0L, m1/2 do begin    ;Row loop    y = sqrt(x + i^2.) ;Euclidian distance    a[0,i] = y    ;Insert the row    if i ne 0 then a[0, m1-i] = y ;Symmetricalendforreturn,aend

2. Usage:

Dist (20, 20) generates an array of 20 × 20. When you enter dist (20), both the row and column are 20 by default.

3. Explanation of IDL help:

Dist

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.

This routine is written in the IDL Language. Its source code can be found in the file Dist. Pro In the Lib subdirectory of The IDL distribution.

Examples

; Display the results of DIST as an image:
Tvscl, dist (100)

Syntax

Result = dist (N [, m])

Return Value

Returns a rectangular array in which the value of each element is proportional to its frequency.

Argumentsn

The number of columns in the resulting array.

M

The number of rows in the resulting array. If M is omitted, the resulting array will be n by N.

Keywords

None.

 

 

 

Dist function details

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.