Logo elodees  elodees

Une IA bien-veillante pour un monde meilleur













Seuls les caractères alphabétiques accentués ou non ainsi que l'espace sont acceptés

Logo IA




Filtre de Kirsch





Pas encore de compte ?

Inscrivez-vous pour accéder à tous les contenus




Testé sous Anaconda et Python 3.7

# -*- coding: utf-8 -*-
"""
Created on Sat Aug 27 11:18:35 2022
 
@author: elodees
"""
 
import cv2
import numpy as np
from matplotlib import pyplot as plt
from PIL import Image
 
img = cv2.imread("city.jpg")
 
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.axis('off')
plt.title('Originale image')
plt.show()
 
height, width, depth = np.shape(img)
 
new_im = Image.new('RGB', (width, height))
 
pixel_map = new_im.load()
 
# North Direction Edge
N = [[ 5, 5, 5],
     [-3, 0,-3],
     [-3,-3,-3]]
 
# North-West Direction Edge     
NW = [[ 5, 5,-3],
      [ 5, 0,-3],
      [-3,-3,-3]]
 
# West Direction Edge     
W = [[ 5,-3,-3],
     [ 5, 0,-3],
     [ 5,-3,-3]]
 
# South-West Direction Edge     
SW = [[-3,-3,-3],
      [ 5, 0,-3],
      [ 5, 5,-3]]      
 
# South Direction Edge     
S = [[-3,-3,-3],
     [-3, 0,-3],
     [ 5, 5, 5]]
 
# South-East Direction Edge     
SE = [[-3,-3,-3],
      [-3, 0, 5],
      [-3, 5, 5]]
 
# East Direction Edge     
E = [[-3,-3, 5],
     [-3, 0, 5],
     [-3,-3, 5]]
 
# North-East Direction Edge      
NE = [[-3, 5, 5],
      [-3, 0, 5],
      [-3,-3,-3]]
 
H = int(len(N))
 
for j in range(0, width - H):
    for i in range(0, height - H):
 
        summ = 0
 
        for k in range(0, H):
            for l in range(0, H):
 
                # RGB to Gray
                img[i+k][j+l][0] = img[i+k][j+l][1] = img[i+k][j+l][2] = 0.2989 * img[i+k][j+l][0] + 0.5870 * img[i+k][j+l][1] + 0.1140 * img[i+k][j+l][2]
 
                summ = summ + N[k][l] * img[i+k][j+l][0]
 
        if(summ > 255):
           summ = 255
 
        if(summ < 0):
           summ = 0
 
        pixel_map[j, i] = (summ, summ, summ)
 
plt.imshow(new_im)
plt.axis('off')
plt.show()
 
new_im = Image.new('RGB', (width, height))
 
pixel_map = new_im.load()
 
for j in range(0, width - H):
    for i in range(0, height - H):
 
        summ = 0
 
        for k in range(0, H):
            for l in range(0, H):
 
                img[i+k][j+l][0] = img[i+k][j+l][1] = img[i+k][j+l][2] = 0.2989 * img[i+k][j+l][0] + 0.5870 * img[i+k][j+l][1] + 0.1140 * img[i+k][j+l][2]
 
                summ = summ + NW[k][l] * img[i+k][j+l][0]
 
        if(summ > 255):
           summ = 255
 
        if(summ < 0):
           summ = 0
 
        pixel_map[j, i] = (summ, summ, summ)
 
plt.imshow(new_im)
plt.axis('off')
plt.show()
 
new_im = Image.new('RGB', (width, height))
 
pixel_map = new_im.load()
 
for j in range(0, width - H):
    for i in range(0, height - H):
 
        summ = 0
 
        for k in range(0, H):
            for l in range(0, H):
 
                img[i+k][j+l][0] = img[i+k][j+l][1] = img[i+k][j+l][2] = 0.2989 * img[i+k][j+l][0] + 0.5870 * img[i+k][j+l][1] + 0.1140 * img[i+k][j+l][2]
 
                summ = summ + W[k][l] * img[i+k][j+l][0]
 
        if(summ > 255):
           summ = 255
 
        if(summ < 0):
           summ = 0
 
        pixel_map[j, i] = (summ, summ, summ)
 
plt.imshow(new_im)
plt.axis('off')
plt.show()
 
new_im = Image.new('RGB', (width, height))
 
pixel_map = new_im.load()
 
for j in range(0, width - H):
    for i in range(0, height - H):
 
        summ = 0
 
        for k in range(0, H):
            for l in range(0, H):
 
                img[i+k][j+l][0] = img[i+k][j+l][1] = img[i+k][j+l][2] = 0.2989 * img[i+k][j+l][0] + 0.5870 * img[i+k][j+l][1] + 0.1140 * img[i+k][j+l][2]
 
                summ = summ + SW[k][l] * img[i+k][j+l][0]
 
        if(summ > 255):
           summ = 255
 
        if(summ < 0):
           summ = 0
 
        pixel_map[j, i] = (summ, summ, summ)
 
plt.imshow(new_im)
plt.axis('off')
plt.show()
 
new_im = Image.new('RGB', (width, height))
 
pixel_map = new_im.load()
 
for j in range(0, width - H):
    for i in range(0, height - H):
 
        summ = 0
 
        for k in range(0, H):
            for l in range(0, H):
 
                img[i+k][j+l][0] = img[i+k][j+l][1] = img[i+k][j+l][2] = 0.2989 * img[i+k][j+l][0] + 0.5870 * img[i+k][j+l][1] + 0.1140 * img[i+k][j+l][2]
 
                summ = summ + S[k][l] * img[i+k][j+l][0]
 
        if(summ > 255):
           summ = 255
 
        if(summ < 0):
           summ = 0
 
        pixel_map[j, i] = (summ, summ, summ)
 
plt.imshow(new_im)
plt.axis('off')
plt.show()
 
new_im = Image.new('RGB', (width, height))
 
pixel_map = new_im.load()
 
for j in range(0, width - H):
    for i in range(0, height - H):
 
        summ = 0
 
        for k in range(0, H):
            for l in range(0, H):
 
                img[i+k][j+l][0] = img[i+k][j+l][1] = img[i+k][j+l][2] = 0.2989 * img[i+k][j+l][0] + 0.5870 * img[i+k][j+l][1] + 0.1140 * img[i+k][j+l][2]
 
                summ = summ + SE[k][l] * img[i+k][j+l][0]
 
        if(summ > 255):
           summ = 255
 
        if(summ < 0):
           summ = 0
 
        pixel_map[j, i] = (summ, summ, summ)
 
plt.imshow(new_im)
plt.axis('off')
plt.show()
 
new_im = Image.new('RGB', (width, height))
 
pixel_map = new_im.load()
 
for j in range(0, width - H):
    for i in range(0, height - H):
 
        summ = 0
 
        for k in range(0, H):
            for l in range(0, H):
 
                img[i+k][j+l][0] = img[i+k][j+l][1] = img[i+k][j+l][2] = 0.2989 * img[i+k][j+l][0] + 0.5870 * img[i+k][j+l][1] + 0.1140 * img[i+k][j+l][2]
 
                summ = summ + E[k][l] * img[i+k][j+l][0]
 
        if(summ > 255):
           summ = 255
 
        if(summ < 0):
           summ = 0
 
        pixel_map[j, i] = (summ, summ, summ)
 
plt.imshow(new_im)
plt.axis('off')
plt.show()
 
new_im = Image.new('RGB', (width, height))
 
pixel_map = new_im.load()
 
for j in range(0, width - H):
    for i in range(0, height - H):
 
        summ = 0
 
        for k in range(0, H):
            for l in range(0, H):
 
                img[i+k][j+l][0] = img[i+k][j+l][1] = img[i+k][j+l][2] = 0.2989 * img[i+k][j+l][0] + 0.5870 * img[i+k][j+l][1] + 0.1140 * img[i+k][j+l][2]
 
                summ = summ + NE[k][l] * img[i+k][j+l][0]
 
        if(summ > 255):
           summ = 255
 
        if(summ < 0):
           summ = 0
 
        pixel_map[j, i] = (summ, summ, summ)
 
plt.imshow(new_im)
plt.axis('off')
plt.show()
 


Image originale

Image gratuite et libre de droits fournie par pexel.com

Nuances de gris

Image gratuite et libre de droits fournie par pexel.com

N

Image gratuite et libre de droits fournie par pexel.com

NW

Image gratuite et libre de droits fournie par pexel.com


W

Image gratuite et libre de droits fournie par pexel.com

SW

Image gratuite et libre de droits fournie par pexel.com


S

Image gratuite et libre de droits fournie par pexel.com

SE

Image gratuite et libre de droits fournie par pexel.com


E

Image gratuite et libre de droits fournie par pexel.com

NE

Image gratuite et libre de droits fournie par pexel.com












Bienvenu, je m’appelle Eric Soupet et je suis l'administrateur du site elodees.com. elodees.com est un état de l'art de l'Intelligence Artificielle et se veut collaboratif, vous pouvez dès à présent proposer du contenu tels que des articles, des événements, des tutoriels, ... alors n'hésitez pas !

Crédit des images de la plate-forme : Pixabay - Pixabay License | Pexels - Pexels License