3dSurfMask distance computation within mask

Dear AFNI experts,

I use 3dSurfMask to compute distance between voxels and specified surface. Since it is quite time consuming (no OpenMP), esp. for high resolution grid_parent, is it possible to restrict the computation within a mask?

Many thanks~

Best regards,

It looks like 3dSurfMask doesn’t have a mask option, but there other ways to accomplish what I think you want to do. You can get the xyz voxel centers for the volume mask from 3dmaskdump. Then get the xyz coordinates of the nodes in the surface with SurfMeasures, Surf2VolCoord. Then calculate simple euclidean distance with 3dcalc or 1deval. You may also want to consider finding the closest nodes to the volume xyz coordinates with SurfaceMetrics.

Wow, I’ll try this new approach.
Thank you very much, Daniel~

Hi afni experts,

Here is a follow up question: without using 3dSurfMask, which doesn’t support volume masking and is very slow,

  1. Is it possible to get signed distance from a surface for a list of voxels?
  2. Alternative, is it possible to determine whether a list of voxels are inside or outside a closed surface (which apparently could be concave)?

I realize that this is the true computationally demanding task that 3dSurfMask managed to solve.


SurfaceMetrics, through its “-closest_node” options, gives the closest node and distance from a list of xyz coordinates. I don’t think it does a signed distance, where I suppose you want to know if it’s inside or outside the surface. You can use 3dVol2Surf to map from the volume to the surface. If the selected voxels are a mask, you can use that and normal vectors from the surface. If the voxels in the mask were replaced by an index you could see which voxels are crossed with the -seg_vals option. Normal vectors can be configured to go into and/or outside the surface.

You could also compute distance by converting a surface to an ASCII text or vec (vector) format and compute distance with 3dcalc or similar.