import numpy as np
import matplotlib.pyplot as plt

def get_image(N,p=0.1):
    '''N : Taille de l'image
    p : proportion de points noirs'''
    image=np.random.random((N,N))>p
    return image.astype(float)

A=get_image(10)
##
plt.figure()
plt.close('all')

plt.imshow(A,cmap="gray")

plt.show()


## Script 3





## test

T=pgcb_memo(A)

print(pgcb_memo(A))



## Script 4

def emplacement(A):


    return [max, coord]



print(emplacement(A))


## Script 5

from matplotlib.ticker import MultipleLocator  # pour le quadrillage


def affiche(A):
    '''représente l'image A originelle d'une part,
    le carré blanc (en gris) au sein de A d'autre part'''

    L=emplacement(A)

    x,y=L[1]
    max=L[0]

    B=A.copy()
    B[x-max+1:x+1,y-max+1:y+1]=0.8  # on colore en gris clair le plus grand carré

    plt.close('all')

    plt.figure()

    plt.subplot(121)
    plt.imshow(A,cmap="gray")
    plt.title('image originelle')

    plt.gca().xaxis.set_major_locator(MultipleLocator(10))
    plt.gca().xaxis.set_minor_locator(MultipleLocator(5))
    plt.gca().yaxis.set_major_locator(MultipleLocator(10))
    plt.gca().yaxis.set_minor_locator(MultipleLocator(5))

    plt.subplot(122)
    plt.imshow(B,cmap="gray")
    plt.title('plus gd carré blanc (en gris!)')

    plt.gca().xaxis.set_major_locator(MultipleLocator(10))
    plt.gca().xaxis.set_minor_locator(MultipleLocator(5))
    plt.gca().yaxis.set_major_locator(MultipleLocator(10))
    plt.gca().yaxis.set_minor_locator(MultipleLocator(5))

    plt.tight_layout()
    plt.show()




##Script 6 bottom up

def pgcb_bottom_up(T):
    T={}



    return T



print(pgcb_bottom_up(A))

## grand test
A=get_image(500,0.01)

affiche(A)




