Reputation: 422
I'm tring to use the PIL or scipy libraries to open and view images (as well as stuff from numpy and scipy), but I cannot run the program effectively and have it work. Every thing I follow on the internet gives me a different result and it is driving me crazy
First of all, I have WinPython installed. I hate the "spyder" and IPython interfaces and I would rather just write my code on Notepad++ and run it on the command line.
If I run this set of commands on the spyder interface, the image opens in an image viewer:
from scipy import misc
l = misc.lena()
misc.imsave('lena.png',l)
plt.imshow(l)
plt.show()
And the image:
I don't have the faintest clue why it's colored like that given that the original image is in grayscale, but one problem at a time.
When I run that same exact program (after all the imports that spyder gives initially), that same image viewer opens, but instantly closes....
Another tutorial. If I run this code on the command line, the default windows 8 image viewer (which I don't want) pops up and shows the image (correct, not colored like the one above):
from PIL import Image, ImageFilter
original = Image.open("lena.png")
blurred = original.filter(ImageFilter.BLUR)
original.show()
blurred.show()
The Internet has not helped me at all. All tutorials use IPython, which I'm not accustomed to, and each use different way to open and view images. Since I'm new, just following tutorials, and have no actual idea of what I'm doing, I would appreciate it if someone could help me out, focusing on the following points:
Upvotes: 2
Views: 4319
Reputation: 85605
The example in the docstring of misc.lena()
is actually:
>>> import matplotlib.pyplot as plt
>>> plt.gray()
>>> plt.imshow(lena)
>>> plt.show()
that produces a greyscale picture.
plt.gray()
sets the default colormap to gray and applies it to the current image if any.
Your image closes probably because after the program runs and ends there is no image object in memory anymore. Try maintaining the program running after it 'ends' (easier way is to include a raw_input('enter any key to close')
line at the end)
Your last problem is related with how pyplot and PIL display your images. Pyplot uses matplotlib but PIL im.show()
simply calls the default system image viewer for the extension it gives to your image in memory. This extension can by changed setting im.format
to the format (p.e. "PNG") to which your desired image editor or viewer is associated.
Upvotes: 2