Python图像特效之模糊玻璃效果
作者:Matrix_11 时间:2022-09-08 11:38:21
今天介绍一种基于高斯滤波和邻域随机采样,生成一种毛玻璃的图像特效,简单来说,就是先对图像做高斯滤波模糊,然后对模糊后的图像,通过对邻域的随机采样来赋予当前的像素点,这样,生成的图像有有一定的随机扰动和模糊,看起来就像隔着一层毛玻璃在观察图像一样。
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 20 11:03:53 2017
@author: shiyi
"""
import matplotlib.pyplot as plt
from skimage.filters import gaussian
from scipy.misc import imsave, imread
import random
file_name='D:/Visual Effects/PS Algorithm/4.jpg';
img=imread(file_name)
g_img = gaussian(img, sigma=2, multichannel=True)
img_out = g_img.copy()
rows, cols, dpt = img.shape
p_size = 3
for i in range(p_size, rows-p_size, 1):
for j in range(p_size, cols-p_size, 1):
k1= random.random() - 0.5
k2= random.random() - 0.5
m=int (k1*(p_size*2-1))
n=int (k2*(p_size*2-1))
h=(i+m) % rows
w=(j+n) % cols
img_out[i, j, :] = g_img[h, w, :]
imsave('out.jpg', img_out)
plt.figure
plt.imshow(img_out)
plt.show()
效果图:
效果图:
小编再为大家分享一段之前收藏的实例,感谢原作者的分享。
#coding:utf-8
'''
毛玻璃效果
'''
import cv2
import numpy as np
src = cv2.imread('datas/images/f1.jpg')
dst = np.zeros_like(src)
rows,cols,_ = src.shape
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()
来源:https://chenjunkai.blog.csdn.net/article/details/78345426
标签:python,模糊玻璃
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
pyspark操作hive分区表及.gz.parquet和part-00000文件压缩问题
2022-02-07 14:35:53
![](https://img.aspxhome.com/file/2023/0/79580_0s.png)
基于python 爬虫爬到含空格的url的处理方法
2023-04-16 09:55:47
使用beaker让Facebook的Bottle框架支持session功能
2023-07-01 02:35:35
python安装pillow的三种方法
2023-07-20 02:36:53
![](https://img.aspxhome.com/file/2023/5/79495_0s.png)
如何在Python3中使用telnetlib模块连接网络设备
2022-03-11 12:57:33
Python实现的十进制小数与二进制小数相互转换功能
2022-02-17 16:24:39
![](https://img.aspxhome.com/file/2023/9/115879_0s.jpg)
tf.concat中axis的含义与使用详解
2021-05-21 12:38:00
Python搭建代理IP池实现接口设置与整体调度
2023-05-25 11:52:03
![](https://img.aspxhome.com/file/2023/7/105617_0s.png)
php获取访问者IP地址汇总
2023-11-14 12:14:06
asp如何更好地保护我的网页?
2009-11-22 19:29:00
Python实现手写一个类似django的web框架示例
2022-06-18 03:17:26
![](https://img.aspxhome.com/file/2023/9/65049_0s.png)
PHP 应用容器化以及部署方法
2023-11-14 15:45:06
![](https://img.aspxhome.com/file/2023/8/80518_0s.jpg)
详解Python中的null是什么
2022-11-30 15:33:56
![](https://img.aspxhome.com/file/2023/0/67750_0s.png)
python3.7调试的实例方法
2022-09-22 17:16:24
![](https://img.aspxhome.com/file/2023/8/82758_0s.png)
Python获取单个程序CPU使用情况趋势图
2021-11-19 02:36:59
![](https://img.aspxhome.com/file/2023/4/115074_0s.png)
python+PyQT实现系统桌面时钟
2023-07-21 07:46:33
asp测字符串长度及截取定长字符串汉字的处理
2007-10-12 13:14:00
python中三种输出格式总结(%,format,f-string)
2022-06-11 16:34:40
![](https://img.aspxhome.com/file/2023/6/75356_0s.png)
python状态机transitions库详解
2021-07-14 15:52:16
php设计模式 Singleton(单例模式)
2023-11-20 14:37:50