View and change the current working path
path="D:\\python-file\\faker" os.chdir(path) retval=os.getcwd() print(retval)
Glob usage:
glob.glob(path+r ' *.jpg ' )
I am here to get all the jpg files under the path
python reads image:
Python can use the two libraries matplotlib and PIL to manipulate pictures, here use PIL
For color images, no matter the image format is PNG, BMP, or JPG, in PIL, after using the open() function of the Image module to open, the mode of the returned image object is "RGB". For grayscale images, no matter the image format is PNG, BMP, or JPG, after opening, its mode is "L"
There are nine different modes in PIL. 1, L, P, RGB, RGBA, CMYK, YCbCr, I, F respectively.
Read every image in the directory
for name in glob.glob(path+r'*.jpg'): im = Image.open(name)
Grayscale
im_grey = im.convert('L')
You can also directly:
im = Image.open(name).convert('L')
pending upgrade