首页 > 解决方案 > 如何在 python 中将高斯噪声添加到 tif 图像文件中?

问题描述

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

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

简历2:

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 文件。任何帮助,将不胜感激!

标签: pythontensorflowscikit-imagecv2

解决方案


根据本文档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)的函数。


推荐阅读