import numpy as np
import os
from scipy.misc import imread, imresize
import matplotlib.pyplot as plt
cwd = os.getcwd()
def print_typeshape(img):
print "type is %s" % type(img)
print "shape is %s" % str(img.shape)
img = imread(os.path.join(cwd, 'image00041.jpg'))
print_typeshape(img)
plt.figure(0)
plt.imshow(img)
plt.title('original image with imread')
img2 = img.astype(np.float32)
plt.imshow(img2)
plt.title('original image with imread astype')
# plt.show()
img3 = img.astype(np.float32)/255.0
plt.imshow(img3)
plt.title('original image with imread astype')
# plt.show()
def rgb2gray(img):
if len(img.shape)== 3:
return img.dot([299./1000, 587./1000 , 114./1000])
else:
return img
grayimg = rgb2gray(img)
print_typeshape(grayimg)
plt.imshow(grayimg, cmap='gray')
plt.title('gray image')
plt.show()