<jupyter_start><jupyter_text>RGB to Gray<jupyter_code>import cv2
import numpy as np
import matplotlib.pyplot as plt
cv2.__version__
im = cv2.imread("mafalda.jpg")
print(im[300, 600])
im = im[:,:,::-1]
print(im[300, 600])
plt.imshow(im)
im.shape<jupyter_output><empty_output><jupyter_text>RGB to Gray$color = 0.2989 * r + 0.5870 * g + 0.1140 * b$<jupyter_code>def rgb2grey1(im):
  return (im[:,:,0] + im[:,:,1] + im[:,:,2]) // 3
def rgb2grey2(im):
  return np.floor(0.2989 * im[:,:,0] + 0.587 * im[:,:,1] + 0.114 * im[:,:,2])
plt.imshow(rgb2grey1(im), cmap="Greys_r")
plt.imshow(rgb2grey2(im), cmap="Greys_r")
merkel = cv2.imread("merkel.jpg")
merkel = merkel[:,:,::-1]
plt.imshow(merkel)
plt.imshow(rgb2grey1(merkel), cmap="Greys_r")
plt.imshow(rgb2grey2(merkel), cmap="Greys_r")
def hist(grayim):
  h = np.zeros((256))
  H, W = grayim.shape
  for i in range(H):
    for j in range(W):
      h[math.floor(grayim[i, j])] += 1

  return h
grayim1 = rgb2grey1(im)
grayim2 = rgb2grey2(im)
h1 = hist(grayim1)
h2 = hist(grayim2)
plt.plot(h1)
plt.plot(h2)
plt.imshow(grayim1, cmap="Greys_r")
plt.imshow(grayim2, cmap="Greys_r")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20608695652173914, 'fraction_numerical': 0.07217391304347825, 'mean_word_length': 5.691860465116279, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '363837', 'license': 'CC0-1.0', 'n_tokens_mistral': 598, 'n_tokens_neox': 551, 'n_words': 93, 'path': '01_01_rgb2gray.ipynb', 'repo_name': 'lmcanavals/dip', 'size': '1150'}