im.py

Created by yacine-ahjaou

Created on March 25, 2023

1.53 KB


# Type your text here
def matriceGris(n,p):
  M = np.zeros((n,p), np.uint8)
  return M

def matriceCouleurs(n,p):
  return np.zeros((n,p,3),np.uint8)

# Exercice 2 
    
def invRB(M):
    # M tableau à 3 dimensions codant pour une image en couleurs
    n,p,c = np.shape(M)
    NM = matriceCouleurs(n,p)
    for i in range(n) : # boucle sur les indices de lignes
        for j in range(p): # boucle sur les indices de colonnnes
            NM[i][j][0] = M[i][j][2]
            NM[i][j][1] = M[i][j][1]
            NM[i][j][2] = M[i][j][0]
    return NM

def inverse(M):
    # M tableau à 3 dimensions codant pour une image en couleurs
    n,p,c = np.shape(M)
    NM = matriceCouleurs(n,p)
    for i in range(n) : # boucle sur les indices de lignes
        for j in range(p): # boucle sur les indices de colonnnes
            for k in range(c): # boucle sur les indices de couleurs
                NM[i][j][k] = M[n-1-i][j][k]
    return NM

def couleurVersNGris(M):
    """
        M : tableau à 3 dimensions codant pour une image en couleurs
        Retour : tableau à 2 dimensions codant pour la même image en
        niveau de gris selon la relation : 
            Gris = 0.2125*Rouge+0.7154*Vert+0.0721*Bleu
    """
    n,p,c = np.shape(M)
    NM = matriceGris(n,p)
    for i in range(n) : # boucle sur les indices de lignes
        for j in range(p) : # boucle sur les indices de colonnnes
            # on remplit le niveau de gris du pixel (i,j) de NM
            NM[i][j] = 0.2125*M[i][j][0]+0.7154*M[i][j][1]+0.0721*M[i][j][2]
    return NM

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.