Clear Filters
Clear Filters

Distance Transform in 3D

4 views (last 30 days)
Sumayyah Alhydary
Sumayyah Alhydary on 24 Apr 2021
Edited: Sumayyah Alhydary on 24 Apr 2021
Hello everyone!
Background:
Let us say I have 4 binary 5x5 matrices:
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
0 0 0 0 0
0 1 1 0 0
0 1 1 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 1 1 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 1 1 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
Imagine that we stack all of them on top of each other (first one is at the bottom).
The propuse of them is they explain the density of each position in a 5x5 image:
If we sum the 1's for each position, that gives us the density of that position.
For example:
  • the density of the position where the bolded 1 is will be 2 (it appears in the first matrix and second matrix)
  • for the underlined 1's will be 4 for all three positions (they apears in all 4 matrices)
  • all of the other position's density is 1 (apears only in first matrix).
resulting in the following 5 x 5 matrix with maximum density of 4:
1 1 1 1 1
1 4 4 1 1
1 4 2 1 1
1 1 1 1 1
1 1 1 1 1
Quesiton:
If have 100 binary 512x512 matrices and I want to calculate the distance transform for each one of the 100, how can I do that?
I found the following figure online and I will use it as another example:
Imagine here that we have 11 matrices and the first one is all 1 (that's why the bottom row in the following figure is all colored).
The tail of the arrow is assigned the distance to the boundary of the object as indicated by the tip of the arrow.
Guidelines:
  • All positions have a value of 1 in the first matrix.
  • If a position value changed from 1 to 0, it will not change back to 1 later.
Thanks in advance.
And in case you're wondering ..
I'm trying to implement the interpolation exaplained in "Shape-Based Interpolation of Multidimensional Grey-Level Images" By George J. Grevera.

Answers (1)

Image Analyst
Image Analyst on 24 Apr 2021
The distance transform is not just the summing along the third dimension. Since you say you want to sum along the third dimension of your 512 x 512 x 100 matrix, why not simply do
image2DSum = sum(image3D, 3); % Sum along dimension #3.
  1 Comment
Sumayyah Alhydary
Sumayyah Alhydary on 24 Apr 2021
Edited: Sumayyah Alhydary on 24 Apr 2021
Thanks for your responce and sorry I didn't explain the problem correctly. I just edit it the questoin.
The sum will give me the density for that pixel (which I will use later to decide the gray-level for that pixel)
But now, I need to find the distance transform matrix for each "layer" or matrix of the given 4.
So in the figure I showed above, I need to find the shortest distance to the top for each colored cell.
(What i'm trying to do in my probject is to have two gray-scaled images > convert each to 3D by doing what I did in the 5x5x4 example > apply distance transformation to each layer > apply interpolation on the distance matrices > collapse them back to 2D. Now I have an interpolated image between these two images)

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!