import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
f = "../data/001_raw/figs/u_norm_173.png"
img = Image.open(f)
matriz = np.array(img)
rojo  = matriz[:,:,0]
verde = matriz[:,:,1]
azul  = matriz[:,:,2]
alpha = matriz[:,:,3]
alpha.min()
np.uint8(255)
img

alpha.shape
(894, 4800)
alpha.size
4291200
alpha.ndim
2
renglon = alpha.flatten()
renglon.reshape(8,536400)
array([[255, 255, 255, ..., 255, 255, 255],
       [255, 255, 255, ..., 255, 255, 255],
       [255, 255, 255, ..., 255, 255, 255],
       ...,
       [255, 255, 255, ..., 255, 255, 255],
       [255, 255, 255, ..., 255, 255, 255],
       [255, 255, 255, ..., 255, 255, 255]],
      shape=(8, 536400), dtype=uint8)
renglon.reshape(32,-1)
array([[255, 255, 255, ..., 255, 255, 255],
       [255, 255, 255, ..., 255, 255, 255],
       [255, 255, 255, ..., 255, 255, 255],
       ...,
       [255, 255, 255, ..., 255, 255, 255],
       [255, 255, 255, ..., 255, 255, 255],
       [255, 255, 255, ..., 255, 255, 255]],
      shape=(32, 134100), dtype=uint8)
fig, ax = plt.subplots()

ax.imshow(matriz[:,:,3],cmap="gray")

fig, ax = plt.subplots()

ax.imshow(rojo,cmap="gray")

fig, ax = plt.subplots()

ax.imshow(verde,cmap="jet")

fig, ax = plt.subplots()

ax.imshow(azul,cmap="gray")

promedio = np.mean(matriz,axis=-1)
fig, ax = plt.subplots()

ax.imshow(promedio, cmap="jet")

fig, ax = plt.subplots()

ax.imshow(promedio,cmap="jet")

promedio.min()
np.float64(101.25)
promedio_sin4 = np.mean(matriz[:,:2],axis=-1)
fig, ax = plt.subplots()

ax.imshow(promedio_sin4,cmap="jet")

promedio = np.mean(matriz[:,:,:3],axis=-1)
promedio
array([[255., 255.,  50., ...,  50.,  50., 255.],
       [255., 255.,  50., ...,  50.,  50., 255.],
       [255., 255.,  50., ...,  50.,  50., 255.],
       ...,
       [255., 255.,  50., ...,  50.,  50., 255.],
       [255., 255.,  50., ...,  50.,  50., 255.],
       [255., 255.,  50., ...,  50.,  50., 255.]], shape=(894, 4800))
azul
array([[255, 255,  97, ...,  97,  97, 255],
       [255, 255,  97, ...,  97,  97, 255],
       [255, 255,  97, ...,  97,  97, 255],
       ...,
       [255, 255,  97, ...,  97,  97, 255],
       [255, 255,  97, ...,  97,  97, 255],
       [255, 255,  97, ...,  97,  97, 255]],
      shape=(894, 4800), dtype=uint8)
rojo
array([[255, 255,   5, ...,   5,   5, 255],
       [255, 255,   5, ...,   5,   5, 255],
       [255, 255,   5, ...,   5,   5, 255],
       ...,
       [255, 255,   5, ...,   5,   5, 255],
       [255, 255,   5, ...,   5,   5, 255],
       [255, 255,   5, ...,   5,   5, 255]],
      shape=(894, 4800), dtype=uint8)
np.stack([rojo,azul],axis=2)
array([[[255, 255],
        [255, 255],
        [  5,  97],
        ...,
        [  5,  97],
        [  5,  97],
        [255, 255]],

       [[255, 255],
        [255, 255],
        [  5,  97],
        ...,
        [  5,  97],
        [  5,  97],
        [255, 255]],

       [[255, 255],
        [255, 255],
        [  5,  97],
        ...,
        [  5,  97],
        [  5,  97],
        [255, 255]],

       ...,

       [[255, 255],
        [255, 255],
        [  5,  97],
        ...,
        [  5,  97],
        [  5,  97],
        [255, 255]],

       [[255, 255],
        [255, 255],
        [  5,  97],
        ...,
        [  5,  97],
        [  5,  97],
        [255, 255]],

       [[255, 255],
        [255, 255],
        [  5,  97],
        ...,
        [  5,  97],
        [  5,  97],
        [255, 255]]], shape=(894, 4800, 2), dtype=uint8)