No account yet ?
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 Kernel = [[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]] H = int(len(Kernel)) 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 + Kernel[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
Grayscale
Outline filter
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