Today introduces a Gaussian filtering and neighborhood random sampling based on the generation of a kind of hairy glass image effects, in short, is the first Gaussian filter blurring of the image, and then the blurred image, through the random sampling of the neighborhood to give the current pixel points, so that the resulting image has a certain degree of random perturbation and blurring, it looks like a layer of hairy glass in the observation of the image as well.
# -*- coding: utf-8 -*- """ Created on Sun Aug 20 11:03:53 2017 @author: shiyi """ import as plt from import gaussian from import imsave, imread import random file_name='D:/Visual Effects/PS Algorithm/'; img=imread(file_name) g_img = gaussian(img, sigma=2, multichannel=True) img_out = g_img.copy() rows, cols, dpt = p_size = 3 for i in range(p_size, rows-p_size, 1): for j in range(p_size, cols-p_size, 1): k1= () - 0.5 k2= () - 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('', img_out) (img_out) ()
Rendering:
Rendering:
I'd like to share another example from a previous collection, thanks to the original author for sharing.
#coding:utf-8 ''' Hair glass effect ''' import cv2 import numpy as np src = ('datas/images/') dst = np.zeros_like(src) rows,cols,_ = offsets = 5 random_num = 0 for y in range(rows - offsets): for x in range(cols - offsets): random_num = (0,offsets) dst[y,x] = src[y + random_num,x + random_num] ('src',src) ('dst',dst) () ()
This is the whole content of this article.