Get color from each image pixel of a PNG or JPG

Hello all,

did anyone have experiences with getting the color of every pixel of an picture?
I just know that from matlab but matlab give me just the part of a jpg file where the colortype is saved so that it is quit easy.

Is something like that possible on node-red (I m pretty sure it is, but have no clue how to)?

Thanks for your help!

I can't remember if there's an easier way but if you use

You can get all the pixels as an array so you can get the RBGA values (all the pixels are #FF000080 in this example)

3 Likes

Basically it works fine, thank you.
But unfortunately the performance is not that good

  • define "slow" - are we talking ~100ms? 1s+? 5s+? 10s+?
  • what size image are you using?
  • what is the source of the image?
  • how often is it being called?
  • is it necessary to access every pixel?
  • Are you certain the slowness is from the image-tools node (perhaps if you are iterating every row and * column & the slowness is in your looping code)?
  • where is node-red running? on on a raspberry PI? in docker? both? How much memory is available to the machine? (images, when decompressed to bitmap can be surprisingly large - hundreds of MBs)

can you post your flow or at least a screenshot & describe your process?
There may be better ways to achieve your goal that you havent considered?

Please note: The library underneath that node is jimp - a pure javascript implementation of image functions. If you expect to process 25fps on a 4K image source you are just asking for trouble. If you are working with 1 image, ad-hoc, does it matter if it is "slow"?

slow means 10+s, but these comes from my for-loop, where I bring the image to an array of rgb objects to check the color of every pixel. So I need an other approach to do that..

Ok so what are you trying to achieve. As I said before, there may be a better solution.

If you really want to put all pixels in an array, numpy in python may be a faster way to go, depending on your needs that is.

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