Posts

Showing posts from May, 2021

Generate-a-compressed-approximation-of-an-image-using-matrix-decomposition-from-linear-algebra

Image
  In [46]: import matplotlib.pyplot as plt import numpy as np In [14]: img = plt . imread ( 'ax.jpg' ) In [16]: plt . imshow ( img ) Out[16]: <matplotlib.image.AxesImage at 0x1ea5f1d1070> In [47]: img . shape Out[47]: (173, 307, 3) In [48]: img . ndim Out[48]: 3 In [49]: img [:, :, 0 ] Out[49]: array([[ 57, 57, 58, ..., 71, 70, 60], [ 57, 58, 59, ..., 56, 63, 74], [ 58, 59, 59, ..., 98, 56, 68], ..., [ 42, 38, 38, ..., 102, 102, 70], [ 48, 46, 46, ..., 87, 76, 53], [ 51, 50, 52, ..., 93, 70, 54]], dtype=uint8) In [50]: img [:, :, 0 ] . shape Out[50]: (173, 307) In [51]: img_array = img / 255 In [52]: img_array . max (), img_array . min () Out[52]: (1.0, 0.0) In [53]: img_array . dtype Out[53]: dtype('float64') In [54]: red_array = img_array [:, :, 0 ] green_array = img_array [:, :, 1 ] blue_array = img_array [:, ...