1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| from PIL import Image
import pylab as py
import os
fichier = "billes.jpg"
ncolors = 255
mon_image = py.array(Image.open(fichier))
rouge = [ r for bande in mon_image[:,:,2] for r in bande ]
vert = [ g for bande in mon_image[:,:,1] for g in bande ]
bleu = [ b for bande in mon_image[:,:,0] for b in bande ]
py.figure()
r_n, r_bins, var = py.hist(rouge, ncolors, histtype='stepfilled', align='left',alpha=0.5,aa=False,ec='none')
g_n, g_bins, var = py.hist(vert, ncolors, histtype='stepfilled', align='left',alpha=0.5,aa=False,ec='none')
b_n, b_bins, var = py.hist(bleu, ncolors, histtype='stepfilled', align='left',alpha=0.5,aa=False,ec='none')
max_samples = py.amax([len(r_n), len(g_n), len(b_n)])
max_density = py.amax([r_n.max(), g_n.max(), b_n.max()])
py.imshow(mon_image, interpolation='bilinear', extent=[0,max_samples,0,max_density])
py.axis('tight')
axes = py.gca()
axes.get_xaxis().set_ticks([])
axes.get_yaxis().set_ticks([])
py.xlabel('Saturation (0-1)')
py.ylabel('Densité')
py.title('Densité de couleur de %s' % os.path.basename(fichier))
py.savefig('histo+image.eps')
py.show() |
Partager