Skip to content

Commit 78d5da4

Browse files
authored
Create blog15-image01.py
1 parent 246c330 commit 78d5da4

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

blog15-gray/blog15-image01.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
import cv2
3+
import numpy as np
4+
import matplotlib.pyplot as plt
5+
6+
#读取原始图像
7+
img = cv2.imread('miao.jpg')
8+
9+
#图像灰度转换
10+
grayImage = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
11+
12+
#获取图像高度和宽度
13+
height = grayImage.shape[0]
14+
width = grayImage.shape[1]
15+
16+
#创建一幅图像
17+
result = np.zeros((height, width), np.uint8)
18+
19+
#图像灰度上移变换 DB=DA+50
20+
for i in range(height):
21+
for j in range(width):
22+
23+
if (int(grayImage[i,j]+50) > 255):
24+
gray = 255
25+
else:
26+
gray = int(grayImage[i,j]+50)
27+
28+
result[i,j] = np.uint8(gray)
29+
30+
#显示图像
31+
cv2.imshow("Gray Image", grayImage)
32+
cv2.imshow("Result", result)
33+
34+
#等待显示
35+
cv2.waitKey(0)
36+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)