Skip to content

Instantly share code, notes, and snippets.

@danmusetoiu
Last active May 27, 2018 10:56
Show Gist options
  • Save danmusetoiu/be100f8766a3178af0707f82e0c71342 to your computer and use it in GitHub Desktop.
Save danmusetoiu/be100f8766a3178af0707f82e0c71342 to your computer and use it in GitHub Desktop.
image pixels visualization in python
#import modulele necesare
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
from skimage.io import imread
from skimage.transform import resize
#incarc o imagine. Oroginal, este o fotografie color, insa incarcarea o fac in alb-negru (tonuri de gri)
image = imread('/Users/dan/Desktop/codrutza.jpg',as_grey=True)
image = resize(image,(56,56),mode='reflect')
print('Aceasta imagine este de tipul: ',type(image), 'si are dimensiunile:', image.shape)
plt.imshow(image,cmap='gray')
#hai sa vedem si pixelii
def vezi_pixeli(img, ax):
ax.imshow(img, cmap='gray')
width, height = img.shape
thresh = img.max()/2.5
for x in range(width):
for y in range(height):
ax.annotate(str(round(img[x][y],2)), xy=(y,x),
horizontalalignment='center',
verticalalignment='center',
color='white' if img[x][y]<thresh else 'black')
fig = plt.figure(figsize = (24,24))
ax = fig.add_subplot(111)
vezi_pixeli(image, ax)
print("Acum se vede clar cum o imagine poate fi inteleasa matematic ca o matrice. In cazul meu, o matrice cu 56 de linii si 56 de coloane")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment