Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the effect of Fuzzy Glass by Python

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report