Create a stl model from binary images with specific spacing.

Dear VTK users, I am a newbie VTK user (python). Does anyone know how to generate a stl model from 3 dimentional binary images? For example, I have a folder including 800 jpg images. Then I need to stack them into 3D matrix and convert it in binary. The size of the matrix is (800, 512, 512). And the corresponding voxel spacing is (0.7, 0.4, 0.4). I used the example from this link. But I got the model like this following picture that is a bunch of discrete points. And I don’t how to fix it. Thanks in advance for the replies.

There are many examples for this on VTK examples site. You can check out this one and find others by searching for marchingcubes, flyingedges, or contour filter.

i have this example if you want to use the vtkplotter helper package: numpy2volume.py, you can set the spacing in
v = Volume(matrix, spacing=(0.7, 0.4, 0.4)) and generate isosurfaces with
s = v.isosurface(threshold=...)
You can equally use PyVista: find an example here.