Getting RGB values out of image

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
okdude
Posts: 4
Joined: Sat Dec 04, 2021 3:57 pm

Getting RGB values out of image

Post by okdude » Sat Dec 04, 2021 4:00 pm

Hey there! Is there any option on getting RGB values out of an image? I could not find anything. Is this possible in pure python?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Getting RGB values out of image

Post by pythoncoder » Sun Dec 05, 2021 11:07 am

You'll have to give us more information if we are to help. Please describe the image format.
Peter Hinch
Index to my micropython libraries.

okdude
Posts: 4
Joined: Sat Dec 04, 2021 3:57 pm

Re: Getting RGB values out of image

Post by okdude » Sun Dec 05, 2021 6:22 pm

It’s 8x8 PNG. I need to get the RGB value of every pixel in the image.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Getting RGB values out of image

Post by pythoncoder » Sun Dec 05, 2021 6:47 pm

PNG format is quite involved. For a file that small it might be worth using a format conversion tool to copy it to a simpler format such as uncompressed BMP. Getting pixel data from that should be fairly easy.
Peter Hinch
Index to my micropython libraries.

okdude
Posts: 4
Joined: Sat Dec 04, 2021 3:57 pm

Re: Getting RGB values out of image

Post by okdude » Sun Dec 05, 2021 10:43 pm

Thank you! I will look into this tomorrow.

okdude
Posts: 4
Joined: Sat Dec 04, 2021 3:57 pm

Re: Getting RGB values out of image

Post by okdude » Mon Dec 06, 2021 10:17 am

pythoncoder wrote:
Sun Dec 05, 2021 6:47 pm
PNG format is quite involved. For a file that small it might be worth using a format conversion tool to copy it to a simpler format such as uncompressed BMP. Getting pixel data from that should be fairly easy.
Any tips on how to convert this? I can only find solutions that involve using Pillow :/

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Getting RGB values out of image

Post by pythoncoder » Mon Dec 06, 2021 10:25 am

As usual there are two options. Search for a library someone's already written; failing that, look up the spec for a BMP file and do it yourself.

This isn't something I've investigated in detail, but I do know that uncompressed BMP is one of the simplest graphics formats.
Peter Hinch
Index to my micropython libraries.

Post Reply