【问题标题】:How do you add Gaussian Noise to a tif image file in python?如何在 python 中将高斯噪声添加到 tif 图像文件中?
【发布时间】:2020-08-04 22:01:08
【问题描述】:

我正在尝试将高斯噪声添加到一组 tif 文件中。我同时使用了 scikit-image 和 cv2。

Scikit-Image:noise_img = random_noise(np_img, mode='gaussian', seed=None, clip=True)

CV2:

gauss = gauss.reshape(np_img.shape[0], np_img.shape[1], np_img.shape[2]).astype('uint8')
noise_img = cv2.add(np_img, gauss)

我在传统的 jpeg 和 png 图像上使用了这两种方法,它们都有效。但是,它们似乎不适用于 tif 文件。任何帮助将不胜感激!

【问题讨论】:

  • 我猜你的 TIFF 图像有一个 shapedtype 与噪声函数不兼容,但由于你没有共享 TIFF 文件,我不能确定。跨度>

标签: python tensorflow scikit-image cv2


【解决方案1】:

根据本文档https://www.tensorflow.org/io/api_docs/python/tfio/experimental/image/decode_tiff,您可以使用以下函数在 Tensorflow 中解码 .tiff 图像:

image = tf.io.read_file(filepath)
image = tfio.experimental.image.decode_tiff(image, index=0, name=None)

稍后您可以添加所需的操作。请注意,在您的图像上,您只能在这种情况下使用来自 tf* 的函数,而不能使用来自其他库(如 PIL 或 OpenCV)的函数。

【讨论】:

    猜你喜欢
    • 2016-01-24
    • 2015-10-28
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 2017-10-11
    • 1970-01-01
    • 1970-01-01
    • 2013-04-07
    相关资源
    最近更新 更多