Public Lab Research note

This is an attempt to replicate an activity.

Low cost NDVI analysis using RaspberryPi and PiNoIR

by petter_mansson1 | April 09, 2019 11:34 09 Apr 11:34 | #19007 | #19007

This project is about conducting an Experiment to see if a PI NoIR camera is able to perform NDVI calculations.

An automated system has been built and the experiment is on week 2 out of 4. When it's finished results will be shared and hopefully I will be able to share my code.

Please leave any questions as a comment and I will be glad to answer them.

Starting this post where I will publish my findings.

Expect results in around 1-2 months since this work is part of my Bachelor Thesis in computer science at Malmö university.

image descriptionimage descriptionimage description

1. First image is the raw image from camera with custom white balance using a blue filter.

2. Second image is the image without applied colormap. It can be considered as grayscale since its only 1 channel of 255 values.

3. Third image is after a colormap has been applied. I'm currently using fastie's colormap.

Code is written in Python and fully automated process for collecting data. Pictures are taken 3 times a day.

As of now I'm scaling the images from 1920x1080 to 800x600 with Lancosz algorithm for interpolation. The reason being for noise reduction, smaller storage size and faster calculation time.

After processing the images on the raspberry pi I upload them to google drive.

I have tried to create a process for automated data collection to see if I can correlate NDVI values to values generated by the environment. If so one might be able to use NDVI values or another "color based index approach" for monitoring plant health [1].

Plants grown are from left to right Mixed Lettuce, Tatsoi, Australische Gele.

The experiment is conducted on the propagation stage of plants for Hydroponic farming.

Two separate containers has been setup with the same plants in both. The dependent variable is that a 3 part nutrient solution has been added since day one to one of the containers and I will plot differences in NDVI value between the two containers.

Checkout github repo here:

Only intended for users who are comfortable with Python environment. Some editing of the code needs to be done to suit personal use but hopefully it will serve someone with ideas. I will look into adding better documentation but you can always reach me in the comment section here.image description

This graph represents the mean of NDVI values from each day during the experiment. One day is the composite of pictures taken at 6am, 12pm, 6pm. Only values between 0.28-0.9 are used since they tend to be plant pixels. Interesting results since I added nutrients from day 0 in one of the growboxes. From this graph it seems like the nutrient solution started taking effect from day 9 where the trend is shifting between the two growboxes.


[1] Esmael Hamuda, Martin Glavin, and Edward Jones. A survey of image processing techniques for plant extraction and segmentation in the field. Computers and Electronics in Agriculture, 125:184--199, July 2016. **

I did this Help out by offering feedback!

People who did this (0)

None yet. Be the first to post one!


This is fantastic! Looking forward to seeing your conclusions!

Reply to this comment...

Hi! This is awesome. Have you seen our Infragram Pi software, somewhat documented at:

We'd love feedback on this project for standardized and easy-to-use infrared pi software!

I was not aware of this. Very cool, I had an idea doing something of the same sort but it's better if we work together! I'd love to share what I've learned since I have gotten so much knowledge from this site.

Reply to this comment...

that'd be awesome. The image workflow we've built is javascript based, but it's also possible to use Pi Builder to produce reproducible python toolsets. You can check out the JS workflow on these pages:

On Tue, Apr 9, 2019 at 12:35 PM \<> wrote:

Hi! There's been a response to a discussion you're involved in. You can reply to this email or visit this link:

petter_mansson1 wrote:

I was not aware of this. Very cool, I had an idea doing something of the same sort but it's better if we work together! I'd love to share what I've learned since I have gotten so much knowledge from this site.

Look like spam? Mark this as Spam

Reply at:

Report abuse to:

Check out the blog at | Love our work? Become a Public Lab Sustaining Member today at If this email title has an ID in the format #0000, you can reply with the email you use at and your response will be posted as a comment on the website.

Is this a question? Click here to post it to the Questions page.

Reply to this comment...

Wow, great work Peter! Have you not included the non-filtered image used to generate the single channel NDVI? or are you doing 'single image' NDVI using a special blue filter?

I'm working on a similar project, using python, rPi, a NoIR cam and I'm even targeting the propagation stage as my primary use case!

Thanks for uploading the single channel image! Now I can do some simple tests while I wait for my camera equipment to arrive (without having to reverse engineer the colormap lol)

I'd love to talk about implementation, possible improvements, and more.


Is this a question? Click here to post it to the Questions page.

Hi Jacob,

Cool! It would be interesting to compare ideas.

I'm taking a single image, using the blue filter that came with the NoIR camera module. I also set a custom white balance for blue and red channel to get the image for NDVI calculation.

Dang, nice! Didn't realize this was possible with the blue filter that ships with the piNoIR. I can't believe how clear these results are.

I'm also a computer science graduate, I'm interested in applying machine learning to NDVI (and other VI) images. I should have my setup put together in the next week or two, and look forward to posting my results here on publiclab.

Lol wish I had saved the blue filter it shipped with

Reply to this comment...

Hi Peter,

What red/blue gains did you use for these photos (I assume you are using picamera)? I know that lighting conditions vary and white balance settings will vary as well but all my images are coming out completely washed and I've tried a few different settings.

Is this a question? Click here to post it to the Questions page.


Is this a question? Click here to post it to the Questions page.

I wrote a simple GUI application using TK for Python with 2 sliders to control AWB gains. That was my approach to finding a good balance. I don't think my settings will work for your environment since it depends on the amount of light present.

Here is my repo for the GUI application. Run the script on your raspberry pi. Think you need to install a Tkinter library. At first I only created it for personal use. It will give you error messages if it's missing a library so just install it using pip. I'm new to python so my fundamentals are quite there yet.

Thanks Petter, I'm using a headless Raspberry Pi so I don't have the option of writing a GUI application (without networking the stream and severely complicating things).

What I've done is written a script that takes a load of photos at different white balance settings to try and find the sweet spot.

I've got my new filter in now and my results are quite a bit better. I'm going to write a research note when I get things set up and I've taken a few rounds of photos.

I found your NDVI processing and it seems practically identical to mine, I hadn't used the vmin, vmax attributes of matplotlib to view the raw ndvi values (I had to truncate the negative values and scaled into 0-255 range), thats a nice trick that I'll have to try!

I use a combination of PILLOW, numpy and Matplotlib. You can also find all my camera settings in It might be abit of a mess but look in

Hi! Just noting that this software stack I mentioned above is configured to run headlessly and to send video over WiFi, including NDVI processing:

Could be helpful!

Reply to this comment...

This is awesome I am working on implementing this into analyzing my hydroponic garden. Just got my piNoIr camera running & am looking through your project. Thanks for writing this up!

Reply to this comment...

Hi Peter, you explained that you used the GUI to manually find your proper balance, however how did you actually quantify what made a good photo?

Is this a question? Click here to post it to the Questions page.

Have you found your answer already or is there anyone else with a feedback on how to know when one found the best balance? :) pretty hard to find informations on this in the web.

@petter_mansson1 thanks a lot for this great intro into NDVI analysis! Hope to enrich my HPA system with this to get a better / shorter feedback loop on the settings of my system!

Is this a question? Click here to post it to the Questions page.

Reply to this comment...

Hi @petter_mansson1 I can not use Cloud Upload in MainNDVI Thise error missing 2 required positional arguments : 'preNDVIFilepath' and 'timestamp'
Help me Pls 😔

Reply to this comment...


Nice work.

The final goal here is to analyze the nutrient effect. Right?

The normal camera (Raspberry pi camera) can also get this type of result. If we plot the total area covered by the plant vs days, we also get this type of graph. What is the extra information we get here using NoIR camera?

The Raspberry pi camera is cheaper than Raspberry pi NoIR camera.

Is this a question? Click here to post it to the Questions page.

Reply to this comment...

Login to comment.