欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python圖像特效之模糊玻璃效果

 更新時(shí)間:2021年09月06日 14:42:05   作者:Matrix_11  
這篇文章主要為大家詳細(xì)介紹了Python圖像特效之模糊玻璃效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

今天介紹一種基于高斯濾波和鄰域隨機(jī)采樣,生成一種毛玻璃的圖像特效,簡(jiǎn)單來(lái)說(shuō),就是先對(duì)圖像做高斯濾波模糊,然后對(duì)模糊后的圖像,通過(guò)對(duì)鄰域的隨機(jī)采樣來(lái)賦予當(dāng)前的像素點(diǎn),這樣,生成的圖像有有一定的隨機(jī)擾動(dòng)和模糊,看起來(lái)就像隔著一層毛玻璃在觀察圖像一樣。

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

效果圖:

效果圖:

小編再為大家分享一段之前收藏的實(shí)例,感謝原作者的分享。

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

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論