python - 如何在 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 文件。任何帮助,将不胜感激!
解决方案
根据本文档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)的函数。
推荐阅读
- python - 如何通过有条件地查找另一个 DF 并将结果水平附加到新的 DF 中来创建 DF?
- azure - Azure RBAC - 模块化和自定义角色继承
- javascript - 无法为 Outlook 获取正确的 .ics 格式以将其识别为请求
- python-3.x - ProjError:从 CRS 创建 Transformer 时出错。:
- python - 基于变量调用某个函数
- javascript - 当您将鼠标悬停在javascript中的div上时如何只发出一次声音
- reactjs - 使用 Fetch 发布请求在 componentDidMount 中不起作用
- javascript - 尝试使用 SceneView 设置缩放时出错
- c++ - 尝试将套接字存储到结构中时出现问题
- android - 我需要在我的 android 应用程序中获取 GCLID