zoukankan      html  css  js  c++  java
  • Python: PS 图像特效 — 模糊玻璃

    今天介绍一种基于高斯滤波和邻域随机采样,生成一种毛玻璃的图像特效,简单来说,就是先对图像做高斯滤波模糊,然后对模糊后的图像,通过对邻域的随机采样来赋予当前的像素点,这样,生成的图像有有一定的随机扰动和模糊,看起来就像隔着一层毛玻璃在观察图像一样。

    # -*- 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()

    这里写图片描述

    效果图:
    这里写图片描述

  • 相关阅读:
    html5css练习 旋转
    html5 css练习 画廊 元素旋转
    html5 渐变按钮练习
    html5 旋转导航练习
    html5 javascript 表单练习案例
    html5 p1练习1,移动页面,标准标签布局
    pyqt5desinger的安装即配置
    python 文件操作
    openGL 大作业之n星变换
    openGL 蓝天白云
  • 原文地址:https://www.cnblogs.com/mtcnn/p/9412383.html
Copyright © 2011-2022 走看看