学习Python你必须了解的lenna小姐姐

2.截图显示

img_crop = img[0:100, 0:200]

cv2.imshow(‘lena_crop’,img_crop)

# 判断键盘按键   如果是27 esc 则退出游戏

key = cv2.waitKey()

if key == 27:

cv2.destroyAllWindows()

3.RGB转换

B,G,R = cv2.split(img)

cv2.imshow(‘B’,B)

cv2.imshow(‘G’,R)

cv2.imshow(‘R’,R)

key = cv2.waitKey()

if key == 27:

cv2.destroyAllWindows()

4.加入滤镜

def random_light_color(img):

# brightness

B, G, R = cv2.split(img)

b_rand = random.randint(-50, 50)

if b_rand == 0:

pass

elif b_rand > 0:

lim = 255 - b_rand

B[B > lim] = 255

B[B <= lim] = (b_rand + B[B <= lim]).astype(img.dtype)

elif b_rand < 0:

lim = 0 - b_rand

B[B < lim] = 0

B[B >= lim] = (b_rand + B[B >= lim]).astype(img.dtype)

g_rand = random.randint(-50, 50)

if g_rand == 0:

pass

elif g_rand > 0:

lim = 255 - g_rand

G[G > lim] = 255

G[G <= lim] = (g_rand + G[G <= lim]).astype(img.dtype)

elif g_rand < 0:

lim = 0 - g_rand

G[G < lim] = 0

G[G >= lim] = (g_rand + G[G >= lim]).astype(img.dtype)

r_rand = random.randint(-50, 50)

if r_rand == 0:

pass

elif r_rand > 0:

lim = 255 - r_rand

R[R > lim] = 255

R[R <= lim] = (r_rand + R[R <= lim]).astype(img.dtype)

elif r_rand < 0:

lim = 0 - r_rand

R[R < lim] = 0

R[R >= lim] = (r_rand + R[R >= lim]).astype(img.dtype)

img_merge = cv2.merge((B, G, R))

#img = cv2.cvtColor(final_hsv, cv2.COLOR_HSV2BGR)

return img_merge

img_random_color = random_light_color(img)

cv2.imshow(‘img_random_color’, img_random_color)

key = cv2.waitKey()

if key == 27:

cv2.destroyAllWindows()

5.gamma校正

def adjust_gamma(image, gamma=1.0):

invGamma = 1.0 / gamma

table = []

for i in range(256):

table.append(((i / 255.0) ** invGamma) * 255)

table = np.array(table).astype(“uint8”)

return cv2.LUT(img_dark, table)

img_dark = cv2.imread(‘material/lenna.jpg’)

cv2.imshow(‘img_dark’, img_dark)

img_brighter = adjust_gamma(img_dark, 2)

cv2.imshow(‘img_dark’, img_dark)

cv2.imshow(‘img_brighter’, img_brighter)

key = cv2.waitKey()

if key == 27:

cv2.destroyAllWindows()

6.图像旋转

M = cv2.getRotationMatrix2D((img.shape[1] / 2, img.shape[0] / 2), 30, 1)  # center, angle, scale

img_rotate = cv2.warpAffine(img, M, (img.shape[1], img.shape[0]))

cv2.imshow(‘rotated lenna’, img_rotate)

key = cv2.waitKey(0)

if key == 27:

cv2.destroyAllWindows()

7.仿射变换

rows, cols, ch = img.shape

pts1 = np.float32([[0, 0], [cols - 1, 0], [0, rows - 1]])

pts2 = np.float32([[cols * 0.2, rows * 0.1], [cols * 0.9, rows * 0.2], [cols * 0.1, rows * 0.9]])

M = cv2.getAffineTransform(pts1, pts2)

dst = cv2.warpAffine(img, M, (cols, rows))

cv2.imshow(‘affine lenna’, dst)

key = cv2.waitKey(0)

if key == 27:

cv2.destroyAllWindows()

8.透视变化

def random_warp(img, row, col):

height, width, channels = img.shape

# warp:

random_margin = 60

在这里插入图片描述

感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的:

① 2000多本Python电子书(主流和经典的书籍应该都有了)

② Python标准库资料(最全中文版)

③ 项目源码(四五十个有趣且经典的练手项目及源码)

④ Python基础入门、爬虫、web开发、大数据分析方面的视频(适合小白学习)

⑤ Python学习路线图(告别不入流的学习)

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里无偿获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 7
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值