---
title: "RGB Visible Indices for Image Analysis"
author: |
  RN Singh  
  Bappa Das  
  Sonam  
  Anil Kumar  
  Santosha Rathod*  
date: "`r Sys.Date()`"
output: html_document
vignette: >
  %\VignetteIndexEntry{RGB Visible Indices for Image Analysis}
  %\VignetteEngine{knitr::rmarkdown}
---

*Corresponding author: santoshagriculture@gmail.com*

# 1. Introduction

The `rgbIndices` package provides a comprehensive set of RGB-based indices derived from digital images. These indices are widely used in agriculture, crop phenotyping, vegetation monitoring, and image-based modeling.

The package includes multiple groups of indices such as basic, difference, ratio, normalized difference, vegetation, and color indices.

---

# 2. RGB Components

An RGB image consists of three channels:

- **R**: Red (0–255)  
- **G**: Green (0–255)  
- **B**: Blue (0–255)  

---

# 3. Basic Indices

| Index | Formula |
|------|--------|
| Normalized Red (r) | R / (R + G + B) |
| Normalized Green (g) | G / (R + G + B) |
| Normalized Blue (b) | B / (R + G + B) |
| Intensity (INT) | (R + G + B) / 3 |

---

# 4. Difference Indices

| Index | Full Form | Formula |
|------|----------|--------|
| GRD | Green Red Difference | G − R |
| BGD | Blue Green Difference | B − G |
| RGD | Red Green Difference | R − G |
| RBD | Red Blue Difference | R − B |
| GBD | Green Blue Difference | G − B |
| BRD | Blue Red Difference | B − R |

---

# 5. Ratio Indices

| Index | Full Form | Formula |
|------|----------|--------|
| GRRI | Green Red Ratio Index | G / R |
| GBRI | Green Blue Ratio Index | G / B |
| RBRI | Red Blue Ratio Index | R / B |
| RGRI | Red Green Ratio Index | R / G |
| BGRI | Blue Green Ratio Index | B / G |
| BRRI | Blue Red Ratio Index | B / R |

---

# 6. Normalized Difference Indices

| Index | Full Form | Formula |
|------|----------|--------|
| NGRDI | Normalized Green Red Difference Index | (G − R) / (R + G + B) |
| NRGDI | Normalized Red Green Difference Index | (R − G) / (R + G + B) |
| NBRDI | Normalized Blue Red Difference Index | (B − R) / (R + G + B) |
| NRBDI | Normalized Red Blue Difference Index | (R − B) / (R + G + B) |
| NGBDI | Normalized Green Blue Difference Index | (G − B) / (R + G + B) |
| NBGDI | Normalized Blue Green Difference Index | (B − G) / (R + G + B) |

---

**Note:** Some normalized difference indices are sign-inverted counterparts of each other (e.g., NGRDI vs NRGDI).

# 7. Vegetation Indices

| Index | Full Form | Formula |
|------|----------|--------|
| WI | Woebbecke Index | (G − B) / (R − G) |
| GRVI | Green Red Vegetation Index | (G − R) / (G + R) |
| IKAW | Kawashima Index | (R − B) / (R + B) |
| NDTI | Normalized Difference Turbidity Index | (R − G) / (R + G) |
| GBI | Green Blue Index | (G − B) / (G + B) |
| GLI | Green Leaf Index | (2G − R − B) / (2G + R + B) |
| VARI | Visible Atmospherically Resistant Index | (G − R) / (G + R − B) |
| NDI | Normalized Difference Index | (g − r) / (g + r) |
| ExG | Excess Green Index | 2g − r − b |
| ExR | Excess Red Index | 1.4r − g |
| ExGR | Excess Green minus Red | 3g − 2.4r − b |
| MxEG | Modified Excess Green | 1.262G − 0.884R − 0.311B |
| ExB | Excess Blue | 1.4b − g |
| RGBVI | RGB Vegetation Index | (G² − RB) / (G² + RB) |

---

# 8. Color Indices

| Index | Full Form | Formula |
|------|----------|--------|
| Grey | Gray Intensity | 0.2898r + 0.5870g + 0.1140b |
| BI | Brightness Index | √((R² + G² + B²)/3) |
| HI | Hue Index | (2R − G − B) / (G − B) |
| RI | Redness Index | R² / (B × G³) |
| SI | Saturation Index | 2(R − G − B) / (G − B) |
| CI | Coloration Index | (R − B) / R |
| CIVE | Color Index of Vegetation | 0.441R − 0.811G + 0.385B + 18.78745 |
| VEG | Vegetative Index | G / (R^0.667 × B^0.333) |
| SAT | Overall Saturation Index | (|R−G| + |R−B| + |G−B|) / (3(R+G+B)) |
| OHI | Overall Hue Index | atan(2(R − G − B)/(30.5(G − B))) |
| TCVI | True Color Vegetation Index | 1.4(2R − 2B)/(2R − G − 2B + 255×0.4) |

---

# 9. Example Workflow
```{r}
library(rgbIndices)
library(raster)

# ---------------------------
# Example
# ---------------------------
set.seed(123)
r <- raster::raster(matrix(runif(30*30), 30, 30))
g <- raster::raster(matrix(runif(30*30), 30, 30))
b <- raster::raster(matrix(runif(30*30), 30, 30))
img <- raster::stack(r, g, b)

# Compute indices
idx  <- rgb_basic(img)
idx1 <- rgb_diff(img)
idx2 <- rgb_ratio(img)
idx3 <- rgb_normdiff(img)
idx4 <- rgb_veg(img)
idx5 <- rgb_color(img)

# Summary statistics
rgb_indices_to_mean(idx)

# Convert to table
tbl <- rgb_indices_to_tbl(idx)
head(tbl)
```

# ---------------------------
# Real image example
# ---------------------------
```{r eval=FALSE}
img_real <- raster::stack(rgb_example())
raster::plotRGB(img_real)
rgb_basic(img_real)
```

----

# 10. Applications

- Crop health monitoring  
- Disease detection  
- Plant phenotyping  
- Precision agriculture  
- Weed detection and classification  

# 11. Reference

Singh, R. N., Krishnan, P., Singh, V. K., & Das, B. (2023).  
Estimation of yellow rust severity in wheat using visible and thermal imaging coupled with machine learning models.  
Geocarto International.  
https://www.tandfonline.com/doi/full/10.1080/10106049.2022.2160831

