Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is NDVI calculation correct? #713

Closed
cagsen opened this issue Aug 11, 2022 · 1 comment · Fixed by #714
Closed

Is NDVI calculation correct? #713

cagsen opened this issue Aug 11, 2022 · 1 comment · Fixed by #714
Assignees
Labels
transforms Data augmentation transforms
Milestone

Comments

@cagsen
Copy link

cagsen commented Aug 11, 2022

Description

Hi,
I had negative NDVI values therefore I was checking the code for indices calculation and found a small issue:

According to https://github.com/microsoft/torchgeo/blob/main/torchgeo/transforms/indices.py
you calculate the NDVI by using the following formula:

\text{NDVI} = \frac{\text{R} - \text{NIR}}{\text{R} + \text{NIR}}

which is the negative of NDVI, right? The common NDVI formula is: ( NIR -RED )/ (Red+NIR)

Is it a bug or did I miss anything?

Steps to reproduce

I just did code analysis.

Version

commit 35fb022 on Jul 11

@adamjstewart adamjstewart added the transforms Data augmentation transforms label Aug 11, 2022
@adamjstewart adamjstewart added this to the 0.3.1 milestone Aug 11, 2022
@adamjstewart
Copy link
Collaborator

Good catch! You're right, our NDVI calculation is definitely wrong. The only reason we didn't notice this in our tutorials is that we're reversing the colormap to get the results we expect. I'll fix this ASAP and it will be included in the next bugfix release.

P.S. NDVI can be negative, this is often the case over water bodies. But you're probably seeing the reverse where NDVI is only positive over water bodies, which is definitely incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
transforms Data augmentation transforms
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants