Skip to content

Commit

Permalink
Added Crust Index algorithm to i.vi (OSGeo#1997)
Browse files Browse the repository at this point in the history
As per Request OSGeo#1995 : OSGeo#1995
  • Loading branch information
Yann Chemin authored and ninsbl committed Oct 26, 2022
1 parent f204091 commit 2e44390
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
23 changes: 23 additions & 0 deletions imagery/i.vi/ci.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

/*From https://karnieli-rsl.com/image.ashx?i=901711.pdf&fn=1997-Karnieli_CI_IJRS_97.pdf
* Crust Index CI=1-(RED-BLUE)/(RED+BLUE). (KARNIELI, 1997)
* Development and implementation of spectral crust index over dune sands
* The Remote Sensing Laboratory, J. Blaustein Institute for Desert Research, Ben Gurion University, Sede-Boker Campus 84990, Israel. (Received 26 January 1996; in ® nal form 19 July 1996) */
/* Crust Index */
double c_i(double bluechan, double redchan)
{
double result;

if ((redchan + bluechan) == 0.0) {
result = -1.0;
}
else {
result = 1 - (redchan - bluechan) / (redchan + bluechan);
}
return result;
}


19 changes: 18 additions & 1 deletion imagery/i.vi/i.vi.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ <h2>DESCRIPTION</h2>
parameters.

<ul>
<li>ARVI: atmospherically resistant vegetation indices</li>
<li>ARVI: Atmospherically Resistant Vegetation Index</li>
<li>CI: Crust Index</li>
<li>DVI: Difference Vegetation Index</li>
<li>EVI: Enhanced Vegetation Index</li>
<li>EVI2: Enhanced Vegetation Index 2</li>
Expand Down Expand Up @@ -79,6 +80,22 @@ <h3>Vegetation Indices</h3>
( nirchan + (2.0*redchan - bluechan))
</pre></div>

<b>CI: Crust Index</b>
<p>
Advantage is taken of a unique spectral feature of soil biogenic
crust containing cyanobacteria. It has been shown that the special phycobilin
pigment in cyanobacteria contributes in producing a relatively higher re ̄ ectance
in the blue spectral region than the same type of substrate without the
biogenic crust. The spectral crust index (CI) is based on
the normalized difference between the RED and the BLUE spectral values (Karnieli, 1997).

<div class="code"><pre>
ci ( bluechan, redchan )

CI = 1 - (redchan - bluechan) /
(redchan + bluechan)
</pre></div>

<p>
<b>DVI: Difference Vegetation Index</b>

Expand Down
13 changes: 11 additions & 2 deletions imagery/i.vi/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <grass/raster.h>
#include <grass/glocale.h>

double c_i(double bluechan, double redchan);
double s_r(double redchan, double nirchan);
double nd_vi(double redchan, double nirchan);
double nd_wi(double greenchan, double nirchan);
Expand Down Expand Up @@ -107,9 +108,10 @@ int main(int argc, char *argv[])
opt.viname->description = _("Type of vegetation index");
desc = NULL;
G_asprintf(&desc,
"arvi;%s;dvi;%s;evi;%s;evi2;%s;gvi;%s;gari;%s;gemi;%s;ipvi;%s;msavi;%s;"
"arvi;%s;ci;%s;dvi;%s;evi;%s;evi2;%s;gvi;%s;gari;%s;gemi;%s;ipvi;%s;msavi;%s;"
"msavi2;%s;ndvi;%s;ndwi;%s;pvi;%s;savi;%s;sr;%s;vari;%s;wdvi;%s",
_("Atmospherically Resistant Vegetation Index"),
_("Crust Index"),
_("Difference Vegetation Index"),
_("Enhanced Vegetation Index"),
_("Enhanced Vegetation Index 2"),
Expand All @@ -127,7 +129,7 @@ int main(int argc, char *argv[])
_("Visible Atmospherically Resistant Index"),
_("Weighted Difference Vegetation Index"));
opt.viname->descriptions = desc;
opt.viname->options = "arvi,dvi,evi,evi2,gvi,gari,gemi,ipvi,msavi,msavi2,ndvi,ndwi,pvi,savi,sr,vari,wdvi";
opt.viname->options = "arvi,ci,dvi,evi,evi2,gvi,gari,gemi,ipvi,msavi,msavi2,ndvi,ndwi,pvi,savi,sr,vari,wdvi";
opt.viname->answer = "ndvi";
opt.viname->key_desc = _("type");

Expand Down Expand Up @@ -232,6 +234,9 @@ int main(int argc, char *argv[])
result = opt.output->answer;
G_verbose_message(_("Calculating %s..."), viflag);

if (!strcasecmp(viflag, "ci") && (!(opt.blue->answer) || !(opt.red->answer)) )
G_fatal_error(_("ci index requires blue and red maps"));

if (!strcasecmp(viflag, "sr") && (!(opt.red->answer) || !(opt.nir->answer)) )
G_fatal_error(_("sr index requires red and nir maps"));

Expand Down Expand Up @@ -468,6 +473,10 @@ int main(int argc, char *argv[])
Rast_set_f_null_value(&outrast[col], 1);
}
else {
/* calculate crust_index */
if (!strcasecmp(viflag, "ci"))
outrast[col] = c_i(d_bluechan, d_redchan);

/* calculate simple_ratio */
if (!strcasecmp(viflag, "sr"))
outrast[col] = s_r(d_redchan, d_nirchan);
Expand Down

0 comments on commit 2e44390

Please sign in to comment.