element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Pi IoT
  • Challenges & Projects
  • Design Challenges
  • Pi IoT
  • More
  • Cancel
Pi IoT
Blog [Pi IoT] Plant Health Camera #9 - calculating BNDVI and GNDVI
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: gpolder
  • Date Created: 23 Aug 2016 8:57 PM Date Created
  • Views 1044 views
  • Likes 7 likes
  • Comments 3 comments
  • pi camera noir v2
  • pi 3
  • python
  • ndvi
  • pi-iot
  • pi camera v2
  • piiot challenge
  • plant health camera
Related
Recommended

[Pi IoT] Plant Health Camera #9 - calculating BNDVI and GNDVI

gpolder
gpolder
23 Aug 2016

Today a quick update. I wrote a small program to extract the GNDVI and BNDVI images as explained in my previous post.

 

Previous posts:

[Pi IoT] Plant Health Camera #8 - Aligning the images

[Pi IoT] Plant Health Camera #7 - Synchronizing the cameras

[Pi IoT] Plant Health Camera #6 - Putting the slave Pi to work

[Pi IoT] Plant Health Camera #5 - OpenCV

[Pi IoT] Plant Health Camera #4 - Putting the parts together

[Pi IoT] Plant Health Camera #3 - First steps

[Pi IoT] Plant Health Camera #2 - Unboxing

[Pi IoT] Plant Health Camera #1 - Application

 

Python code for extracting GNDVI and BNDVI

As explained last week I added the infra-blue filter in front of the Pi NoIR Camera, in order to get rid of the red part of the scene.

image

Then I wrote a small Python program which grabs a color image and converts them to GNDVI and BNDVI:

The range of the original NDVI images is -1 to +1. In order to display this properly I converted these values to the range 0-255 and applied a colormap such that NDVI value 0 is green, -1 is blue and +1 is red:

 

-1

image

+1

ndvicam.py

# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import numpy
import cv2

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
rawCapture = PiRGBArray(camera)

# allow the camera to warmup
time.sleep(0.1)

# grab an image from the camera
camera.capture(rawCapture, format="bgr")
color_image = rawCapture.array

# extract red green and blue channel
nir_channel = color_image[:,:,0]/256.0
green_channel = color_image[:,:,1]/256.0
blue_channel = color_image[:,:,2]/256.0

# calculate and show gndvi
gndvi = (nir_channel - green_channel)/(nir_channel + green_channel)
gndvi = (gndvi+1)/2
gndvi = cv2.convertScaleAbs(gndvi*255)
gndvi = cv2.applyColorMap(gndvi, cv2.COLORMAP_JET)
cv2.imshow("GNDVI", gndvi)

# calculate and show bndvi
bndvi = (nir_channel - blue_channel)/(nir_channel + blue_channel)
bndvi = (bndvi+1)/2
bndvi = cv2.convertScaleAbs(bndvi*255)
bndvi = cv2.applyColorMap(bndvi, cv2.COLORMAP_JET)
cv2.imshow("BNDVI", bndvi)

# display the image on screen and wait for a keypress
cv2.imshow("Image", color_image)

# save images
cv2.imwrite("./images/color.jpg",color_image)
cv2.imwrite("./images/gndvi.jpg",gndvi)
cv2.imwrite("./images/bndvi.jpg",bndvi)

cv2.waitKey(0)

 

 

Unfortunately at the time of writing sunset has passes already two hours ago, so I couldn't image the plants in my garden.

The only  agricultural stuff I could image was a raspberry:

 

Color image: (note how green it is due to filtering out the red)

image

 

GNDVI:

image

 

BNDVI:

image

 

Stay tuned for real plant images and 'real' NDVI images using the other cameras red channel.

  • Sign in to reply

Top Comments

  • fvan
    fvan over 9 years ago +1
    Looks like you're nearly there!
  • volly
    volly over 9 years ago

    gpolder. Splendid ol' chap...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 9 years ago

    You are making good progress.

     

    There are a wealth of information that you can attain by mixing the various color bands.

     

    There is just so much you can do with spectral analysis.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fvan
    fvan over 9 years ago

    Looks like you're nearly there! image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube