import cv2 import numpy as np img = cv2.imread('image1.jpg',1) imgInfo = img.shape height = imgInfo[0] width = imgInfo[1] gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # newP = gray0-gray1+150 加上150是为了增强图片的浮雕灰度等级 # 相邻像素相减是为了突出灰度的凸片,即它的边缘特征. dst = np.zeros((height,width,1),np.uint8) for i in range(0,height): for j in range(0,width-1): grayP0 = int(gray[i,j)# 表明我们的当前像素 获取当前的灰度值 grayP1 = int(gray[i,j+1])# 表明下一个像素 newP = grayP0-grayP1+150 if newP > 255: newP = 255 if newP < 0: newP = 0 dst[i,j] = newP cv2.imshow('dst',dst) cv2.waitKey(0)
150就是当前的灰度值,边沿细节就是我们的相邻像素之差。
import cv2 import numpy as np img = cv2.imread('image2.jpg',1) imgInfo = img.shape height = imgInfo[0] width = imgInfo[1] gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # newP = gray0-gray1+150 加上150是为了增强图片的浮雕灰度等级 # 相邻像素相减是为了突出灰度的凸片,即它的边缘特征. dst = np.zeros((height,width,1),np.uint8) for i in range(0,height): for j in range(0,width-1): grayP0 = int(gray[i,j])# 表明我们的当前像素 获取当前的灰度值 grayP1 = int(gray[i,j+1])# 表明下一个像素 newP = grayP0-grayP1+150 if newP > 255: newP = 255 if newP < 0: newP = 0 dst[i,j] = newP cv2.imshow('dst',dst) cv2.waitKey(0)