如何解决如何读取多个堆栈 tiff 文件,应用函数并保存多个堆栈 tiff 文件?
背景
我使用预训练的 U-net 模型进行语义分割。它适用于一个堆栈 tiff 文件(具有多个切片的 CT 图像)。到目前为止我所做的:
##load pre-trained U-Net Model :
model.load_weights('/content/drive/MyDrive/Models saved/segmentation_cancer4.hdf5')
##import and preprocess new files:
large_test_stack = tiff.imread('/content/drive/MyDrive/datasets/test/Test0.tif')
SIZE=256
all_img_patches = []
for img in range(large_test_stack.shape[0]):
#print(img) #just stop here to see all file names printed
large_image = large_test_stack[img]
patches_img = patchify(large_image,(SIZE,SIZE),step=SIZE) #Step=256 for 256 patches means no overlap
for i in range(patches_img.shape[0]):
for j in range(patches_img.shape[1]):
single_patch_img = patches_img[i,j,:,:]
single_patch_img = (single_patch_img.astype('float32')) / 255.
all_img_patches.append(single_patch_img)
images = np.expand_dims(normalize(np.array(all_img_patches),axis=1),3)
##apply model segmentation:
prediction_other = (model.predict(images) > 0.9).astype(np.uint16)
##save it as segmented volume.
from tifffile import imsave
imsave('/content/drive/MyDrive/datasets/results/Resultat24.tif',prediction_other)
问题
现在我想处理代表一百名患者的堆栈 tiff 文件列表,但我正在努力寻找一种简单的方法。我需要读取多个堆栈 tiff 文件,应用模型预测,然后将每个堆栈 tiff 预测保存在单独的文件夹中。
我怎么能做到这一点?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。