mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-24 12:31:11 +00:00
12 lines
366 B
Python
12 lines
366 B
Python
|
|
||
|
import numpy as np
|
||
|
import matplotlib.pyplot as plt
|
||
|
import matplotlib.image as mpimg
|
||
|
|
||
|
def rgb2gray(png_file='file_example.png'):
|
||
|
img = mpimg.imread(png_file)
|
||
|
gray = np.dot(img[:,:,:3], [0.2989, 0.5870, 0.1140])
|
||
|
plt.imshow(gray, cmap=plt.get_cmap('gray'), vmin=0, vmax=1)
|
||
|
plt.axis('off')
|
||
|
plt.savefig('gray_' + png_file + '.png', dpi=300)
|