mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-23 20:11:10 +00:00
Merge pull request #116 from muratonuryildirim/master
Issue No: 82 RGB to Grayscale
This commit is contained in:
commit
5e42fdc82d
10
scripts/rgb_to_grayscale/readme.md
Normal file
10
scripts/rgb_to_grayscale/readme.md
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# RGB to Grayscale Images
|
||||||
|
|
||||||
|
This simple script converts RGB .png files to Grayscale .png files.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Dependency:
|
||||||
|
- numpy
|
||||||
|
- matplotlib
|
||||||
|
- Use `pip install numpy and python` and `-m pip install -U matplotlib`
|
11
scripts/rgb_to_grayscale/script.py
Normal file
11
scripts/rgb_to_grayscale/script.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
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)
|
Loading…
Reference in New Issue
Block a user