# graydist

Gray-weighted distance transform of grayscale image

## Syntax

``T = graydist(I,mask)``
``T = graydist(I,C,R)``
``T = graydist(I,ind)``
``T = graydist(___,method)``

## Description

````T = graydist(I,mask)` computes the gray-weighted distance transform of the grayscale image `I`. Locations where `mask` is `true` are seed locations.```

example

````T = graydist(I,C,R)` specifies the column and row coordinates of seed locations in vectors `C` and `R`.```
````T = graydist(I,ind)` specifies the linear indices of seed locations, `ind`.```
````T = graydist(___,method)` specifies an alternate distance metric, `method`.```

## Examples

collapse all

Create a magic square. Matrices generated by the magic function have equal row, column, and diagonal sums. The minimum path between the upper-left and lower-right corner is along the diagonal.

`A = magic(3)`
```A = 3×3 8 1 6 3 5 7 4 9 2 ```

Calculate the gray-weighted distance transform, specifying the upper left corner and the lower right corner of the square as seed locations.

```T1 = graydist(A,1,1); T2 = graydist(A,3,3);```

Sum the two transforms to find the minimum path between the seed locations. As expected, there is a constant-value minimum path along the diagonal.

`T = T1 + T2`
```T = 3×3 10 11 17 13 10 13 17 17 10 ```

## Input Arguments

collapse all

Grayscale image, specified as a numeric or logical array.

Binary mask that specifies seed locations, specified as a logical array the same size as `I`.

Column and row coordinates of seed locations, specified as a vector of positive integers. Coordinate values are valid `C`,`R` subscripts in `I`.

Indices of seed locations, specified as a vector of positive integers.

Distance metric, specified as one of these values.

Method

Description

`'chessboard'`

In 2-D, the chessboard distance between (x1,y1) and (x2,y2) is

max(│x1x2│,│y1y2│).

`'cityblock'`

In 2-D, the cityblock distance between (x1,y1) and (x2,y2) is

x1x2│ + │y1y2

`'quasi-euclidean'`

In 2-D, the quasi-Euclidean distance between (x1,y1) and (x2,y2) is

## Output Arguments

collapse all

Gray-weighted distance transform, returned as a numeric array of the same size as `I`. If the input numeric type of `I` is `double`, then the output numeric type of `T` is `double`. If the input is any other numeric type, then the output `T` is `single`.

Data Types: `single` | `double`

## Algorithms

`graydist` uses the geodesic time algorithm . The basic equation for geodesic time along a path is:

`${\tau }_{f}\left(P\right)=\frac{f\left({p}_{o}\right)}{2}+\frac{f\left({p}_{l}\right)}{2}+\sum _{i=1}^{l-1}f\left({p}_{i}\right)$`

`method` determines the chamfer weights that are assigned to the local neighborhood during outward propagation. Each pixel's contribution to the geodesic time is based on the chamfer weight in a particular direction multiplied by the pixel intensity.

 Soille, P. "Generalized geodesy via geodesic time." Pattern Recognition Letters. Vol.15, December 1994, pp. 1235–1240.
{"ft_lang_label":"__label__en","ft_lang_prob":0.7332426,"math_prob":0.9980815,"size":2663,"snap":"2023-40-2023-50","text_gpt3_token_len":716,"char_repetition_ratio":0.10605491,"word_repetition_ratio":0.04883721,"special_character_ratio":0.24671423,"punctuation_ratio":0.12252964,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9975367,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-29T19:55:16Z\",\"WARC-Record-ID\":\"<urn:uuid:443585c2-36e5-4c18-91e9-53f64456e621>\",\"Content-Length\":\"98496\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b06ed532-2dcc-4259-97c5-830886343629>\",\"WARC-Concurrent-To\":\"<urn:uuid:debb6af0-a927-42fa-9927-c784399de323>\",\"WARC-IP-Address\":\"104.100.162.78\",\"WARC-Target-URI\":\"https://ww2.mathworks.cn/help/images/ref/graydist.html\",\"WARC-Payload-Digest\":\"sha1:5DFNBCL4VPUKOSB6L53HUGOQKJM77OCE\",\"WARC-Block-Digest\":\"sha1:SQCAEOSA3BJVNIWHXZ2YYVCJAW6HVK7W\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510528.86_warc_CC-MAIN-20230929190403-20230929220403-00815.warc.gz\"}"}