Skip to content

Instantly share code, notes, and snippets.

@Biazus
Created July 24, 2025 04:28
Show Gist options
  • Save Biazus/47bc7cf7339d81a2cf4a2dc5d59e7597 to your computer and use it in GitHub Desktop.
Save Biazus/47bc7cf7339d81a2cf4a2dc5d59e7597 to your computer and use it in GitHub Desktop.
Just a small snippet to test normalization
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread("D:\\Projetos\\Cinza\\teste.jpg")
gray = 0.299 * img[:, :, 0] + 0.587 * img[:, :,1] + 0.114 * img[:, :,2]
gray = gray.astype(np.uint8) # garantindo valores inteiros
limit = 127
black = np.zeros_like(gray)
for i in range(len(gray)):
for j in range(len(gray[i])):
black[i][j] = 1 if gray[i][j] > limit else 0
plt.imshow(gray, cmap='gray')
plt.show()
plt.imshow(black, cmap='gray')
plt.show()
print(img.shape)
print(gray.shape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment