OpenCV入门(17):图片的浮雕效果

import cv2
import numpy as np

img = cv2.imread("./mm1.jpg",1)
cv2.imshow("src",img)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]

gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# 浮雕效果:每个新的像素值等于相邻两个像素之差减去一个固定值 newPixel = grayPixel_0 - grayPixel_1 + 固定值(起凸显作用)
dst = np.zeros((height,width,1),np.uint8)
for i in range(0,height):
    for j in range(0,width-1):
        grayPixel_0 = int(gray[i,j])
        grayPixel_1 = int(gray[i,j+1])
        newPixel = grayPixel_0 - grayPixel_1 + 150
        if newPixel > 255:
            newPixel = 255
        if newPixel < 0:
            newPixel = 0
        dst[i,j] = newPixel

cv2.imshow("dst",dst)
cv2.waitKey(0)

你可能感兴趣的:(OpenCV)