[英]Adding noise to an image in increments
Hi I am trying to add noise to a QR image that I create, this is my code so far: 嗨,我正在尝试为创建的QR图像添加噪点,到目前为止,这是我的代码:
import numpy
import scipy
import scipy.misc
import sys
sys.path.append('M:/PythonMods')
import qrcode
if __name__ == "__main__":
myqr = qrcode.make("randomtexxxxxxxxxt")
#myqr.show()
myqr.save("M:/COMPUTINGSEMESTER2/myqr4.png")
filename = 'myqr4.png'
imagea = (scipy.misc.imread(filename)).astype(float)
poissonNoise = numpy.random.poisson(50,imagea.shape).astype(float)
noisyImage = imagea + poissonNoise
Please could someone advise me how I get it to show the noisy image? 请有人能告诉我如何显示噪点图像吗? and how to save the image so I can test it? 以及如何保存图像以便进行测试?
Any help really appreciated. 任何帮助真的很感激。
edit 编辑
I tried adding this code to the program to get it to show the image: 我尝试将以下代码添加到程序中以使其显示图像:
from PIL import Image
myimage = Image.open(noisyImage)
myimage.load()
But then got this error: 但是然后得到这个错误:
Traceback (most recent call last):
File "M:\COMPUTINGSEMESTER2\untitled4.py", line 28, in <module>
myimage = Image.open(noisyImage)
File "Q:\PythonXY273_MaPS-T.v01\Python27\lib\site-packages\PIL\Image.py", line 1958, in open
prefix = fp.read(16)
AttributeError: 'numpy.ndarray' object has no attribute 'read'
Image.open
needs an image file as parameter, use Image.fromarray
: Image.open
需要一个图像文件作为参数,请使用Image.fromarray
:
im = Image.fromarray(noisyImage)
im.save("myFile.jpeg")
you may also use matplotlib
module to show the image directly: 您还可以使用matplotlib
模块直接显示图像:
import matplotlib.pyplot as plt
plt.imshow(noisyImage) #Needs to be in row,col order
scipy.misc.imsave('NoisyImage.jpg', noisyImage)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.