We are creating a program that binarizes hundreds of images in black and white in python.I was able to binarize one image, but I would like to know a program that can binarize hundreds of images at once.After that, we would like to learn about the binarized image by finding the area of the black area and the length of the surrounding area.
The image is in the character area defined by C:\Users\LSL and is named AC001.png, AC002.png, AC003.png...
python python3 image
There are the following ways of thinking: What you want to do, what you have knowledge, and how long you can use it
and so on, and try to do it in a way that looks good.
1. It may have already been done, but the Python program for image processing is
Command-line parameters include input and output files with pathname
Allow to be specified.
Alternatively, enter the file name or image data itself from the standard input and
Output processing results to standard output.
複数Multiple file processing can be done by command line, batch file FOR statement, etc.
Create another program (Python, VB, C#, whatever) and then
Call the Python program for image processing with the target file as a parameter.
For example, if it's a command line FOR statement, the file to process the current folder
Make it a folder containing , and specify as follows:
When describing in a batch file, %I should be %%I.
FOR %I IN (AC*.png) DO Python Image Processing Program Pathname %I Output Folder\%I
2. Make the above image processing program functional and use the command line parameter
Add a main action that allows wildcards and folders to be specified and
Enable processing of multiple extracted files.
If you have additional subfolders, you can think of recursive processing.
Calling a program is the same command line or another program as above 1. Yes.
PUse Python os module listdir or glob module to
Create a list of files to be processed from what is specified in the parameter and
It is sequentially processed by an image processing function.
For example, extracting the relevant lines would look like this:
importos.path
import glob
files=glob.glob('C:\\Users\\LSL\\' + defined character space storage variable + '\\' + input file specified storage variable)
for inputfile in files:
outputfile = output folder name storage variable + '\\' + os.path.basename (inputfile)
Image processing function (inputfile, outputfile)
3. Add GUI to Python program for image processing
TkInter included in Python and external tools such as wxPython, PyQt, PyGTK, etc.
There are a variety of development environments, libraries, and tools. For example, this summary article
I have it for your reference.
Python GUI Toolkit Personal Comparison Summary
http://hennohito.cocolog-nifty.com/blog/2013/02/python-gui-f3c1.html
Select Python GUI Development Tools
https://51flya.com/python/248.html
If you search for it, you'll find many more.
© 2024 OneMinuteCode. All rights reserved.