opencv图像处理浮雕效果
浮雕效果是将俩个像素差值加上某一个固定的像素值。
import cv2
import numpy as np
import random
import math
img0 = cv2.imread(r"C:\Users\lenovo\Desktop\python\python_vision\image.jpg",1)
imgInfo = img0.shape
height = imgInfo[0]
weight = imgInfo[1]
# 转换灰度图像 2.高斯滤波
gray = cv2.cvtColor(img0,cv2.COLOR_RGB2GRAY)
dst = np.zeros((height,weight,1),np.uint8)
for i in range(0,height):
for j in range(0,weight-5):
grayp0 = int(gray[i,j])
grayp1 = int(gray[i,j+5])
newp = grayp0-grayp1 +100
if newp > 255:
newp = 255
if newp <0:
newp =0
dst[i,j] = newp
cv2.imshow("dst",dst)
cv2.waitKey()
公式:
浮雕效果展示:
核心代码展示:
for i in range(0,height):
for j in range(0,weight-5):
grayp0 = int(gray[i,j])
grayp1 = int(gray[i,j+5])
newp = grayp0-grayp1 +100
if newp > 255:
newp = 255
if newp <0:
newp =0
dst[i,j] = newp