Pregunta

Hi I am trying to add noise to a QR image that I create, this is my code so far:

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'
¿Fue útil?

Solución

Image.open needs an image file as parameter, use Image.fromarray:

im = Image.fromarray(noisyImage)
im.save("myFile.jpeg")

you may also use matplotlib module to show the image directly:

import matplotlib.pyplot as plt
plt.imshow(noisyImage) #Needs to be in row,col order

Otros consejos

scipy.misc.imsave('NoisyImage.jpg', noisyImage)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top