import numpy as np # Standard numpy abbreviation : np import mahotas as mh # Standard mahotas abbreviation : mh #im = mh.imread('lena.jpg') # loads lena image im = mh.demos.load('lena') print im.shape r,g,b = im.transpose((2,0,1)) # Obtain the red/green/blue/channels with numpy methods imshow(im) # Display the image # Let's play around with stretching the images: print im ** 2. imshow(im ** 2.) # Matplotlib does not deal with that image very well # mahotas.stretch to the rescue: stretches the image to be in 0..255 range: imshow(mh.stretch(im ** 2.)) # We can manipulate each channel independently and then use mh.as_rgb to put them back together: imshow(mh.as_rgb(r**1.9, g, b**2)) imshow(mh.as_rgb(r**1.9, g**1.2, b**2)) im_filtered = mh.as_rgb(r**1.9, g**1.2, b**2) mh.imsave('lena_filtered.jpg', im_filtered)