-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCanny.py
More file actions
49 lines (35 loc) · 1.41 KB
/
Canny.py
File metadata and controls
49 lines (35 loc) · 1.41 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
"""
Created on Fri May 7 17:42:39 2021
@author: VArri
Simple Edge Enhancing Technique as preprocessing for PLD. First step is to
compute a slight Gaussian Blur as an average image, then substract it to the
original image with addweighted weights to keep the same level of luminosity.
Fast and simple technique.
Simple Canny Edge Detection is also availbale but is not that useful for PLD
"""
import cv2
# import matplotlib.pyplot as plt
# import numpy as np
import os
def EdgeEnhancing(path, image_path):
img = cv2.imread(image_path)
# gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.resize(img, dsize = (int(img.shape[1]*0.25), int(img.shape[0]*0.25)))
#edge = cv2.Canny(gray, 100, 200)
blur = cv2.GaussianBlur(img,(5,5),0)
smooth = cv2.addWeighted(img,1.5,blur,-0.5,0)
# https://stackoverflow.com/questions/4993082/how-can-i-sharpen-an-image-in-opencv
filename, file_extension = os.path.splitext(os.path.basename(image_path))
output_path = os.path.join(path, 'edge1000', filename+'_edge.jpg')
cv2.imwrite(output_path, smooth)
os.chdir(r"C:\Users\VArri\Documents\PowerLines\images\visuel")
path = os.getcwd()
basis_dir = os.path.join(path, 'basis')
dirs = os.listdir(basis_dir)
for di in dirs:
image_path = os.path.join(basis_dir, di)
#print(di)
#print(image_path)
#break
EdgeEnhancing(path, image_path)