Is there a way to read the pixel colours values of an image without using any external libraries?
Asked
Active
Viewed 356 times
0
-
What is the motivation for doing this please? And what are the constraints of the problem? – Mark Setchell Jan 07 '21 at 15:50
-
I need to process a set of images, bringing images to the same size. – Marius Vuscan Jan 07 '21 at 16:01
-
My only constraint is to do this from scratch. – Marius Vuscan Jan 07 '21 at 16:09
-
1Libraries are designed, debugged, tested and improved over time. I would recommend you use them as you can *"see further standing on the shoulders of giants"* - **Isaac Newton**. – Mark Setchell Jan 07 '21 at 16:28
-
I’m voting to close this question because it is way too broad for Stack Overflow to write image editing software for JPEG, PNG, TIFF, TGA, PSD, PPM, WEBP, BMP without using libraries. – Mark Setchell Jan 07 '21 at 16:31
-
I agree, it's difficult to do this without an external library. I just thought that maybe someone has already done such an implementation, of reading the pixel colour values, at least for one format and it's happy to share. – Marius Vuscan Jan 07 '21 at 16:36
2 Answers
2
If you really, really must do this in Python without using a library, your simplest option is to convert your images to NetPBM format - PGM if greyscale, PPM if colour, PNM if RGBA.
You can do that with the NetPBM tools, or with ImageMagick, or libvips
. See here
Then you can easily open the files with Python without libraries, see third example here.

Mark Setchell
- 191,897
- 31
- 273
- 432
0
Yes, there is a way. You could read the bytes of the binary file and parse its bytes according to the image format you are facing. This is very time consumptive and error-prone and due to this, I would not recommend doing it.

Yannick Funk
- 1,319
- 10
- 23
-
https://www.kite.com/python/answers/how-to-read-bytes-from-a-binary-file-in-python this describes to read the bytes of a binary file in python, this http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html describes the bytes structure of a png file, You can read the bytes and match them with the described file structure to read the image – Yannick Funk Jan 07 '21 at 15:32