Bonjour,

Je suis débutante en Python et je dois programmer un filtre passe-haut dans ce langage en utilisant scipy.misc pour gérer l'image et non le module Image. Voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
33
34
 
import numpy as np
from scipy import misc
import matplotlib.pyplot as plt
 
img = misc.imread("fichier_initial.png")
 
Filtre = [[0, -4, 0], [-4, 18, -4], [0, -4, 0]]
 
 
def convolution2D(Filtre, TPix, x, y):
    p0 = p1 = p2 = 0
    for i in range(-1, 1):
        for j in range(-1, 1):
            p0 += Filtre[i + 1][j + 1] * TPix[x + j, y + i][0]
            p1 += Filtre[i + 1][j + 1] * TPix[x + j, y + i][1]
            p2 += Filtre[i + 1][j + 1] * TPix[x + j, y + i][2]
    p0 = int(p0 / 9.0)
    p1 = int(p1 / 9.0)
    p2 = int(p2 / 9.0)
    return (p0, p1, p2)
 
 
def filtre_convolution(img_orig):
    im = np.copy(img_orig)  # On fait une copie de l'original
    for x in range(1, img_orig.shape[0] - 1):
        for y in range(1, img_orig.shape[1] - 1):
            p = convolution2D(Filtre, img_orig, x, y)
            im[x, y] = p
    return im
 
image = filtre_convolution(img)
plt.imshow(image)
plt.show()
Dans l'absolu le code fonctionne, il donne quelque chose. Mais ce n'est pas le bon résultat, autrement dit ce n'est pas ce qui est attendu avec un filtre passe-haut. Cela fait un moment que je travaille dessus et je ne trouve pas la solution ni pourquoi il y a cette pixélisation.
Est-ce que quelqu'un pourrait m'aider s'il vous plait?
Merci d'avance.