In [6]:
%matplotlib inline
import numpy as np
from scipy.misc import imread, imresize
import matplotlib.pyplot as plt
import rawpy
import imageio
img_list = ['1.pgm', '891539.bmp', 'fR01.raw', 'lenna.tif', 'koala512.jpg', 'array.tif']
In [50]:
# for test
img = imread(img_list[0])
print(img.shape)
plt.imshow(img)
plt.show()
# img_reshape = img.reshape(img.shape[0]*img.shape[1], 1)
# img_hist = plt.hist(img_reshape, 256)
# plt.show()
In [93]:
# use plt.subplot()
img_list = ['1.pgm', '891539.bmp', 'fR01.raw', 'lenna.tif', 'koala512.jpg', 'array.tif']
subplot_list = [1, 2, 3, 7, 8, 9]
plt.figure(figsize=(20, 20))
for i in range(len(img_list)):
target_img = img_list[i]
subplot_index = subplot_list[i]
if target_img == 'fR01.raw':
img = np.fromfile(target_img, 'uint8')
img = img.reshape(300, 300)
else:
img = imread(target_img)
plt.subplot(4, 3, subplot_index)
plt.title(target_img, fontsize=20)
plt.imshow(img)
# plt.show()
new_shape = 1
for shape in img.shape:
new_shape = new_shape * shape
plt.subplot(4, 3, subplot_index+3)
plt.title('Histogram of ' + target_img, fontsize=20)
img_reshape = img.reshape(new_shape, 1)
img_hist = plt.hist(img_reshape, 256)
plt.tight_layout()
# plt.show()
plt.savefig('output_by_python.png', dpi=300)
In [ ]: