What is python-3 using instead of PIL for manipulating Images?
The "friendly PIL fork" Pillow works on Python 2 and 3. Check out the Github project for support matrix and so on.
Christoph Gohlke managed to build PIL (for Windows only) for python versions up to 3.3: http://www.lfd.uci.edu/~gohlke/pythonlibs/
I tried his version of PIL with Python 3.2, and image open/create/pixel manipulation/save all work.
Qt works very well with graphics. In my opinion it is more versatile than PIL.
You get all the features you want for graphics manipulation, but there's also vector graphics and even support for real printers. And all of that in one uniform API, QPainter.
To use Qt you need a Python binding for it: PySide or PyQt4.
They both support Python 3.
Here is a simple example that loads a JPG image, draws an antialiased circle of radius 10 at coordinates (20, 20) with the color of the pixel that was at those coordinates and saves the modified image as a PNG file:
from PySide.QtCore import *
from PySide.QtGui import *
app = QCoreApplication([])
img = QImage('input.jpg')
g = QPainter(img)
g.setRenderHint(QPainter.Antialiasing)
g.setBrush(QColor(img.pixel(20, 20)))
g.drawEllipse(QPoint(20, 20), 10, 10)
g.end()
img.save('output.png')
But please note that this solution is quite 'heavyweight', because Qt is a large framework for making GUI applications.
As of March 30, 2012, I have tried and failed to get the sloonz fork on GitHub to open images. I got it to compile ok, but it didn't actually work. I also tried building gohlke's library, and it compiled also but failed to open any images. Someone mentioned PythonMagick above, but it only compiles on Windows. See PythonMagick on the wxPython wiki.
PIL was last updated in 2009, and while it's website says they are working on a Python 3 port, it's been 3 years, and the mailing list has gone cold.
To solve my Python 3 image manipulation problem, I am using subprocess.call() to execute ImageMagick shell commands. This method works.
See the subprocess module documentation.
You can use my package mahotas on Python 3. It is numpy-based rather than PIL based.
You want the Pillow library, here is how to install it on Python 3:
pip3 install Pillow
If that does not work for you (it should), try normal pip:
pip install Pillow
Depending on what is needed, scikit-image may be the best choice, with manipulations going way beyond PIL and the current version of Pillow. Very well-maintained, at least as much as Pillow. Also, the underlying data structures are from Numpy and Scipy, which makes its code incredibly interoperable. Examples that pillow can't handle:
You can see its power in the gallery. This paper provides a great intro to it. Good luck!
If you are on Python3 you can also use the library PILasOPENCV which works in Python 2 and 3. Function api calls are the same as in PIL or pillow but internally it works with OpenCV and numpy to load, save and manipulate images. Have a look at https://github.com/bunkahle/PILasOPENCV or install it with pip install PILasOPENCV. Not all PIL functions have been simulated but the most common functions work.
Related
I want to use one of the newest versions of Python, (3.5+), and I need to import Image. I use:
from PIL import Image
except this returns an error. I don't have the error on my right now but the important part is there is a problem with PIL (I have already determined that from my Python Discord server)
Can I use pillow? I think I have that installed. I would try it but I want to know how (and if) it's applicable. Thanks
Can I use pillow?
Sure. pillow is a successor project of PIL, as development on the latter was last continued in 2011.
The first thing mentioned in the official pillow documentation is how to import the Image class.
I'm having trouble in finding PIL source code.
The main page of the library http://www.pythonware.com/products/pil/ does not have any link to git repositories.
Is Pillow (https://github.com/python-pillow/Pillow) repository correct project?
PIL was never ported to Python 3, so Pillow forked the project and took it over. Pillow has since been back-ported to Python 2, but if you are working with Python 3, you must use Pillow. They are essentially the same.
If you want the source code of PIL, just download it and look within the files yourself. If you want the documentation for PIL, this is a good reference.
No. I think it is difference project.
https://pillow.readthedocs.io/en/latest/installation.html
When you want to install pillow, you must uninstall PIL
I am trying to use scikit-image to do some research. The system is Windows 7 64bit, and the python version is 2.7, 64bit.
The first program I run is from: http://scikit-image.org/
The code is
from skimage import data, io, filter
image = data.coins() # or any NumPy array!
edges = filter.sobel(image)
io.imshow(edges)
io.show()
However, the problem happens, and the error message is:
C:\Python27\lib\site-packages\skimage\io_plugins\null_plugin.py:14:
RuntimeWarning: No plugin has been loaded. Please refer to
skimage.io.plugins()
for a list of available plugins.
warnings.warn(RuntimeWarning(message))
I believe that both Python and scikit-image are correctly installed. So, may I know what is wrong with it?
Any suggestion is appreciated. Many thanks.
Just had precisely the same issue on amazon linux. The issue is that skimage requires PIL, and PIL is not installed. In the latest skimage they added the dependency, but the version that I got installed with pip didn't have it yet.
The solution is
pip install Pillow
EDIT: and after that you will probably immediately face another issue, with skimage loading image, but not being able to read it (in particular, shape being empty tuple). Here's the solution
Why does scipy.ndimage.io.imread return PngImageFile, not an array of values
Is there an exif library out there for Python 3.x? It seems every exif library I run into is for Python 2.x only. I don't need anything too fancy. Just reading the values is enough.
Option 1. Use pyexiv2. See: pyexiv2 Bug #824440: Python 3 support You need boost-python for py3k and also to manually apply the patch posted at the end of the bug above, but aside from that it works. Probably easiest to get up and running under latest Ubuntu.
Option 2. Use PIL Downside: this branch/fork doesn't seem to be actively developed.
from PIL import Image
from PIL.ExifTags import TAGS
image = Image.open("test.jpg")
exif = image._getexif()
# decode exif using TAGS
Option 3. Use PythonMagick
from PythonMagick import Image
img = Image("image.jpg")
print img.attribute("EXIF:Orientation")
See also: Exif manipulation library for python
For reference, the pyexiv2 homepage now has a deprecation warning which points to Gexiv2, a GObject-introspection based wrapper around libexiv2 (the same library pyexiv2 wraps) specifically for the purpose of Python 3.x support.
Unfortunately, at the time of writing, installation of Gexiv2 is still painful and thus far I've been unable to get it working on Ubuntu Precise (looks like the libs are out of date - probably serves me right for sticking around on an LTS...), so PIL is still the best option for reading EXIF tags in Python 3.
Where can i get OpenCV for python?What are the pre-requisites?? i tried to install opencv-python through synaptic package manager but Python says
No module named CVtypes
CVTypes is a third party implementation that essentially wraps python around objects written in C, the language that OpenCV is written in (along with C++). If you want to use that, you will have to download and install it separately, as it is not part of the standard repositories of Ubuntu's Synaptic package manager that I know of at this time (I assume you are on Ubuntu because you mentioned 'Synaptic', Ubuntu's package manager).
However, there is an official python interface for OpenCV that is included in the OpenCV SVN repository and build packages. When installing version 1.0 from the package manager in Ubuntu, the python modules will be installed in the following directory:
/usr/lib/pymodules/python2.6/opencv
Ensure that is part of your PYTHONPATH environment variable and you should be able to import the modules as such:
from opencv.cv import *
from opencv.highgui import *
OpenCV over time has accumulated numerous Python bindings, mostly due to the strange way arrays are represented in OpenCV (IMHO). Here is a short list:
PyOpenCV
Scikits Image
Ctypes OpenCV
SWIG OpenCV
Choose which one you want to use and keep it consistent and upto date. I personally prefer the classic WillowGarage version[listed last] over its fancier cousins since it has most development and test muscle behind it.
get it from here unofficial binary packages.
by the way, they provide unofficial packages for many other projects
Tried the official website? http://opencv.willowgarage.com/wiki/Welcome
check your openCV version. Version 2 needs a simple
import cv
you may have a look at the samples/python folder.
this webpage explains in great depth on the installation
http://opencvpython.blogspot.com/2012/05/install-opencv-in-windows-for-python.html
after the installation try out the samples provided by opencv\samples\python2