In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you how to use Python image processing, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Python image processing is an easy to learn and powerful interpretive programming language. It has concise syntax, efficient high-level data structure, and can realize object-oriented programming simply and effectively. Python image processing is described below.
Of course, first of all, I would like to thank "Flower Butterfly" for his article "using Python Image processing" to help me strengthen my idea of solving problems with Python and PIL. You can take a look at this article for some introduction and basic operation of PIL. My main purpose here is to introduce my experience in the process of using it.
PIL can convert the color of the image, and supports modes such as 24-bit color, 8-bit grayscale image and binary image. Simple conversion can be completed through the Image.convert (mode) function, where mode represents the color mode of the output. For example, 'Lemma' represents grayscale, '1percent' represents binary pattern, and so on.
However, when the grayscale image is converted into binary image by using convert function, the fixed threshold value of 127is adopted, that is, the pixel value of gray level higher than 127is 1, while the pixel value of gray level lower than 127is 0. In order to realize the conversion from grayscale image to binary image through custom threshold, it is necessary to use Image.point function.
The Image.point function has many forms. Here we only discuss Image.point (table, mode). Using this function, we can realize the mode conversion of pixel color by looking up the table. Where table is the mapping table in the color conversion process, each color channel should have 256elements, and mode represents the output color mode, similarly, 'gray' represents grayscale, and '1pixel' represents binary image mode.
It can be seen that the key to the conversion process is to design the mapping table. If only a simple clamp value is needed, the elements above or below the clamp value in table can be set to 1 and 0 respectively. Of course, since there are no special requirements for table here, you can achieve any desired one-to-one mapping within the range of (0,255) by setting special settings for elements.
The sample code is as follows:
Import Image # load a color image im = Image.open (''fun.jpg'') # convert to grey level image Lim = im.convert (' 'fun_Level.jpg''') Lim.save (''fun_Level.jpg'') # setup a converting table with constant threshold threshold = 80 table = [] for i in range: if I < threshold: table.append (0) else: table.append (1) # Convert to binary image by the table bim = Lim.point (table '1percent') bim.save (fun_binary.jpg'')
It has become an open secret that the tasks that IT parts usually have to accomplish are quite onerous, but there are few resources to support them. Any IT solution that promises to improve coding efficiency and reduce the total cost of software should be carefully considered. One of the significant advantages of Python image processing is that it can save a lot of money in the software creation and maintenance phase of the enterprise, and the software cost of these two stages accounts for 50% to 95% of the total cost of the software throughout the life cycle.
Python's clear and readable syntax makes the software code unusually readable, even for programmers who are not originally exposed to and developed the original project. Although some programmers object to the heavy use of spaces in Python code.
However, almost everyone agrees that Python image processing is far more readable than C or Java, both of which use special characters to mark the beginning and end of code block structures, loops, functions, and other programming structures. Proponents of Python also claim that the adoption of these characters can lead to significant programming style differences, making it difficult for those responsible for maintaining the code to be readable.
On how to use Python image processing to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it 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.
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.