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




Robinson filter





No account yet ?

Sign up to access all content




Tested in Anaconda and Python 3.7

# -*- coding: utf-8 -*-
"""
Created on Mon Sep 12 15:46:58 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 = [[ 1, 2, 1],
     [ 0, 0, 0],
     [-1,-2,-1]]
 
# North-West Direction Edge     
NW = [[ 2, 1, 0],
      [ 1, 0,-1],
      [ 0,-1,-2]]
 
# West Direction Edge     
W = [[ 1, 0,-1],
     [ 2, 0,-2],
     [ 1, 0,-1]]
 
# South-West Direction Edge     
SW = [[ 0,-1,-2],
      [ 1, 0,-1],
      [ 2, 1, 0]]      
 
# South Direction Edge     
S = [[-1,-2,-1],
     [ 0, 0, 0],
     [ 1, 2, 1]]
 
# South-East Direction Edge     
SE = [[-2,-1, 0],
      [-1, 0, 1],
      [ 0, 1, 2]]
 
# East Direction Edge     
E = [[-1, 0, 1],
     [-2, 0, 2],
     [-1, 0, 1]]
 
# North-East Direction Edge      
NE = [[ 0, 1, 2],
      [-1, 0, 1],
      [-2,-1, 0]]
 
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