# Get color from each image pixel of a PNG or JPG

**URL:** <https://discourse.nodered.org/t/get-color-from-each-image-pixel-of-a-png-or-jpg/32251>\
**Category:** General\
**Created:** [31 August 2020 12:43 UTC](https://discourse.nodered.org/t/get-color-from-each-image-pixel-of-a-png-or-jpg/32251 "2020-08-31T12:43:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![YT2310](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yt2310/32/35255_2.png) [@YT2310](https://discourse.nodered.org/u/YT2310)\
**Post date:** [31 August 2020 12:43 UTC](https://discourse.nodered.org/t/get-color-from-each-image-pixel-of-a-png-or-jpg/32251/1 "2020-08-31T12:43:45Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [31 August 2020 14:06 UTC](https://discourse.nodered.org/t/get-color-from-each-image-pixel-of-a-png-or-jpg/32251/2 "2020-08-31T14:06:20Z")

</div>

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

> **[node-red-contrib-image-tools](https://flows.nodered.org/node/node-red-contrib-image-tools)**
>
> A dynamic Image editor node with over 40 functions, a viewer node and a 1D + 2D Barcode Decoder node

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/94afe2486112db26caf6e12211b49d8c08970355.png)

---

<div class="post-metadata">

**Author:** ![YT2310](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yt2310/32/35255_2.png) [@YT2310](https://discourse.nodered.org/u/YT2310)\
**Post date:** [3 September 2020 08:18 UTC](https://discourse.nodered.org/t/get-color-from-each-image-pixel-of-a-png-or-jpg/32251/3 "2020-09-03T08:18:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 September 2020 07:12 UTC](https://discourse.nodered.org/t/get-color-from-each-image-pixel-of-a-png-or-jpg/32251/4 "2020-09-04T07:12:32Z")

</div>

- 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"?

---

<div class="post-metadata">

**Author:** ![YT2310](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yt2310/32/35255_2.png) [@YT2310](https://discourse.nodered.org/u/YT2310)\
**Post date:** [4 September 2020 11:28 UTC](https://discourse.nodered.org/t/get-color-from-each-image-pixel-of-a-png-or-jpg/32251/5 "2020-09-04T11:28:51Z")

</div>

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..

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 September 2020 12:23 UTC](https://discourse.nodered.org/t/get-color-from-each-image-pixel-of-a-png-or-jpg/32251/6 "2020-09-04T12:23:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [4 September 2020 14:27 UTC](https://discourse.nodered.org/t/get-color-from-each-image-pixel-of-a-png-or-jpg/32251/7 "2020-09-04T14:27:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 September 2020 14:27 UTC](https://discourse.nodered.org/t/get-color-from-each-image-pixel-of-a-png-or-jpg/32251/8 "2020-09-18T14:27:24Z")

</div>

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