In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
It is believed that many inexperienced people don't know what to do about how to modify the brightness and saturation of pictures in batches in Python. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
1. Prepare for
Before you begin, make sure that Python and pip are successfully installed on your computer. Oh, if not, please visit this article: hyperdetailed Python installation Guide for installation.
Open Cmd in Windows environment (start-run-CMD), open Terminal in Apple system environment (enter Terminal in command+ space). Enter the following command to install the modules we need:
Pip install numpy
Pip install opencv-python
If you see Successfully installed xxx, the installation is successful.
two。 Develop brightness and saturation adjustment tools
In this part, we will develop a tool that can adjust the brightness and saturation of the image, and this tool supports sliding adjustment. Actually, it's a small project in other languages, but in Python, we can solve it in 50 lines of code.
The first step is to load the picture, and then you need to convert the picture to HLS mode to adjust the brightness and saturation. This is because the default image color space is RGB, which is very suitable for display, but because there are only three color categories, it is not suitable for image processing.
The HLS mode is much more complex than the RGB color space. HLS stands for H: Hue (hue), L: Lightness (luminance) and S: Saturation (saturation), respectively. Its color space is a three-dimensional space, as shown in the following figure:
This color space allows us to adjust the details of the picture. In Python code, it is easy to convert RGB to HLS space, which can be done in two lines of code:
Then we need to make two sliders, one to adjust the brightness and one to adjust the saturation:
The original image needs to be saved before adjustment, so we will copy a new variable in memory to adjust the image, then get the values of the two sliders, and then adjust the brightness and saturation according to the values:
The effect is shown in the following figure:
This is not enough, because it is a tuning supported by the while loop, we also need to make it available to exit and save:
In this way, press the s key to save the picture and exit, and press the ESC key to exit the editor directly. Complete text version of 50 lines of code, please reply in the official account of Python practical Treasure Code: batch modify pictures to get.
3. Batch modification
Previously, according to our gadget to get the desired saturation and brightness, write down this pair of values and you can batch modify the image. Of course, we don't have the feature to automatically modify the correct value to such an inverse value. This tool is only suitable for images that can be adjusted with the same pair of brightness and saturation in the same scene:
This part is simpler than the tool just made, and it can be said to be a simplified version of the tool. It is divided into six steps:
1. Load the picture.
two。 Convert to HLS space.
3. Adjust the brightness.
4. Adjust the saturation.
5. Convert to RGB space.
6. Save.
Then we only need to transfer the images to this function in batches to achieve batch conversion:
After reading the above, have you mastered how to modify the brightness and saturation of pictures in batch in Python? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.