Python: PS 滤镜--表面模糊

本文用 Python 实现 PS 滤镜中的表面模糊,具体的算法原理和效果可以参考之前的博客:

http://blog.csdn.net/matrix_space/article/details/52818857

import matplotlib.pyplot as plt
from skimage import io
import numpy as np
import numpy.matlib

file_name='D:/Visual Effects/PS Algorithm/1.jpg';
img=io.imread(file_name)

def Sur_blur ( I_in, thre, half_size):
    I_out = I_in * 1.0
    row, col = I_in.shape
    w_size = half_size * 2 + 1
    for ii in range (half_size, row-1-half_size):
        for jj in range (half_size, col-1-half_size):
            aa = I_in [ii-half_size:ii+half_size+1, jj-half_size : jj+half_size+1]
            p0 = I_in [ii, jj]
            mask_1 = numpy.matlib.repmat(p0, w_size, w_size)
            mask_2 = 1-abs(aa-mask_1)/(2.5*thre);
            mask_3 = mask_2 * (mask_2 > 0)
            t1 = aa * mask_3
            I_out[ii, jj] = t1.sum()/mask_3.sum()

    return I_out

img_out = img * 1.0
thre = 20
half_size =10 
img_out[:, :, 0] = Sur_blur (img[:, :, 0], thre, half_size)
img_out[:, :, 1] = Sur_blur (img[:, :, 1], thre, half_size)
img_out[:, :, 2] = Sur_blur (img[:, :, 2], thre, half_size)

img_out = img_out/255

plt.figure(1)
plt.imshow(img)
plt.axis('off')

plt.figure(2)
plt.imshow(img_out)
plt.axis('off')

plt.show()


转载于:https://www.cnblogs.com/mtcnn/p/9412384.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值