向图像添加泊松噪声
问题内容:
为了更全面地分析它们,我需要添加一些图像以增加Poisson噪声。我知道您可以在MATLAB中执行此操作,但是如何在Python中执行此操作呢?到目前为止,搜索没有任何结果。
问题答案:
如果您可以使用numpy /
scipy,则以下内容应会有所帮助。我建议您将数组转换为浮点数以进行中间计算,然后将其转换回uint8以进行输出/显示。由于泊松噪声都> =
0,因此您需要决定在转换回uint8时如何处理数组溢出。您可以根据自己的目标进行缩放或截断。
filename = 'myimage.png'
imagea = (scipy.misc.imread(filename)).astype(float)
poissonNoise = numpy.random.poisson(imagea).astype(float)
noisyImage = imagea + poissonNoise
#here care must be taken to re cast the result to uint8 if needed or scale to 0-1 etc...