How does graydist work?

8 views (last 30 days)
ILoveMATLAB
ILoveMATLAB on 4 May 2022
Answered: Pavan Sahith on 3 Nov 2023
What does each element of the gray dist transfrom mean with repect to the imputs? How is each element calculated. I think i have use case for a weighted distance transfrom, but I cant understand the function.
% Please note this is part of the example included in the MATLAB
% documentation.
A= magic(3)
A = 3×3
8 1 6
3 5 7
4 9 2
T1 = graydist(A,1,1)
T1 = 3×3
0 4.5000 8.0000
5.5000 6.5000 8.5000
9.0000 11.5000 10.0000
Prework,
  1. I double checked Digital Image Processing By Rafael Gonzalez. The book only discusses the binary distance transfrom. I understand the binary distance transform.
  2. I searched google/ youtube.
  3. I searched for the cited article but my company does not have access to it.
  4. I looked at the algorithm section. The formula has no disciption of the variables.

Answers (1)

Pavan Sahith
Pavan Sahith on 3 Nov 2023
Hello,
I understand that you want to know about the “graydist” function's output matrix.
T1 = graydist(A,1,1)
The `graydist` function in MATLAB calculates the grayscale distance transform of an input image, where each element in the output matrix (T1) represents the grayscale distance from the corresponding pixel to a reference pixel at coordinates (1,1).
For example, the element T1(1,1) represents the grayscale distance from the pixel at (1,1) in the input image to itself (the reference pixel). Since it's the same pixel, the distance is 0.
The element T1(2,2) represents the grayscale distance from the pixel at (2,2) in the input image to the reference pixel at (1,1). This distance is 4.5.
Similarly, each element in T1 represents the grayscale distance of the corresponding pixel to the reference pixel.
The equation used to calculate grayscale distance in the `graydist` function is based on the geodesic time concept. The equation of geodesic time is as follows:
my understanding of the equation is stated below
A discrete path P of length l going from p to q in a graph G can be defined as a (l+ 1 ) - tuple () of vertices of G such that , =q, and defines an arc of G for all i [ 1, l].
The time necessary to cover a discrete path of length l defined on a discrete grey-scale image f equals the mean of the values off taken two at a time along P:
`` represents half of the grayscale value at the starting pixel, indicating the "cost" of starting the journey from that pixel.
`` represents half of the grayscale value at the ending pixel, indicating the "cost" of ending the journey at that pixel.
The summation (∑) adds up the grayscale values of the intermediate pixels () along the path (from to ), representing the "cost" of traveling through these pixels.
Hope this helps.

Products


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!