I have a very large 3D image stored in a matrix (approx. 500x500x40
voxels) in Matlab. In this matrix about 30000 points are selected (suppose randomly). Suppose the selected voxels have a value of one and the non-selected points are zero. Now I need to calculate for every voxel in the entire 3D-image the Euclidian distance to the nearest selected point.
So for example in 2D, given a 4x4
matrix:
selection = 0 0 1 0
1 0 0 0
0 0 0 1
0 0 0 0
The corresponding distance matrix would be:
distance = 1 1 0 1
0 1 1 1
1 √2 1 0
2 √5 √2 1
Is there an efficient way to do this, in terms of both time and memory?
250000 x 40
matrix, then sample from this matrix to get a30000 x 40
matrix of points, then use the above marked duplicate. – rayryeng