Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Purely Python Imaging with Pymaging

Purely Python Imaging with Pymaging

A little over a year ago, frustration with the state of image processing in Python led me to start a project called pymaging. Pymaging is a pure Python image processing library that works on Python 2.x and 3.x. This talk will dive into why I started this project, how I dug into the problems, what I learned about image formats and my goals for the future of this project.

Avatar for PyCon 2013

PyCon 2013

March 17, 2013
Tweet

More Decks by PyCon 2013

Other Decks in Programming

Transcript

  1. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 2/28

    JONAS OBRIST github.com/ojii twitter.com/ojiidotch [email protected] django CMS core developer DjangoCon Europe 2012 Organizer Python Enthusiast
  2. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 3/28

    NO IDEA ABOUT DIGITAL IMAGING Can't code C Can barely read C Had no idea how images work
  3. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 4/28

    GOALS OF PYIMAGING Pure Python solution for common* imaging tasks Easily installable Easy to use Easy to hack Easy to extend Support for Python 2 and 3
  4. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 5/28

    ORIGINS OF PYMAGING December 21st 2011 #django-cms on freenode "Installing PIL is hard" < o j i i > a n d I d o n ' t g e t h o w n o o n e c a m e u p w i t h a n a l t e r n a t i v e y e t < o j i i > i s t h a t r e a l l y T H A T h a r d ? < o j i i > a n d d o e s i t r e a l l y * N E E D * C ? < k e z a b e l l e > s o u n d s l i k e y o u ' r e v o l u n t e e r i n g ; ) < o j i i > h a h < o j i i > i w i s h i c o u l d < T r i b a a l > I t h i n k s o m e b o d y j u s t h a s t o d o i t
  5. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 6/28

    EARLY RESISTANCE "Not Fast Enough" < G o t e n X i a o > o j i i : t h e p r o b l e m i s t h a t p u r e P y t h o n r u n n i n g o n C P y t h o n i s n ' t f a s t e n o u g h < T r i b a a l > p y p y : ) < o j i i > p y p y !
  6. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 8/28

    EARLY APPROACH Porting PIL C code line-by-line Previous success with this approach PIL proofed to be too complicated
  7. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 12/28

    GLUING THINGS TOGETHER Different library maturities Different internal storage But working proof-of-concept end of January 2012
  8. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 14/28

    FORMATS Register through setuptools entry points Provide an encoder and/or decoder Separate from the main package
  9. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 15/28

    CORE Defines the internal data structure Defines the API Keeps track of installed formats Implements basic algorithms
  10. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 16/28

    HOW IMAGES ARE STORED INTERNALLY P i x e l A r r a y and friends Flat a r r a y . a r r a y of pixel data High-level API to manipulate pixels and the canvas
  11. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 18/28

    FORMATS PNG encoding/decoding JPG decoding (broken) BMP decoding PSD (by Mikhail Korobov)
  12. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 19/28

    APIS Resize/Crop (Thumbnailing) Affine transforms (thanks Craig de Stigter) Rotation Drawing Blit (merging)
  13. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 20/28

    PYTHON 3 Python 2.6 ~ 3.3 Not as hard as I thought Pymaging only handles bytes, not strings New libraries should really support 3!
  14. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 22/28

    FORMATS Level of documentation varies a lot! PNG is amazing! BMP is weird JPEG is complicated GIF is really close to being easy
  15. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 23/28

    PYPY IS AWESOME The primary "speed" strategy Very helpful developers They fix PyPy if you find slow parts
  16. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 24/28

    YOU'RE NOT THE FIRST Chances are somebody tried before Google! Build on others work
  17. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 26/28

    I NEED HELP You can most likely contribute Pick a format, implement it Pick a format, fix it Ask me for help
  18. 3/17/13 reveal.js - The HTML Presentation Framework file:///home/jonas/Ubuntu One/presentations/pymaging/local/index.html#/ 28/28

    THANK YOU / QUESTIONS? github.com/ojii/pymaging github.com/ojii/pymaging-png github.com/ojii/pymaging-bmp github.com/ojii/pymaging-jpg twitter.com/ojiidotch [email protected] github.com/ojii