M Leonard
M Leonard

Reputation: 591

fastest Python native way to manipulate images?

I'm creating a process that iterates over an image and does x/y transformations and zooms. The original images are very large. My current process involves making a bash script (using python) to creates rows and rows with the all-famous Imagemagick Convert. The major upside of using convert is the fact that you can load the image into memory once, then write out each frame. However, this bash script workflow is not sustainable, and I need something more native. So this begs the question:

Here is where my research (and some tinkering) has led me:

Wand (Imagemagick wrapper) - Theoretically, Wand would be great! But I have found no mention of being able to read the image from memory, which makes it VERY slow.

Skimage - I'd love to use Skimage for the depth of the operations (though overkill for my needs), but I've found the API/Documentation very difficult to work with. However, the fact that you can load an image into a numpy array and get breakneck speeds (for Python, anyways), seems like a compelling argument.

PIL - Pil can be very tricky to install, which has caused a lot of trouble on a few systems I'm trying to deploy. The API, though, it's pretty darn easy. I've heard generally to stay away from PIL due to it's ongoing development woes.

Pillow - Similar to above, I've had some trouble getting Pillow working. I think I read that Pillow can conflict with PIL... maybe that's the problem?

I would love some input.

Upvotes: 4

Views: 4500

Answers (1)

fmw42
fmw42

Reputation: 53081

This is too long for a single comment. So I am putting it here.

Note that I am not an expert on any of these tools, other than ImageMagick, but have dabbled a little with each.

I welcome comments or opinions from others more expertise than I with these tools

I have not used Wand or PIL much. I don't like PIL since it is not as compatible with numpy without reformatting in my limited experience. So I do not use it. Wand looks good if you like ImageMagick convert. I have used both Skimage and OpenCV for different things. And have mixed them in some Python numpy scripts.

Wand is probably the easiest to use if you know ImageMagick. I do not know much about its speed. See https://docs.wand-py.org/en/0.6.12/wand/image.html. One Wand limitation that I believe exists is that it is missing the ability to deal with profile.

See https://pillow.readthedocs.io/en/stable/reference/Image.html for PIL, which is likely the next easiest to use. But its image format may require format changing to work with numpy. I do not think it is quite as full-functioned as Wand.

Also see http://scikit-image.org/docs/dev/api/skimage.transform.html for rotate, resize and affine transform. It is the next easiest to use but may be faster than the other two.

Also See https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_geometric_transformations/py_geometric_transformations.html, though you have to do all that with matrices. It is also very fast and has GPU capabilities.

I have no experience with timing other than I find Skimage and OpenCV faster than Imagemagick. But they are less directly functional for simple things that Imagemagick can do, apart from my comments above.

I think you have to decide what compromise you want with respect to speed and efficiency of coding.

If any one knows of a set of coding and speed tests comparing these tools on simple operations such as resize, rotate, crop, affine, perspective, etc, then that would be useful and I would welcome knowing more about the comparisons.

P.S. I found these references regarding PIL being outdated and superseded by Pillow:

https://pillow.readthedocs.io/en/stable/about.html https://pillow.readthedocs.io/en/stable/installation.html

Also see for docs: https://pypi.org/project/pillow/ https://pillow.readthedocs.io/en/stable/reference/Image.html

I have not tried the newer version of Pillow.

Upvotes: 3

Related Questions