# Advice for using node-red-contrib-image-tools

**URL:** <https://discourse.nodered.org/t/advice-for-using-node-red-contrib-image-tools/81082>\
**Category:** General\
**Created:** [6 September 2023 14:49 UTC](https://discourse.nodered.org/t/advice-for-using-node-red-contrib-image-tools/81082 "2023-09-06T14:49:10Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [6 September 2023 14:49 UTC](https://discourse.nodered.org/t/advice-for-using-node-red-contrib-image-tools/81082/1 "2023-09-06T14:49:10Z")

</div>

I am using [these nodes](https://flows.nodered.org/node/node-red-contrib-image-tools) to do some image processing on a locally hosted 567 KB file (see sample attached jpeg)

 ![test1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0ed91e2ab3565a1f3747d553f89adf477167f8d9.jpeg)

This flow works on a RPi Zero. It takes about 30 seconds for the output to appear in the debug node, and another 30-45 seconds for the image to appear in the Viewer node:

```auto
[{"id":"7b5298742b600106","type":"file in","z":"7ab8211d86815752","name":"","filename":"/home/rpi0c/test1.jpg","filenameType":"str","format":"","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":340,"y":620,"wires":[["2f63038ac579084d","09aee8b775bb98b8"]]},{"id":"a75dd86ce191280d","type":"inject","z":"7ab8211d86815752","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":620,"wires":[["7b5298742b600106"]]},{"id":"2f63038ac579084d","type":"debug","z":"7ab8211d86815752","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":740,"wires":[]},{"id":"09aee8b775bb98b8","type":"image viewer","z":"7ab8211d86815752","name":"","width":160,"data":"payload","dataType":"msg","active":true,"x":610,"y":540,"wires":[[]]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/5/b54758d33457b8b5fd540e79664af179f6fb43e3.png)

However, adding more complexity like this causes Node-RED to crash (or at least that is what I believe is happening):

```auto
[{"id":"7b5298742b600106","type":"file in","z":"7ab8211d86815752","name":"","filename":"/home/rpi0c/test1.jpg","filenameType":"str","format":"","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":380,"y":320,"wires":[["2f63038ac579084d","6b9ff5cfae66000a"]]},{"id":"a75dd86ce191280d","type":"inject","z":"7ab8211d86815752","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":320,"wires":[["7b5298742b600106"]]},{"id":"2f63038ac579084d","type":"debug","z":"7ab8211d86815752","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":500,"wires":[]},{"id":"6b9ff5cfae66000a","type":"jimp-image","z":"7ab8211d86815752","name":"","data":"payload","dataType":"msg","ret":"buf","parameter1":".7","parameter1Type":"num","parameter2":"","parameter2Type":"msg","parameter3":"","parameter3Type":"msg","parameter4":"","parameter4Type":"msg","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","sendProperty":"payload","sendPropertyType":"msg","parameterCount":0,"jimpFunction":"greyscale","selectedJimpFunction":{"name":"greyscale","fn":"greyscale","description":"remove colour from the image","parameters":[]},"x":620,"y":320,"wires":[["df118e676152ee4f","750771f347d6065f"]]},{"id":"df118e676152ee4f","type":"image viewer","z":"7ab8211d86815752","name":"","width":160,"data":"payload","dataType":"msg","active":true,"x":670,"y":380,"wires":[[]]},{"id":"750771f347d6065f","type":"jimp-image","z":"7ab8211d86815752","name":"","data":"payload","dataType":"msg","ret":"buf","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":"payload","sendPropertyType":"msg","parameterCount":0,"jimpFunction":"invert","selectedJimpFunction":{"name":"invert","fn":"invert","description":"invert the image colours","parameters":[]},"x":790,"y":320,"wires":[["59ea95591285fe1a","12e432d2a2a5e34d"]]},{"id":"59ea95591285fe1a","type":"image viewer","z":"7ab8211d86815752","name":"","width":160,"data":"payload","dataType":"msg","active":true,"x":850,"y":380,"wires":[[]]},{"id":"12e432d2a2a5e34d","type":"file","z":"7ab8211d86815752","name":"","filename":"digits.png","filenameType":"str","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":960,"y":320,"wires":[["2fdea0775e5675af"]]},{"id":"2fdea0775e5675af","type":"debug","z":"7ab8211d86815752","name":"debug 10","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1120,"y":320,"wires":[]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/ace0889a0453406da8c8106662578733b939e41d.png)  
Again, it takes about 30 seconds for the output to appear, but in this case after about 8 minutes, no images appear and this is what the log looks like:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/2/b2ef5e22747f38a39697a96bd0b7492aed2f60b0.png)

Any ideas what could be causing this? Am I over reaching by using a RPi Zero for this? I only need to process the image (which changes regularly) about once per minute.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 September 2023 15:12 UTC](https://discourse.nodered.org/t/advice-for-using-node-red-contrib-image-tools/81082/2 "2023-09-06T15:12:37Z")

</div>

What does `top` look like while it is thinking?

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [6 September 2023 15:22 UTC](https://discourse.nodered.org/t/advice-for-using-node-red-contrib-image-tools/81082/3 "2023-09-06T15:22:34Z")

</div>

Here is what I see after the first debug message appears:

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

and here it is after another 3-4 minutes:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/d/5daf39f4ac39c0babd57f1501ec5dce7e0ed8c60.png)

Maybe the Pi Zero is not the right tool for this task?

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [6 September 2023 15:34 UTC](https://discourse.nodered.org/t/advice-for-using-node-red-contrib-image-tools/81082/4 "2023-09-06T15:34:29Z")

</div>

I think I was grabbing too large of an image. It's obviously a seven-segment LCD with two digits and two colors. I downsized to 640 x 480 and it runs in \< 1 minute:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/caf0f9c43eadfa567375c940ea1d12628b3ec4b2.png)

---

<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:** [6 September 2023 15:39 UTC](https://discourse.nodered.org/t/advice-for-using-node-red-contrib-image-tools/81082/5 "2023-09-06T15:39:36Z")

</div>

> [@grant1](#):
>
> processing on a locally hosted 567 KB file

Do you know what size, in memory a 567KB JPEG takes? This image appears to be a 1920x1080 24bit image. Each pixel uses **3 bytes**. So, the maximum size of a 1920x1080 image with 3-byte pixels is approximately 6,220,800 bytes (6.22 megabytes). Thats without the overhead of the node (which holds the packed and unpacked parts of the image)

Then each time your flow branches, a clone is made.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b669859f8ac34000108a169efb5e8eb7093be561.png)

In short, it is not surprising since an RPi Zero has only 512MB to play with.

Does this _REALLY_ need to be an image? 7 seg displays can be made easily with a [few lines of HTML+CSS](https://codepen.io/noleli/pen/abbeWRL)

If you must work with images on such a limited device, my recommendations are as follows.

1. NEVER branch the outputs (one wire per output)
2. Dont use the viewer, but if you do, use it in-line (thats why there is an output pin on it)
3. Where sensible, work with smaller images (your HTML can always set width and height)

---

<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:** [6 September 2023 15:41 UTC](https://discourse.nodered.org/t/advice-for-using-node-red-contrib-image-tools/81082/6 "2023-09-06T15:41:18Z")

</div>

> [@grant1](#):
>
> I downsized to 640 x 480 and it runs in \< 1 minute

640 x 480 x 3 is still 1MB to shift around. Try to follow my recommendations in prev post and this will be a lot quicker.

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [6 September 2023 19:10 UTC](https://discourse.nodered.org/t/advice-for-using-node-red-contrib-image-tools/81082/7 "2023-09-06T19:10:58Z")

</div>

Thanks for the advice / tips. I resized the image even further (when taking the photo) and was able to do some tricks using the [ssocr program](https://www.unix-ag.uni-kl.de/~auerswal/ssocr/) running on the Pi, and thus eliminate the use of the image tools. Pi camera snaps a photo every minute or so of the 2-digit display and then SSOCR picks it up to analyze it.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/9/79e1b1618d75c862743c924dc9ad4bbc1b93cbb9.png)

---

<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:** [6 September 2023 19:15 UTC](https://discourse.nodered.org/t/advice-for-using-node-red-contrib-image-tools/81082/8 "2023-09-06T19:15:10Z")

</div>

Each time you branch, msg is cloned.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/d/0d797b97a446dacb87f84a46a2941f40474121c2.png)

> [@Steve-Mcl](#):
>
> NEVER branch the outputs (one wire per output)

> [@Steve-Mcl](#):
>
> Dont use the viewer, but if you do, use it in-line (thats why there is an output pin on it)

---

<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:** [6 September 2023 19:18 UTC](https://discourse.nodered.org/t/advice-for-using-node-red-contrib-image-tools/81082/9 "2023-09-06T19:18:24Z")

</div>

Also, I would recommend **not** writing to SD card. You can pass the image data as a buffer to a tesseract node for OCR instead of a commandline tool

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [6 September 2023 20:09 UTC](https://discourse.nodered.org/t/advice-for-using-node-red-contrib-image-tools/81082/10 "2023-09-06T20:09:37Z")

</div>

I put the viewer in my flow only for purposes of the screenshot to show what I was doing.

I tried the tesseract node several months ago and had mixed results with it.

I will look into not storing the file on the SD and instead just passing the buffer.

---

<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:** [20 September 2023 20:10 UTC](https://discourse.nodered.org/t/advice-for-using-node-red-contrib-image-tools/81082/11 "2023-09-20T20:10:02Z")

</div>

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