Please refresh the page if equations are not rendered correctly.
---------------------------------------------------------------
1. 使用Scikit-image
from skimage import io
import numpy as np
io.use_plugin('pil')
ic = io.imread_collection('tow_binary_216_302.tif')
# >>>
image_3d = io.concatenate_images(ic) # numpy.ndarray
image_3d = image_3d[0] # binary - 0 vs 255
# Counts the number of non-zero values in the array a.
count = np.count_nonzero(image_3d) # Corresponding to iSlice 216 - 302
#
coor_x = coor[2]
coor_y = coor[0]
coor_z = coor[1]
# Thresholding and save as images
mask = (image_3d<75)
image_3d[mask]= 0
for i in np.arange(704):
name='0000'+str(i)
name = './longibg/blackbgLong'+name[-4:]+'.tif'
io.imsave(name, image_3d[i,:,:])
使用PyVista
import numpy as np
import pyvista as pv
res = 0.022 # mm
mesh = pv.read('tow_binary_216_302.tif')
mesh = mesh.cast_to_unstructured_grid()
pts = mesh.points
nx, ny, nz = pts.astype(int)[-1,:] + 1
grey_level = mesh['Tiff Scalars'].reshape([nz, ny,nx])
# Return the indices of the elements that are non-zero.
coor = np.nonzero(grey_level)
coor_x = coor[2] * res
coor_y = (coor[0] + 215) * res
coor_z = (257-coor[1]) * res
# non-zero point coordinate
coordinate = np.vstack((coor_x, coor_y, coor_z)).T
Comments NOTHING