【问题标题】:Apply openCV-python adaptive threshold to 3D tiff将 openCV-python 自适应阈值应用于 3D tiff
【发布时间】:2018-05-15 05:43:45
【问题描述】:

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

我想将 OpenCV-python cv2.adaptiveThreshold 应用于整个图像堆栈。以下代码适用于 2D 图像 (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()

谢谢!

【问题讨论】:

标签: python opencv opencv-python adaptive-threshold image-thresholding


【解决方案1】:

使用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)

【讨论】:

    猜你喜欢
    • 2014-04-03
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 2021-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多