How to generate an image from the 8x8 raw heat map data of an AMG8833 thermal sensor

MsevsOFNQb

[{"id":"48674285.9c9d1c","type":"inject","z":"db525c47.ab486","name":"fake heat data","topic":"","payload":"{\"R1\":[27.25,27.25,27.25,27.75,27.75,27.75,27.25,28.25],\"R2\":[27.25,27,27.25,27.75,27.5,27.75,27.75,28.5],\"R3\":[27.75,28,27.25,27.5,27.75,27.5,29.25,30.5],\"R4\":[28,28,27.5,28.5,28.5,29,30,31.25],\"R5\":[28,28.25,28,29.5,29.5,29.25,29.75,30.75],\"R6\":[28.25,28,27.75,27.5,28,27.75,28.25,28.75],\"R7\":[28.5,27.5,28,28,27.25,27.5,28.25,28.75],\"R8\":[28,27.75,27.5,27.25,27.75,27.5,28.25,27.75]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":490,"y":760,"wires":[["b114634d.83964"]]},{"id":"10b8ad6b.f00bc3","type":"jimp-image","z":"db525c47.ab486","name":"","data":"{\"w\":8,\"h\":8,\"background\":\"white\"}","dataType":"json","ret":"img","parameter1":"","parameter1Type":"msg","parameter2":"","parameter2Type":"msg","parameter3":"","parameter3Type":"msg","parameter4":"","parameter4Type":"msg","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","sendProperty":"image","sendPropertyType":"msg","parameterCount":0,"jimpFunction":"none","selectedJimpFunction":{"name":"none","fn":"none","description":"Just loads the image.","parameters":[]},"x":990,"y":840,"wires":[["78b387d.d34c678"]]},{"id":"78b387d.d34c678","type":"function","z":"db525c47.ab486","name":"colorise","func":"\nconst minimum = msg.min; //-10w0.0;\nconst maximum = msg.max; //400.0;\nconst data = msg.data;\nconst img = msg.image;\nvar buf = Buffer.from([255,255,255,255]); //temp buffer object for rgbaToInt\n\nfor(let y = 0; y < data.length; y++){\n    let row = data[y];\n    for(let x = 0; x < row.length; x++){\n        let temp = row[x];\n        let c = celcius2colour(temp);\n        img.setPixelColor(c, x, y);\n    }\n}\n\nreturn msg;\n\n\n\nfunction celcius2colour(value) {\n    var ratio = 2 * (value-minimum) / (maximum - minimum);\n    b = parseInt(Math.max(0, 255*(1 - ratio)));\n    r = parseInt(Math.max(0, 255*(ratio - 1)));\n    g = 255 - b - r;\n    return rgbaToInt(r,g,b,255);\n}\n\n\nfunction rgbaToInt(red,green,blue,alpha){\n    \n    var r = red & 0xFF;\n    var g = green & 0xFF;\n    var b = blue & 0xFF;\n    var a = alpha & 0xFF;\n    \n    buf[0] = r;\n    buf[1] = g;\n    buf[2] = b;\n    return buf.readUInt32BE(0);\n    //return (r << 16) + (g << 8) + (b);\n    //return (r << 24 >>> 0) | (g << 16) | (b << 8) | (a);\n}\n\n\n\n\n\n\n","outputs":1,"noerr":0,"x":800,"y":880,"wires":[["2b3cf4e7.8cda8c"]]},{"id":"2b3cf4e7.8cda8c","type":"image viewer","z":"db525c47.ab486","name":"","width":"80","data":"image","dataType":"msg","x":990,"y":880,"wires":[[]]},{"id":"b114634d.83964","type":"change","z":"db525c47.ab486","name":"setup colourisation min/max","rules":[{"t":"set","p":"min","pt":"msg","to":"20","tot":"num"},{"t":"set","p":"max","pt":"msg","to":"30","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":800,"wires":[["7baa1045.31c6b"]]},{"id":"7baa1045.31c6b","type":"function","z":"db525c47.ab486","name":"normalise data","func":"\nvar data = [];\n\ndata.push([...msg.payload.R1]);\ndata.push([...msg.payload.R2]);\ndata.push([...msg.payload.R3]);\ndata.push([...msg.payload.R4]);\ndata.push([...msg.payload.R5]);\ndata.push([...msg.payload.R6]);\ndata.push([...msg.payload.R7]);\ndata.push([...msg.payload.R8]);\n\nmsg.data = data;\nreturn msg;\n\n","outputs":1,"noerr":0,"x":780,"y":840,"wires":[["10b8ad6b.f00bc3","d517db53.45a488"]]},{"id":"d517db53.45a488","type":"debug","z":"db525c47.ab486","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"data","targetType":"msg","x":1000,"y":800,"wires":[]},{"id":"b9831e5f.974db","type":"inject","z":"db525c47.ab486","name":"fake heat data","topic":"","payload":"{\"R1\":[3.25,5.25,7.25,27.75,27.75,47.75,47.25,48.25],\"R2\":[4.25,5,8.25,27.75,27.5,42.75,41.75,39.5],\"R3\":[6.75,8,9.25,27.5,27.75,33.5,35.25,34.5],\"R4\":[15,16,16.5,28.5,28.5,29,30,31.25],\"R5\":[28,28.25,28,29.5,29.5,29.25,29.75,30.75],\"R6\":[33.25,35,37.75,27.5,28,27.75,28.25,28.75],\"R7\":[41.5,44.5,46,28,27.25,27.5,28.25,28.75],\"R8\":[28,27.75,27.5,27.25,27.75,27.5,28.25,27.75]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":490,"y":840,"wires":[["589dee94.09a09"]]},{"id":"589dee94.09a09","type":"change","z":"db525c47.ab486","name":"setup colourisation min/max","rules":[{"t":"set","p":"min","pt":"msg","to":"0","tot":"num"},{"t":"set","p":"max","pt":"msg","to":"50","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":880,"wires":[["7baa1045.31c6b"]]}]

NOTES:
The colourisation routine approximates a heat map. You will need to set expected min/max values. As your data is mostly +/- 1 degree - it looks like a plain green image so I set the min/max as 20, 30 so you could see something (for this particular data set)

If you wish to save the image (as a PNG or whatever), add another image node after the viewer and set the function to "write"

4 Likes