Logo elodees  elodees

A caring AI for a better world













Only alphabetic characters accented or not as well as the space are accepted

Logo IA




Kirsch filter





No account yet ?

Sign up to access all content




Tested in Anaconda and 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()
 


Original image

Free image provided by pexel.com

Grayscale

Free image provided by pexel.com

N

Free image provided by pexel.com

NW

Free image provided by pexel.com


W

Free image provided by pexel.com

SW

Free image provided by pexel.com


S

Free image provided by pexel.com

SE

Free image provided by pexel.com


E

Free image provided by pexel.com

NE

Free image provided by pexel.com












Welcome, my name is Eric Soupet and I am the administrator of the site elodees.com. elodees.com is a state of the art of Artificial Intelligence and aims to be collaborative, you can now offer content such as articles, events, tutorials, ... so don't hesitate !

Platform images credit : Pixabay - Pixabay License | Pexels - Pexels License