A png 16-bit grayscale image needs to be processed at work, because the processing program has been written in Python and Pil many days ago, but some parameters are hard to remember because it takes too long. When parameters are added together with the above parameters, you can see that errors are always reported when you read and copy PNG files during the running process. After searching, I quickly found out that the original file format was not suitable. I used a 16-bit grayscale image and quickly went to the Pil document to check it, the file formats and types supported by PIL in this document are not 16 bits, and there is no suitable conversion format:
From "Python imaging library overview, pil1.1.3"
When I was in a hurry, I suddenly remembered that Pil is also open-source. Hurry to the installation directory and check it out. I soon found the parsing code (pngimageplugin. py) of the PNG file in it. The definition of the file format is much richer than that in the document:
_ Modes = {
# Supported bits/color combinations, and corresponding modes/rawmodes
(1, 0): ("1", "1 "),
(2, 0): ("L", "l; 2 "),
(4, 0): ("L", "l; 4 "),
(8, 0): ("L", "L "),
(16, 0): ("I", "I; 16B "),
(8, 2): ("RGB", "RGB "),
(16, 2): ("RGB", "RGB; 16B "),
(1, 3): ("P", "P; 1 "),
(2, 3): ("P", "P; 2 "),
(4, 3): ("P", "P; 4 "),
(8, 3): ("P", "P "),
(8, 4): ("La", "La "),
(16, 4): ("rgba", "La; 16B"), # La; 16B-> La not yet available
(8, 6): ("rgba", "rgba "),
(16, 6): ("rgba", "rgba; 16B "),
}
It not only supports 16-bit grayscale images, but also supports rgb16-bit images. It is estimated that HDR is enough for Continuous Cropping. Haha. It is also very simple to use. Reading a file can be automatically identified. When creating a file, you only need to declare its mode as "I; 16B.
Note that in the 16-bit grayscale image processed by Pil, the image data must be saved as the background of the image rather than other layers, otherwise, Pil reads and processes the graph in rgb8 format.