Reputation: 15
I have multiple images taken from the microscope with different Z-axis planes and converted them into single-channel images, and now I want to convert these single-channel images into 3d volume, but directly stack them without Z-axis spacing.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import tifffile as tiff
images = []
image_paths = ['1712071651.5126085_mask.jpg', '1712071668.4542189_mask.jpg', '1712071679.8891838_mask.jpg',"1712071690.5503793_mask.jpg","1712071701.1270576_mask.jpg",
"1712071708.6956294_mask.jpg","1712071716.9926243_mask.jpg","1712071725.3603532_mask.jpg","1712071744.5940547_mask.jpg","1712071753.896742_mask.jpg",
"1712071762.3356335_mask.jpg","1712071774.8131661_mask.jpg","1712071788.2660403_mask.jpg"] # 替换为你的图像路径
for path in image_paths:
image = plt.imread(path)
if len(image.shape) == 3:
image = np.mean(image, axis=-1)
images.append(image)
height, width = images[0].shape
stacked_image = np.zeros((len(images), height, width), dtype=np.uint8)
z_values = [50,50,50,50,50,50,50,50,50,50,50,50,50]
for i, (image, z) in enumerate(zip(images, z_values)):
stacked_image[i] = image
tiff.imsave('stacked_image.tif', stacked_image)
The 3d volume is presented by napari, and the 3d volume displayed is very flat.
Upvotes: 0
Views: 39