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 add snow effects to images by Python

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

Share

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

This article mainly shows you the "Python how to add snow effects to the image", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Python how to add snow effects to the image" this article.

Introduction

Maybe it's for harmony, in the Beginning of Winter's world on this day.

In many cities in the north, the first snow of winter fell quietly, forming a melody.

After two seasons a day, the yellow leaves turn to flowers-falling from the sky, day and night, waking up one night, the eaves of the cabinet are dyed white, and the Imperial Palace completes the transition between autumn and winter.

Stories from the north came one after another.

Qionglou silver, whitewashed jade, unconsciously into the heaven fairyland, guests inside the palace wall, heavy traffic outside the palace wall, if the Imperial Palace as a heavenly palace

I don't feel cold in winter all night. (you can wear long johns .jpg)

(part of the material of this article is a friend at the Imperial Palace in Beijing, which has just been filmed during a visit today-- fresh out.

Let's go to several groups directly today about [the Imperial Palace, it's snowing! Give our friends in the south a close look at the snow picture of the Imperial Palace ~ I hope you like it!

Text

Have you ever been to the Forbidden City? If you haven't been there, follow the editor into the first snow bar of the Imperial Palace in Beijing ~ (I haven't seen it, I can only look at the picture)

No matter north or south, whether men or women, whether you have seen snow or not, we all seem to love her together, probably because in the long cold season

She is a surprise given by God, like the stars all over the night, like a rainbow after a storm.

1. Snow in the Imperial Palace: interface Mini Program 1) main program # initialize pygamepygame.init () # according to the size of the background picture Set screen length and width SIZE = (850,560) screen = pygame.display.set_mode (SIZE) pygame.display.set_caption ("it snows in the Imperial Palace-Mini Program") bg = pygame.image.load ('snow.jpg') # snowflake list snow_list = [] # initialize snowflakes: [X coordinates, y coordinates, x axis speed, y axis speed] for i in range (200): X = random.randrange (0 SIZE [0]) y = random.randrange (0, SIZE [1]) sx = random.randint (- 1,1) sy = random.randint (3,6) snow_list.append ([x, y, sx, sy]) clock = pygame.time.Clock () # Game main cycle done = Falsewhile not done: # message event loop Decide to exit for event in pygame.event.get (): if event.type = = pygame.QUIT: done = True # black background / picture background # screen.fill ((0,0,0)) screen.blit (bg, (0,0)) # snowflake list loop for i in range (len (snow_list)): # draw snowflake Color, position, size pygame.draw.circle (screen, (255,255,255), snow_ list [I] [: 2] Snow_ list [I] [3]-3) # move snowflake position (the next cycle takes effect) snow_ list [I] [0] + = snow_ list [I] [2] snow_ list [I] + = snow_ list [I] [3] # if the snowflake falls off the screen Reset position if snow_ list [I] [1] > SIZE [1]: snow_ list [I] [1] = random.randrange (- 50,-10) snow_ list [I] [0] = random.randrange (0, SIZE [0]) # Refresh screen pygame.display.flip () clock.tick (20) 2) effect display

Part 01 shows--

Part 02 shows--

Second, snow in the Imperial Palace: hand-drawn sketch 1) the main program root = tkinter.Tk (). Withdraw () filename = tkinter.filedialog.askopenfilename () # Open the select file dialog box try: depth = 30 # 0-100, the higher The darker the color, picture_grad = np.gradient (np.asarray (Image.open (filename). Convert ('L')). Astype ('int')) # take the grayscale gradient of the image grad_x, grad_y = picture_grad [0] * depth / 100, picture_grad [1] * depth / 100. # Deep processing the acquired dimensional gradient value base = np.sqrt (grad_x * * 2 + grad_y * * 2 + 1.) # noise reduction basis _ x, _ y, _ z = grad_x / base, grad_y / base, 1. / base sce_z, sce_x = np.pi / 2.1, np.pi / 3 # overlooking angle value and azimuth angle value of the light source Influence of z-axis dx, dy, dz = np.cos (sce_z) * np.cos (sce_x), np.cos (sce_z) * np.sin (sce_x), np.sin (sce_z) Normalized = 255* (dx * _ x + dy * _ y + dz * z) .clip (0 # Light normalized im = Image.fromarray (Normalized.astype ('uint8')) # reconstructed image im.save (' converted sketch .jpg') # Save converted image im.show () # display converted image except Exception: print ('conversion failed!') 2) effect display

Part 01 shows--

Part 02 shows--

The above is all the content of the article "how to add snow effects to images by Python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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