SHARE
TWEET

grayScale

a guest Jan 24th, 2020 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  # -*- coding: utf-8 -*-
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. # o código espera que a imagem esteja no mesmo diretório que ele
  6. try:
  7.   img = plt.imread('image.jpg')  # leitura da imagem como um numpy array
  8. except:
  9.   print("An exception occurred")
  10.   exit(0)
  11.  
  12. nrows, ncols = img.shape[:2]  # obtendo as dimensões da imagem linhas x colunas
  13. img_copy = img.copy()  # cópia da imagem(array) para ser alterado
  14.  
  15. for i in range(nrows):
  16.     for j in range(ncols):
  17.         img_copy[i,j][:3] = img[i, j][0]*0.2126 + img[i, j][1]*0.7152 + img[i, j][2]*0.1722
  18.  
  19. plt.imsave('image_gray.jpg', img_copy)
  20. plt.imshow(img_copy)
  21. plt.show()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top