24毛玻璃、浮雕和油漆特效

https://blog.csdn.net/Eastmount/article/details/89853630

一.图像毛玻璃特效

用图像邻域内随机一个像素点的颜色来替代当前像素点颜色的过程,
从而为图像增加一个毛玻璃模糊的特效。

#coding:utf-8
import cv2
import numpy as np

#读取原始图像
src = cv2.imread('C:/Users/31035/Desktop/yifei/01.jpg')

#新建目标图像
dst = np.zeros_like(src)

#获取图像行和列
rows, cols = src.shape[:2]

#定义偏移量和随机数
offsets = 5
random_num = 0

#毛玻璃效果: 像素点邻域内随机像素点的颜色替代当前像素点的颜色
for y in range(rows - offsets):
    for x in range(cols - offsets):
        random_num = np.random.randint(0,offsets)
        dst[y,x] = src[y + random_num,x + random_num]

#显示图像
cv2.imshow('src',src)
cv2.imshow('dst',dst)

cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

二.图像浮雕特效

通过勾画图像的轮廓,并降低周围的像素值,
从而产生一张具有立体感的浮雕效果图

#读取原始图像
img = cv2.imread('C:/Users/31035/Desktop/yifei/01.jpg')

#获取图像的高度和宽度
height, width = img.shape[:2]

#图像灰度处理
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

##创建目标图像
# dstImg = np.zeros((height,width,1),np.uint8)
#新建目标图像
dstImg = np.zeros_like(gray)

#浮雕特效算法:newPixel = grayCurrentPixel - grayNextPixel + 150
for i in range(0,height):
    for j in range(0,width-3):
        grayCurrentPixel = int(gray[i,j])
        grayNextPixel = int(gray[i,j+3])
        newPixel = grayCurrentPixel - grayNextPixel + 150
        if newPixel > 255:
            newPixel = 255
        if newPixel < 0:
            newPixel = 0
        dstImg[i,j] = newPixel
        
#显示图像
cv2.imshow('src', gray)
cv2.imshow('dst',dstImg)

#等待显示
cv2.waitKey()
cv2.destroyAllWindows()

在这里插入图片描述

三.图像油漆特效

图像油漆特效类似于油漆染色后的轮廓图形,
它主要采用自定义卷积核和cv2.filter2D()函数实现

img = cv2.imread('C:/Users/31035/Desktop/yifei/01.jpg')
#自定义卷积核
kernel = np.array([[-1,-1,-1],[-1,12,-1],[-1,-1,-1]])

#图像浮雕效果
output = cv2.filter2D(gray, -1, kernel)

#显示图像
cv2.imshow('Original Image', gray)
cv2.imshow('Emboss_1',output)

#等待显示
cv2.waitKey()
cv2.destroyAllWindows()
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值