Context: I built a small thermal camera which can save 70x70 pixels to an SD card. These pixels have a color value ranging from 0 to 2^16. (Actually certain colors, like black (value 0) are never displayed). This color is determined like explained here: c++ defined 16bit (high) color
I want to convert this data into an Image with my computer using Python.
An example gathered from another question unfortunately doesn't yield satisfying results: bad image
As you can see, the image doesn't look very good. My screen shows something like this (note that these two examples were not captured at the same time): photo
The white frame is not part of the csv-file.
This is the code I have used to generate the image:
I have experimented with the color_max
value but didn't get good results.
#Python CSV to Image converter
#pip2 install cImage
#pip2 install numpy
from PIL import Image, ImageDraw
from numpy import genfromtxt
color_max = 256
#original 256
g = open('IMAGE_25.TXT','r')
temp = genfromtxt(g, delimiter = ',')
im = Image.fromarray(temp).convert('RGB')
pix = im.load()
rows, cols = im.size
for x in range(cols):
for y in range(rows):
#print str(x) + " " + str(y)
pix[x,y] = (int(temp[y,x] // color_max // color_max % color_max),int(temp[y,x] // color_max % color_max),int(temp[y,x] % color_max))
im.save(g.name[0:-4] + '.jpeg')
This is the csv-file: Image Data
31 represents blue in this case, high values are more red.
Thanks for any help!
Here's some additional information about my project:
Arduino Thermal Camera with SD card support and image saving capability using the AMG8833 Thermal Imaging sensor made by Panasonic: Datasheet
GitHub (Arduino and Python Code)