Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the effect of Fuzzy Glass by Python

Shulou Source: shulou.com Published: 2022-06-03 17:57:36 09月25日 Update

This article is about how Python achieves the effect of blurred glass. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

This paper introduces a kind of image special effect of ground glass based on Gaussian filtering and neighborhood random sampling. to put it simply, the image is blurred by Gaussian filtering at first, and then the blurred image is endowed with the current pixel by random sampling in the neighborhood. In this way, the resulting image has a certain random disturbance and blur, which looks like observing the image through a layer of ground glass.

#-*-coding: utf-8-*-"Created on Sun Aug 20 11:03:53 2017@author: shiyi"import matplotlib.pyplot as pltfrom skimage.filters import gaussianfrom scipy.misc import imsave, imreadimport randomfile_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.shapep_size = 3for i in range (p_size, rows-p_size, 1): for j in range (p_size, cols-p_size 1): K1 = random.random ()-0.5k2 = random.random ()-0.5m=int (K1* (p_size*2-1)) n=int (K2* (p_size*2-1)) h = (isimm)% rows w = (junin)% cols img_out [I, j,:] = g_img [h, w,:] imsave ('out.jpg' Img_out) plt.figureplt.imshow (img_out) plt.show ()

Effect picture:

Effect picture:

The editor would like to share with you an example of the previous collection. Thank the original author for sharing.

# coding:utf-8''' frosted glass effect 'import cv2import numpy as np src = cv2.imread (' datas/images/f1.jpg') dst = np.zeros_like (src) rows,cols,_ = src.shapeoffsets = 5random_num = 0 for y in range (rows-offsets): for x in range (cols-offsets): random_num = np.random.randint (0mos offsets) dst [yMague x] = src [y + random_num] X + random_num] cv2.imshow ('src',src) cv2.imshow (' dst',dst) cv2.waitKey () cv2.destroyAllWindows ()

Thank you for reading! This is the end of this article on "how to achieve fuzzy glass effect in Python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Effects images ground glass content effects more articles neighborhood Gauss generation good practical pixels original original author examples that is articles special effects Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Information macOS MySQL vpn