Skip to content

antoniofcano/ndvi_capture_processing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NDVI Image Processing Library

This library provides an easy-to-use Python class, NDVIProcessor, for processing images to compute the Normalized Difference Vegetation Index (NDVI). The library also includes two example scripts for processing single images and multiple images in a folder.

Table of Contents

What is NDVI?

The Normalized Difference Vegetation Index (NDVI) is a simple graphical indicator used to analyze remote sensing measurements, typically but not necessarily from a space platform, assessing whether the target being observed contains live green vegetation or not. NDVI is widely used in the field of agriculture, forestry, and environmental monitoring.

How is NDVI calculated?

The NDVI is calculated using the following formula: NDVI = (NIR - Red) / (NIR + Red)

where NIR is the near-infrared radiation and Red is the red radiation. The resulting NDVI values range from -1 to 1. High NDVI values (around 0.8) indicate dense vegetation, while low values (around 0) indicate non-vegetated areas such as water, rocks, or sand.

Why use bands 0 and 2?

The code is designed for use with a NoIR camera with a blue filter. The NoIR camera lacks an infrared blocking filter, allowing it to capture both visible and near-infrared light. The blue filter further enhances the camera's ability to capture the NIR and red bands, which are critical for NDVI calculations.

In the case of a NoIR camera with a blue filter, the bands in the captured image are as follows:

  • Band 0: Near-infrared (NIR)
  • Band 1: Green
  • Band 2: Red

The NDVIProcessor class extracts bands 0 and 2 (NIR and Red) from the input image and uses them to compute the NDVI.

NDVIProcessor class

The NDVIProcessor class provides the following methods for NDVI processing:

  • __init__(self, input_file): Initializes the NDVIProcessor with the input file path.
  • process_image(self): Processes the input image and computes the NDVI.
  • apply_colormap(self, colormap=cv2.COLORMAP_JET): Applies the specified colormap to the NDVI image.

Example scripts

There are two example scripts included in this library:

  1. ndvi_single_image.py: This script processes a single input image (JPG or DNG) and saves the resulting NDVI image in the specified output directory. The user can also specify the colormap to apply to the NDVI image.

python ndvi_single_image.py -i input_file_path -o output_directory -c colormap

For both scripts, the recommended colormaps for NDVI representation are:

  • 2: cv2.COLORMAP_JET
  • 11: cv2.COLORMAP_RAINBOW
  • 13: cv2.COLORMAP_HSV
  • 17: cv2.COLORMAP_TWILIGHT

To see the available colormaps and their respective IDs, check the OpenCV documentation.

Additional resources

For more information on NDVI and remote sensing, you can refer to the following resources:


This library and the accompanying examples provide a comprehensive starting point for working with NDVI image processing in Python. The NDVIProcessor class is designed to be easy to use and can be easily integrated into other projects or workflows that require NDVI image processing.

About

NDVI Capture from Raspberry Pi and Processing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published