Skip to content

Commit e4e7bdc

Browse files
authored
Add files via upload
1 parent e502ef5 commit e4e7bdc

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

blog24-tx/blog24-image02.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
import cv2
3+
import numpy as np
4+
5+
#读取原始图像
6+
img = cv2.imread('scenery.png', 1)
7+
8+
#获取图像的高度和宽度
9+
height, width = img.shape[:2]
10+
11+
#图像灰度处理
12+
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
13+
14+
#创建目标图像
15+
dstImg = np.zeros((height,width,1),np.uint8)
16+
17+
#浮雕特效算法:newPixel = grayCurrentPixel - grayNextPixel + 150
18+
for i in range(0,height):
19+
for j in range(0,width-1):
20+
grayCurrentPixel = int(gray[i,j])
21+
grayNextPixel = int(gray[i,j+1])
22+
newPixel = grayCurrentPixel - grayNextPixel + 150
23+
if newPixel > 255:
24+
newPixel = 255
25+
if newPixel < 0:
26+
newPixel = 0
27+
dstImg[i,j] = newPixel
28+
29+
#显示图像
30+
cv2.imshow('src', img)
31+
cv2.imshow('dst',dstImg)
32+
33+
#等待显示
34+
cv2.waitKey()
35+
cv2.destroyAllWindows()

blog24-tx/blog24-image03.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
import cv2
3+
import numpy as np
4+
5+
#读取原始图像
6+
src = cv2.imread('scenery.png')
7+
8+
#图像灰度处理
9+
gray = cv2.cvtColor(src,cv2.COLOR_BGR2GRAY)
10+
11+
#自定义卷积核
12+
kernel = np.array([[-1,-1,-1],[-1,10,-1],[-1,-1,-1]])
13+
14+
#图像浮雕效果
15+
output = cv2.filter2D(gray, -1, kernel)
16+
17+
#显示图像
18+
cv2.imshow('Original Image', src)
19+
cv2.imshow('Emboss_1',output)
20+
21+
#等待显示
22+
cv2.waitKey()
23+
cv2.destroyAllWindows()

blog24-tx/scenery.png

393 KB
Loading

0 commit comments

Comments
 (0)