gpt4 book ai didi

python - 将 openCV-python 自适应阈值应用于 3D tiff

转载 作者:太空宇宙 更新时间:2023-11-03 23:10:57 25 4
gpt4 key购买 nike

我使用共聚焦显微镜生成的 3D 体积。这些图像的 x、y、z 尺寸约为 1024,1024,50,并存储在 .tif 文件中。

我想将 OpenCV-python cv2.adaptiveThreshold 应用于整个图像堆栈。以下代码适用于二维图像 (1024,1024,1)。如何将其展开为整个卷并保存输出的 .tif 文件?

img = cv2.imread("1024x1024x40.tif")
gimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
th = cv2.adaptiveThreshold(gimg, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 7, -20)
cv2.imshow('original',img)
cv2.imshow('Adaptive threshold',th)
cv2.waitKey(0)
cv2.destroyAllWindows()

谢谢!

最佳答案

使用bioformats包:

我没有测试数据但使用 this answer作为指南,您可以尝试以下操作:

import javabridge
import bioformats

javabridge.start_vm(class_path=bioformats.JARS)

path_to_data = '/path/to/data/file_name.tif'

xml_string = bioformats.get_omexml_metadata(path_to_data)
ome = bioformats.OMEXML(xml_string) # be sure everything is ascii
iome = ome.image(0) # e.g. first image

reader = bioformats.ImageReader(path_to_data)
raw_data = []
for z in range(iome.Pixels.get_SizeZ()):
img = reader.read(z=z, series=0, rescale=False)
gimg = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
th = cv2.adaptiveThreshold(gimg, 255,
cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 7, -20)
img = cv2.bitwise_and(img, img, mask = th)
raw_data.append(img)

bioformats.write_image("/path/to/data/file_name_OUTPUT.tif", raw_data)

关于python - 将 openCV-python 自适应阈值应用于 3D tiff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50338907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com