# -*- coding: utf-8 -*-
"""
Created on Wed Dec  9 00:54:09 2015

@author: dconduche
"""

import matplotlib.pyplot as plt
import numpy as np

print("""----------------------1)----------------------""")

a = np.random.rand(20, 20, 3)
a[a > .5] = 1
a[a < .5] = 0
plt.imshow(a, interpolation='none')
plt.show()

print("""---------------------2)---------------------""")

rouge = a[:, :, 0]
vert = a[:, :, 1]
bleu = a[:, :, 2]

plt.imshow(rouge, interpolation='none')
plt.show()


print("""---------------------3)---------------------""")
## Toujours tester
#
#a[:, :, 1:] = 0  # On met à 0 les composantes vertes et bleues
#plt.imshow(a, interpolation='none')
#plt.show()
#
#print("""---------------------4)---------------------""")
#a = plt.imread('couleur.jpg')
#
#print(a.dtype)
## d'où « image 24bit »
#
#
#def neg_numpy(a):  # beaucoup plus rapide
#    return 255 - a
#
#
#def baisse_r(a, N):
#    """baisse la résolution
#    :a: tableau numpy
#    :N: coté du carré de pixel.
#    :return: une image b de résolution //N**2
#    """
#    n, p, _ = a.shape
#    a = a[:(n//N)*N, :(p//N)*N]  # Plus de problème au bord
#    b = a[:n//N, :p//N]  # Pour avoir le même dtype que a
#    for i in range(n//N):
#        for j in range(p//N):
#            b[i, j] = [a[i*N:(i+1)*N, j*N:(j+1)*N, k].sum()/N**2
#                       for k in range(3)]
#    return b
#
#plt.imshow(baisse_r(a, 20), interpolation='none')
#plt.show()
