Image processing:
Import matplotlib.pyplot AS plt Import scipy.ndimage AS ndimage # read the image data num_img_arr = plt.imread ( ' F: // // Getting Python file //test.jpg ' ) plt.imshow (num_img_arr) # Image Capture digital . 5 five_arr = num_img_arr [90: 158,80: 132 ] plt.imshow (five_arr) # dimensionality reduction operation (Five three-dimensional array, it is necessary to reduce the dimension, discarding the third dimension represents the color) # (65, 56, . 3) Print ( ' picture original dimensions: ' , five_arr.shape) # Axis = 2, returns shape = [x, y], z in each of the inner elements are compared Five = five_arr.mean (Axis = 2 ) Print ( ' after pictures dimensionality reduction dimensions: ', five.shape) # (65, 56 is) plt.imshow (Five) # Image compression is 28 pixels * 28 Five = ndimage.zoom (Five, Zoom = (28 / 68,28 / 52 is )) # (28, 28 ) Print ( ' future picture compression dimensions: ' , five.shape) # display compressed 5 plt.imshow (five)
result:
The original picture dimensions: (68, 52, 3 ) the picture down after dimension dimensions: ( 68, 52 ) images after compression dimensions: ( 28, 28)