In [23]:
%matplotlib inline
import matplotlib.pyplot as plt
#http://nbviewer.ipython.org/github/ipython/ipython/blob/1.x/examples/notebooks/Part%203%20-%20Plotting%20with%20Matplotlib.ipynb
from IPython.display import Image, display
In [1]:
from scipy import misc
##### Options for importing images #####
### 1) Pil (and Pillow): it is possible to load image and convert to numpy array
#http://effbot.org/zone/pil-changes-116.htm\
### 2) from skimage import io
#http://scipy-lectures.github.io/packages/scikit-image/
#skimage.io.imread(fname, as_grey=False, plugin=None, flatten=None, **plugin_args)
# img_array : ndarray
# The different colour bands/channels are stored in the third dimension, such that a grey-image is MxN, an RGB-image MxNx3 and an RGBA-image MxNx4.
### 3) from scipy import misc
In [3]:
lena = misc.imread('../example_files/lena.png')
type(lena)
#<type 'numpy.ndarray'>
# lena.shape, lena.dtype
#((512, 512), dtype('uint8'))
#dtype is uint8 for 8-bit images (0-255)
Out[3]:
In [4]:
lena
Out[4]:
In [11]:
#https://docs.scipy.org/doc/scipy-0.14.1/reference/generated/scipy.misc.imread.html
google = misc.imread('../example_files/google_logo.png')
google_flatten = misc.imread('../example_files/google_logo.png', flatten=True)
In [9]:
print google.shape
print google.dtype
In [14]:
#google
# png: RGBA: alpha channel (transparancy) + RGB
# all/most pictures are 8 or 16-bit image. That is why we get int8 or?
In [20]:
print google_flatten.shape
print google_flatten.dtype
google_flatten
Out[20]:
In [29]:
plt.imshow(google) # cannot specify interpret colormap cmap=plt.get_cmap("Greys")
plt.show()
In [26]:
### Show flatten image
plt.imshow(google_flatten, cmap=plt.get_cmap("Greys"))
plt.show()
In [19]:
from IPython.display import Image, display
display(google_flatten)
In [ ]: