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

Hi, I'm trying to generate PNG image from the 8x8 raw heat map of a thermal sensor, AMG8833 in this case.

My goal is to generate an 8x8 PNG image from this data, I can use this image later for video stream, and use another thermal sensor with more pixels.

I couldn't find much info about this, does anybody know how to do it?

Maybe have a look at node-red-contrib-image-tools

Thanks!

I was looking at node-red-contrib-image-tools before I posted the question, this node seems to be a image processing tool, which needs an image or something related to get going.

The data I have is only an array/matrix with temperatures, so I basically have the brightness of each pixel. It seems I need some way of encoding in order to get an image buffer?

It doesn't have to be PNG though, but I think PNG would be a universal way of doing it. Grayscale is good enough, color mapping could be the next step.

@gsenroc

Post a sample of data & describe how it is packed & what the values mean - and I will show you how you can used image-tools to re-constitute and image from it.

That would be nice!

There are 8 rows and 8 columns, 64 pixels in total for the image.

I have msg.payload.R1 which is an array of 8 numbers, each number represents the temperature value of each column in Row 1. msg.payload.R2 for Row 2...up till msg.payload.R8.

I do it this way just because I extract the temperature of the row in one i2c command. I can change the final payload if needed.

For the image, the temperature will need to be mapped to 0-255 I think.

I'll need you to copy the data from debug and post it in a reply

FJF7xnOcN9

```
paste between backticks like this
```

Here it is:

{"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]}

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

I get

"TypeError: Cannot read property 'setPixelColor' of undefined"

in the colorise node

Odd. I re-imported the export (in-case there was an export issue) - works here.

Can you check what versions you have please?

  • node-red version?
  • node version? node -v
  • node-red-contrib-image-tools version? npm info node-red-contrib-image-tools version
  • jimp version? npm info jimp version

It works on my environment. I can see my fingers in the preview. That's amazing!

Attached is the complete flow with the preview, color map and the i2c part, anybody who wants to use the AMG8833 can also take a look into it. There could still be errors in my code so the temperature readout may not be 100% correct.

Thank you @Steve-Mcl !

[{"id":"4d47a9b5.bb401","type":"tab","label":"AMG8833","disabled":false,"info":""},{"id":"b52e94b3.6645f8","type":"inject","z":"4d47a9b5.bb401","name":"Address 105","props":[{"p":"address","v":"105","vt":"num"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":120,"y":180,"wires":[["71e3b925.d384","cd734d6.3e2693","98473018.7ca25","1372cc89.9ad88b","963e1b04.8a6668","9998a3c6.4f3248","95261317.8b00d8","4caa1afc.09f554"]]},{"id":"437c143d.ec4f84","type":"i2c in","z":"4d47a9b5.bb401","name":"","busno":"1","address":"","command":"","count":"16","x":510,"y":40,"wires":[["22837508.99686a"]]},{"id":"71e3b925.d384","type":"change","z":"4d47a9b5.bb401","name":"T01L to T08H","rules":[{"t":"set","p":"command","pt":"msg","to":"128","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":40,"wires":[["437c143d.ec4f84"]]},{"id":"cd734d6.3e2693","type":"change","z":"4d47a9b5.bb401","name":"T09L & T16H","rules":[{"t":"set","p":"command","pt":"msg","to":"144","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":80,"wires":[["e3cebfa2.2a7eb"]]},{"id":"e3cebfa2.2a7eb","type":"i2c in","z":"4d47a9b5.bb401","name":"","busno":"1","address":"","command":"","count":"16","x":510,"y":80,"wires":[["8148de21.03c3a"]]},{"id":"22837508.99686a","type":"function","z":"4d47a9b5.bb401","name":"","func":"var i;\nvar temperature = [];\n\nfor (i = 0; i < 16; i++) {\n    if (i%2 === 0)\n        temperature[i/2] = (msg.payload[i+1] << 8) | (msg.payload[i]);\n        temperature[i/2] = temperature[i/2] <<20;\n        temperature[i/2] = temperature[i/2] / 1048576 / 4;\n} \n\nmsg.payload = temperature;\nmsg.topic = 'R1'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":40,"wires":[["4f2d08d3.5314c8"]]},{"id":"98473018.7ca25","type":"change","z":"4d47a9b5.bb401","name":"T17L & T24H","rules":[{"t":"set","p":"command","pt":"msg","to":"160","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":120,"wires":[["27b578fe.c7e988"]]},{"id":"1372cc89.9ad88b","type":"change","z":"4d47a9b5.bb401","name":"T25L & T32H","rules":[{"t":"set","p":"command","pt":"msg","to":"176","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":160,"wires":[["5a97aee7.af103"]]},{"id":"963e1b04.8a6668","type":"change","z":"4d47a9b5.bb401","name":"T33L & T40H","rules":[{"t":"set","p":"command","pt":"msg","to":"192","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":200,"wires":[["b0415988.3f6de8"]]},{"id":"9998a3c6.4f3248","type":"change","z":"4d47a9b5.bb401","name":"T41L & T48H","rules":[{"t":"set","p":"command","pt":"msg","to":"208","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":240,"wires":[["eae5aea2.396d28"]]},{"id":"95261317.8b00d8","type":"change","z":"4d47a9b5.bb401","name":"T49L & T56H","rules":[{"t":"set","p":"command","pt":"msg","to":"224","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":280,"wires":[["ebff39f.cad48c8"]]},{"id":"4caa1afc.09f554","type":"change","z":"4d47a9b5.bb401","name":"T57L & T64H","rules":[{"t":"set","p":"command","pt":"msg","to":"240","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":320,"wires":[["24b0bf59.a8072"]]},{"id":"27b578fe.c7e988","type":"i2c in","z":"4d47a9b5.bb401","name":"","busno":"1","address":"","command":"","count":"16","x":510,"y":120,"wires":[["8ff8fcd.021df8"]]},{"id":"5a97aee7.af103","type":"i2c in","z":"4d47a9b5.bb401","name":"","busno":"1","address":"","command":"","count":"16","x":510,"y":160,"wires":[["9778b70e.bc0148"]]},{"id":"b0415988.3f6de8","type":"i2c in","z":"4d47a9b5.bb401","name":"","busno":"1","address":"","command":"","count":"16","x":510,"y":200,"wires":[["dd38373e.cb2348"]]},{"id":"eae5aea2.396d28","type":"i2c in","z":"4d47a9b5.bb401","name":"","busno":"1","address":"","command":"","count":"16","x":510,"y":240,"wires":[["a8e84d5b.bd4f38"]]},{"id":"ebff39f.cad48c8","type":"i2c in","z":"4d47a9b5.bb401","name":"","busno":"1","address":"","command":"","count":"16","x":510,"y":280,"wires":[["b108f187.c7e3c8"]]},{"id":"24b0bf59.a8072","type":"i2c in","z":"4d47a9b5.bb401","name":"","busno":"1","address":"","command":"","count":"16","x":510,"y":320,"wires":[["bf00f399.8456"]]},{"id":"8148de21.03c3a","type":"function","z":"4d47a9b5.bb401","name":"","func":"var i;\nvar temperature = [];\n\nfor (i = 0; i < 16; i++) {\n    if (i%2 === 0)\n        temperature[i/2] = (msg.payload[i+1] << 8) | (msg.payload[i]);\n        temperature[i/2] = temperature[i/2] <<20;\n        temperature[i/2] = temperature[i/2] / 1048576 / 4;\n} \n\nmsg.payload = temperature;\nmsg.topic = 'R2'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":80,"wires":[["4f2d08d3.5314c8"]]},{"id":"8ff8fcd.021df8","type":"function","z":"4d47a9b5.bb401","name":"","func":"var i;\nvar temperature = [];\n\nfor (i = 0; i < 16; i++) {\n    if (i%2 === 0)\n        temperature[i/2] = (msg.payload[i+1] << 8) | (msg.payload[i]);\n        temperature[i/2] = temperature[i/2] <<20;\n        temperature[i/2] = temperature[i/2] / 1048576 / 4;\n} \n\nmsg.payload = temperature;\nmsg.topic = 'R3'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":120,"wires":[["4f2d08d3.5314c8"]]},{"id":"9778b70e.bc0148","type":"function","z":"4d47a9b5.bb401","name":"","func":"var i;\nvar temperature = [];\n\nfor (i = 0; i < 16; i++) {\n    if (i%2 === 0)\n        temperature[i/2] = (msg.payload[i+1] << 8) | (msg.payload[i]);\n        temperature[i/2] = temperature[i/2] <<20;\n        temperature[i/2] = temperature[i/2] / 1048576 / 4;\n} \n\nmsg.payload = temperature;\nmsg.topic = 'R4'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":160,"wires":[["4f2d08d3.5314c8"]]},{"id":"dd38373e.cb2348","type":"function","z":"4d47a9b5.bb401","name":"","func":"var i;\nvar temperature = [];\n\nfor (i = 0; i < 16; i++) {\n    if (i%2 === 0)\n        temperature[i/2] = (msg.payload[i+1] << 8) | (msg.payload[i]);\n        temperature[i/2] = temperature[i/2] <<20;\n        temperature[i/2] = temperature[i/2] / 1048576 / 4;\n} \n\nmsg.payload = temperature;\nmsg.topic = 'R5'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":200,"wires":[["4f2d08d3.5314c8"]]},{"id":"a8e84d5b.bd4f38","type":"function","z":"4d47a9b5.bb401","name":"","func":"var i;\nvar temperature = [];\n\nfor (i = 0; i < 16; i++) {\n    if (i%2 === 0)\n        temperature[i/2] = (msg.payload[i+1] << 8) | (msg.payload[i]);\n        temperature[i/2] = temperature[i/2] <<20;\n        temperature[i/2] = temperature[i/2] / 1048576 / 4;\n} \n\nmsg.payload = temperature;\nmsg.topic = 'R6'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":240,"wires":[["4f2d08d3.5314c8"]]},{"id":"b108f187.c7e3c8","type":"function","z":"4d47a9b5.bb401","name":"","func":"var i;\nvar temperature = [];\n\nfor (i = 0; i < 16; i++) {\n    if (i%2 === 0)\n        temperature[i/2] = (msg.payload[i+1] << 8) | (msg.payload[i]);\n        temperature[i/2] = temperature[i/2] <<20;\n        temperature[i/2] = temperature[i/2] / 1048576 / 4;\n} \n\nmsg.payload = temperature;\nmsg.topic = 'R7'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":280,"wires":[["4f2d08d3.5314c8"]]},{"id":"bf00f399.8456","type":"function","z":"4d47a9b5.bb401","name":"","func":"var i;\nvar temperature = [];\n\nfor (i = 0; i < 16; i++) {\n    if (i%2 === 0)\n        temperature[i/2] = (msg.payload[i+1] << 8) | (msg.payload[i]);\n        temperature[i/2] = temperature[i/2] <<20;\n        temperature[i/2] = temperature[i/2] / 1048576 / 4;\n} \n\nmsg.payload = temperature;\nmsg.topic = 'R8'\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":320,"wires":[["4f2d08d3.5314c8"]]},{"id":"4f2d08d3.5314c8","type":"join","z":"4d47a9b5.bb401","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"8","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":850,"y":180,"wires":[["f8898f45.eecea","f6ea6f13.fc84a"]]},{"id":"2366fab4.80d6ee","type":"jimp-image","z":"4d47a9b5.bb401","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":530,"y":620,"wires":[["2143b45c.817ed4"]]},{"id":"2143b45c.817ed4","type":"function","z":"4d47a9b5.bb401","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":340,"y":660,"wires":[["b911c0ad.625f78"]]},{"id":"b911c0ad.625f78","type":"image viewer","z":"4d47a9b5.bb401","name":"","width":"80","data":"image","dataType":"msg","x":530,"y":660,"wires":[[]]},{"id":"f8898f45.eecea","type":"change","z":"4d47a9b5.bb401","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":280,"y":580,"wires":[["cc97fa33.99aa8"]]},{"id":"cc97fa33.99aa8","type":"function","z":"4d47a9b5.bb401","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":320,"y":620,"wires":[["2366fab4.80d6ee","796dc33b.baab7c"]]},{"id":"796dc33b.baab7c","type":"debug","z":"4d47a9b5.bb401","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"data","targetType":"msg","x":540,"y":580,"wires":[]},{"id":"c94c2dca.da21d8","type":"jimp-image","z":"4d47a9b5.bb401","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":530,"y":840,"wires":[["b9039946.bc9398"]]},{"id":"b9039946.bc9398","type":"function","z":"4d47a9b5.bb401","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":340,"y":880,"wires":[["cc3663c5.2d6cf8"]]},{"id":"cc3663c5.2d6cf8","type":"image viewer","z":"4d47a9b5.bb401","name":"","width":"80","data":"image","dataType":"msg","x":530,"y":880,"wires":[[]]},{"id":"f6ea6f13.fc84a","type":"change","z":"4d47a9b5.bb401","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":280,"y":800,"wires":[["4657b85a.c01ce8"]]},{"id":"4657b85a.c01ce8","type":"function","z":"4d47a9b5.bb401","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":320,"y":840,"wires":[["c94c2dca.da21d8","d1dddf76.171948"]]},{"id":"d1dddf76.171948","type":"debug","z":"4d47a9b5.bb401","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"data","targetType":"msg","x":540,"y":800,"wires":[]}]
1 Like

NR 1.1.2
node 12.18.2
image-tools 1.4.0
jimp 0.16.0

Most likely my fault :innocent:

Found the problem. I imported your flow (@Steve-Mcl)'s but for some strange reason, the setting in the image node was wrong. It was set to payload but should be image. After changing this, everything works

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.