import matplotlib.pyplot as plt
import numpy as np
= plt.imread('mario.png') mario
255*mario[:5]).astype(int)[:, :, :-1] (
array([[[255, 164, 64],
[255, 164, 64],
[255, 164, 64],
[255, 164, 64],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]],
[[255, 164, 64],
[255, 164, 64],
[255, 164, 64],
[255, 164, 64],
[ 0, 0, 0],
[248, 56, 0],
[248, 56, 0],
[248, 56, 0],
[248, 56, 0],
[248, 56, 0],
[248, 56, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]],
[[255, 164, 64],
[255, 164, 64],
[248, 56, 0],
[248, 56, 0],
[248, 56, 0],
[248, 56, 0],
[248, 56, 0],
[248, 56, 0],
[248, 56, 0],
[248, 56, 0],
[248, 56, 0],
[248, 56, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]],
[[172, 124, 0],
[172, 124, 0],
[172, 124, 0],
[172, 124, 0],
[255, 164, 64],
[172, 124, 0],
[255, 164, 64],
[255, 164, 64],
[172, 124, 0],
[172, 124, 0],
[172, 124, 0],
[172, 124, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]],
[[172, 124, 0],
[172, 124, 0],
[172, 124, 0],
[255, 164, 64],
[255, 164, 64],
[172, 124, 0],
[255, 164, 64],
[255, 164, 64],
[255, 164, 64],
[172, 124, 0],
[255, 164, 64],
[172, 124, 0],
[172, 124, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0],
[ 0, 0, 0]]])
\[ \begin{bmatrix} 255 \\ 164 \\ 64 \\ \vdots \\ 0 \\ 0 \\ 0 \end{bmatrix} \]
= plt.subplot_mosaic("AB;AC;AD", gridspec_kw={'width_ratios': [3, 1]}, figsize=(6, 4), dpi=150)
fig, axes for i in 'ABCD':
axes[i].set_xticks([])
axes[i].set_yticks([])
'A'].imshow(mario, extent=(0, 17, 0, 16))
axes[
= [(10, 8), (4, 4), (15, 1)]
pixels
for i, (x, y) in zip('BCD', pixels):
'A'].add_patch(plt.Rectangle((x, y), 1, 1, edgecolor='green', fill=False))
axes[= ', '.join([str(int(j*255)) for j in mario[15-y, x][:-1]])
pixel_color 15-y:16-y, x:x+1]))
axes[i].imshow((mario[f"{pixel_color}")
axes[i].set_xlabel(
=0,right=1,bottom=0,top=1)
fig.subplots_adjust(left plt.tight_layout()
= np.array([[i[:-1].mean() for i in j] for j in mario])
mario_grey
= plt.subplot_mosaic("AB;AC;AD", gridspec_kw={'width_ratios': [3, 1]}, figsize=(6, 4), dpi=150)
fig, axes for i in 'ABCD':
axes[i].set_xticks([])
axes[i].set_yticks([])
'A'].imshow(mario_grey, extent=(0, 17, 0, 16), cmap='grey', vmin=0, vmax=1)
axes[
= [(10, 8), (4, 4), (15, 1)]
pixels
for i, (x, y) in zip('BCD', pixels):
'A'].add_patch(plt.Rectangle((x, y), 1, 1, edgecolor='green', fill=False))
axes[= str(int(mario_grey[15-y, x]*255))
pixel_color 15-y:16-y, x:x+1]), cmap='grey', vmin=0, vmax=1)
axes[i].imshow((mario_grey[f"{pixel_color}")
axes[i].set_xlabel(
=0,right=1,bottom=0,top=1)
fig.subplots_adjust(left plt.tight_layout()
= np.array([[i[-1] for i in j] for j in mario])
mario_bw
= plt.subplot_mosaic("AB;AC;AD", gridspec_kw={'width_ratios': [3, 1]}, figsize=(6, 4), dpi=150)
fig, axes for i in 'ABCD':
axes[i].set_xticks([])
axes[i].set_yticks([])
'A'].imshow(mario_bw, extent=(0, 17, 0, 16), cmap='grey', vmin=0, vmax=1)
axes[
= [(10, 8), (4, 4), (15, 1)]
pixels
for i, (x, y) in zip('BCD', pixels):
'A'].add_patch(plt.Rectangle((x, y), 1, 1, edgecolor='green', fill=False))
axes[= str(int(mario_bw[15-y, x]*1))
pixel_color 15-y:16-y, x:x+1]), cmap='grey', vmin=0, vmax=1)
axes[i].imshow((mario_bw[f"{pixel_color}")
axes[i].set_xlabel(
=0,right=1,bottom=0,top=1)
fig.subplots_adjust(left plt.tight_layout()