How to calculate the intersection point between line and mask
If there is a line and a mask, how can I obtain the intersection point?
For example:
mask = np.zeros([300, 300, 50]) mask[:, :, 10:30] = 1
Then, the line is:
p1 = [100, 100, -1] p2 = [100, 100, 1]
The intersection point should be: [100, 100, 10] and [100, 100, 29].
Try:
from vedo import *
import numpy as np
mask = np.zeros([300, 200, 50])
mask[:, :, 10:30] = 1
p1 = [-100, 100, -100]
p2 = [100, 100, 200]
line = Line(p1,p2).c('r').lw(9)
vol = Volume(mask)
vbox = vol.box().wireframe(False).lw(1)
pts = vbox.intersectWithLine(p1,p2)
print(pts)
show(vbox, line, Points(pts, r=20).c('green'), axes=1)
PS: sorry I probably misunderstood.. if you want the boundary hits, where the line hits non-zero voxels you might use
vbox = vol.isosurface(1)
# or
vbox = vol.legosurface(0.9,1.1)
@marcomusy Thank you for your kindly reply. I indeed need the boundary hits.
Sometime, the mask is very thin. For example:

Thus, the vol.isosurface(1) will not return a closed surface, and the boundary hits will contain only one point. But, I need two hit points.