Install stuff with pip -- this is magic, thanks Sean.


In [20]:
!pip uninstall pillow


Uninstalling Pillow:
  /home/johnny/wdbpython/bin/pilconvert.py
  /home/johnny/wdbpython/bin/pildriver.py
  /home/johnny/wdbpython/bin/pilfile.py
  /home/johnny/wdbpython/bin/pilfont.py
  /home/johnny/wdbpython/bin/pilprint.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/BdfFontFile.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/BmpImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/BufrStubImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ContainerIO.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/CurImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/DcxImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/EpsImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ExifTags.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/FitsStubImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/FliImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/FontFile.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/FpxImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/GbrImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/GdImageFile.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/GifImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/GimpGradientFile.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/GimpPaletteFile.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/GribStubImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/Hdf5StubImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/IcnsImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/IcoImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/Image.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageChops.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageCms.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageColor.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageDraw.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageDraw2.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageEnhance.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageFile.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageFileIO.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageFilter.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageFont.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageGrab.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageMath.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageMode.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageMorph.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageOps.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImagePalette.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImagePath.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageQt.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageSequence.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageShow.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageStat.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageTk.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageTransform.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImageWin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/ImtImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/IptcImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/Jpeg2KImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/JpegImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/JpegPresets.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/McIdasImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/MicImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/MpegImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/MspImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/OleFileIO-README.md
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/OleFileIO.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/PSDraw.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/PaletteFile.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/PalmImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/PcdImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/PcfFontFile.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/PcxImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/PdfImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/PixarImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/PngImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/PpmImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/PsdImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/PyAccess.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/SgiImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/SpiderImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/SunImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/TarIO.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/TgaImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/TiffImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/TiffTags.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/WalImageFile.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/WebPImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/WmfImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/XVThumbImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/XbmImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/XpmImagePlugin.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__init__.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/BdfFontFile.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/BmpImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/BufrStubImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ContainerIO.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/CurImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/DcxImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/EpsImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ExifTags.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/FitsStubImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/FliImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/FontFile.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/FpxImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/GbrImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/GdImageFile.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/GifImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/GimpGradientFile.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/GimpPaletteFile.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/GribStubImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/Hdf5StubImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/IcnsImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/IcoImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/Image.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageChops.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageCms.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageColor.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageDraw.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageDraw2.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageEnhance.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageFile.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageFileIO.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageFilter.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageFont.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageGrab.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageMath.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageMode.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageMorph.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageOps.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImagePalette.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImagePath.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageQt.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageSequence.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageShow.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageStat.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageTk.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageTransform.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImageWin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/ImtImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/IptcImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/Jpeg2KImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/JpegImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/JpegPresets.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/McIdasImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/MicImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/MpegImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/MspImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/OleFileIO.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/PSDraw.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/PaletteFile.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/PalmImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/PcdImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/PcfFontFile.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/PcxImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/PdfImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/PixarImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/PngImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/PpmImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/PsdImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/PyAccess.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/SgiImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/SpiderImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/SunImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/TarIO.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/TgaImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/TiffImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/TiffTags.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/WalImageFile.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/WebPImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/WmfImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/XVThumbImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/XbmImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/XpmImagePlugin.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/__init__.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/_binary.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/__pycache__/_util.cpython-34.pyc
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/_binary.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/_imaging.cpython-34m.so
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/_imagingmath.cpython-34m.so
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/_imagingmorph.cpython-34m.so
  /home/johnny/wdbpython/lib/python3.4/site-packages/PIL/_util.py
  /home/johnny/wdbpython/lib/python3.4/site-packages/Pillow-2.5.3-py3.4.egg-info
Proceed (y/n)? ^COperation cancelled by user


In [6]:
!mv Screenshot\ from\ 2014-09-21\ 13\:41\:09.png west.png

In [7]:
!mv Screenshot\ from\ 2014-09-21\ 13\:42\:44.png east.png

In [51]:
import PIL
from PIL import Image

In [57]:
from io import BytesIO
def display_pil_image(im):
   """Displayhook function for PIL Images, rendered as PNG."""

   b = BytesIO()
   im.save(b, format='png')
   data = b.getvalue()

   ip_img = display.Image(data=data, format='png', embed=True)
   return ip_img._repr_png_()


# register display func with PNG formatter:
png_formatter = get_ipython().display_formatter.formatters['image/png']
dpi = png_formatter.for_type(Image.Image, display_pil_image)

In [62]:
east = Image.open('east.png')
west = Image.open('west.png')

In [5]:
east.getpixel((20,10))


Out[5]:
(198, 233, 250)

In [7]:
width, height = east.size
east.size


Out[7]:
(725, 505)

In [60]:
from IPython import display

In [ ]:


In [93]:
def fix(img, width=None, height=None, pmin=75, pmax=90):
    
    w, h = img.size
    if width is None:
        width = w
    if height is None:
        height = h
    
    result = Image.new('RGB', (width, height), 'black')
    fixed = result.load()
    #print(img.size, width, height)
    for x in range(width):
        for y in range(height):
            pix = img.getpixel((x, y))
            if in_range(pix, pmin, pmax):
                fixed[x, y] = (255, 255, 255)
                 
    return result

def in_range(pix, pmin, pmax):
    
    for val in pix:
        if (val < pmin) or (val > pmax):
            return False
    return True

In [96]:
img = fix(west, pmin=0, pmax=100)
img


Out[96]:

In [69]:
display.Image('west.png')


Out[69]:

In [50]:
display.Image(img)


/home/johnny/wdbpython/lib/python3.4/site-packages/IPython/core/formatters.py:249: FormatterWarning: image/png formatter returned invalid type <class 'PIL.Image.Image'> (expected (<class 'bytes'>, <class 'str'>)) for object: <IPython.core.display.Image object at 0x7f4fa39025c0>
  FormatterWarning
Out[50]:
<IPython.core.display.Image at 0x7f4fa39025c0>

In [54]:
img?

In [92]:
a = [1, 2, 3]
b = [0, 3]
a > b


Out[92]:
True