'''
2019.11.22
'''
原理:高斯滤波+滤波算子+查找边缘
原图:
第一步:首先是图像预处理提取特征:img_processing.py
import cv2 as cv
from PIL import Image
import warnings
import numpy as np
import matplotlib.pyplot as plt
def pre_processing(image_path):
image=cv.imread(image_path)
image=np.array(image,dtype=np.uint8)
if image.shape[1]<image.shape[0]:
image=np.rot90(image) #矩阵旋转90
gray=cv.cvtColor(image,cv.COLOR_BGR2GRAY)
blur=cv.GaussianBlur(image,(13,13),0)
blur=cv.resize(blur,(0,0),fx=.1,fy=.1)
gray=cv.resize(gray,(0,0),fx=.1,fy=.1)
return gray,blur,image
from skimage.exposure import rescale_intensity
'''
函数convolve
功能:实现图像与卷积核的相乘,得到处理后的图像
'''
def convolve(image,kernel):
(iH,iW)=image.shape[:2]
(kH,kW)=kernel.shape[:2]
pad=(kW-1)/2
pad=int(pad)
image=cv.copyMakeBorder(image,pad,pad,pad,pad,cv.BORDER_REPLICATE)
output=np.zeros((iH,iW),dtype='float32')
for y in np.arange(pad,iH+pad):
for x in np.arange(pad,iW+pad):
roi=image[y-pad:y+pad+1,x-pad:x+pad+1]
k=(roi*kernel).sum()
output[y-pad,x-pad]=k
output=rescale_intensity(output,in_range=(0,255))