1,浮雕效果实现:
.基本原理:根据像素与周围像素的差值确定像素值,差别较大的像素(边缘点通常像素差别较大)像素值较大,在灰度图中表现为较亮,边缘凸显,形成浮雕状,然后加上一个灰度偏移值,作为图片的整体底色。
实现公式:newP = gray0-gray1+150
代码实现如下:
import cv2
import numpy as np
img = cv2.imread('image0.jpg',1)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# newP = gray0-gray1+150
dst = np.zeros((height,width,1),np.uint8)
for i in range(0,height):for j in range(0,width-1):grayP0 &#61; int(gray[i,j])grayP1 &#61; int(gray[i,j&#43;1])newP &#61; grayP0-grayP1&#43;150if newP > 255:newP &#61; 255if newP <0:newP &#61; 0dst[i,j] &#61; newP
cv2.imshow(&#39;dst&#39;,dst)
cv2.waitKey(0)
实现结果如下&#xff1a;
2&#xff0c;改变rgb ->RGB new “蓝色”
#b&#61;b1.5
#g &#61; g1.3通过改变颜色效果&#xff1a;代码实现&#xff1a;
import cv2
import numpy as np
img &#61; cv2.imread(&#39;image0.jpg&#39;,1)
cv2.imshow(&#39;src&#39;,img)
imgInfo &#61; img.shape
height &#61; imgInfo[0]
width &#61; imgInfo[1]
dst &#61; np.zeros((height,width,3),np.uint8)
for i in range(0,height):for j in range(0,width):(b,g,r) &#61; img[i,j]b &#61; b*1.5g &#61; g*1.3if b>255:b &#61; 255if g>255:g &#61; 255dst[i,j]&#61;(b,g,r)
cv2.imshow(&#39;dst&#39;,dst)
cv2.waitKey(0)
实现效果如下&#xff1a;