Incorrect NDVI results from an exported multispectral (ODM) GeoTIFF in QGIS

Hello

I have trouble processing the multispectral output from OpenDroneMap in QGIS.
I processed the images with the radiometric option: camera+sun
In ODM, when I go to View Map > Plant Health and I select NDVI-algorithm and bands: GRReN (the native band order with DJI Mavic3M), I get a nice visualisation of the vegetation.

However, when I use the exported multispectral GeoTIFF (Raw) from ODM in QGIS to create the NDVI layer using the raster calculator, things go wrong.

In the raster calculator, I enter the NDVI-formula: NDVI = (NIR - Red) / (NIR + Red)

The band order after the ODM export is: Red, Green, NIR, Red Edge
so the formula becomes:
( “ODM_output@3” - “ODM_output@1” ) / ( “ODM_output@3” + “ODM_output@1” )

The result is a distorted (unusable) tif.
Also the values show “340,282,346,638,… to -340,282,346,638,…”

Any ideas what could cause this?
Thanks for your help.

ODM Plant Health view:

QGIS - NDVI output:

This is not a problem with your reflectance data – it comes from the pixels outside the mapped area (and a few edge pixels), which dominate the min/max of your QGIS result.

I reproduced it with an ODM 3.6.2 multispectral orthophoto from another Mavic 3M dataset:

  • The exported GeoTIFF has 5 bands: 1 Red, 2 Green, 3 NIR, 4 RedEdge, 5 alpha (float32 reflectance, the band names are in the band descriptions – so your @3/@1 choice is correct; “GRReN” in the Plant Health view is just the preset name, it picks the bands by description).
  • The file has no NoData value. Outside the mapped area all bands are 0 and only the alpha band (5) is 0. NDVI there is 0/0 → QGIS writes its float32 NoData/±infinity (±3.4·10³⁸), which is exactly the range you see.
  • At the border of the mosaic some pixels have slightly negative reflectance (resampling), so NIR + Red can be ~0 and NDVI jumps to ±150 there (987 of 12.5 M pixels in my test).

Inside the valid area, NDVI is perfectly fine: 1st/50th/99th percentile 0.14 / 0.77 / 0.92 in my test.

Fix in QGIS: mask with the alpha band and ignore the edge pixels, e.g. in the Raster Calculator

( "ODM_output@5" > 0 AND "ODM_output@1" > 0 AND "ODM_output@3" > 0 ) * ( "ODM_output@3" - "ODM_output@1" ) / ( "ODM_output@3" + "ODM_output@1" )

then in the layer’s Symbology set Min = -1 and Max = 1 (or use “Cumulative count cut 2–98 %”) instead of the actual min/max.

Or with GDAL (writes a clean NoData of -9999):

gdal_calc.py -A odm_orthophoto.tif --A_band=3 -B odm_orthophoto.tif --B_band=1 -C odm_orthophoto.tif --C_band=5 \
  --outfile=ndvi.tif --type=Float32 --NoDataValue=-9999 \
  --calc="where((C>0)*(A>0)*(B>0), (A-B)/(A+B), -9999)"

Side note on camera+sun with the M3M: the absolute reflectance values come out low (NIR ≈ 0.05–0.10 over vegetation). ODM applies DJI’s published formula correctly, but DJI doesn’t publish the final calibration constant, so the M3M only gives values proportional to reflectance (absolute values need a reflectance panel). NDVI is a ratio, so it is not affected by that.

I tried this with GDAL and the output is fine now :slightly_smiling_face:
However, as for the suggested fix for QGIS, the output is similarly (wrong) and within the ±3.4·10³⁸ range as well.

Thank you for the clarification and assistance!

Thanks for testing, and glad GDAL works!

I’ve now checked the QGIS side properly, in QGIS 3.34 with an ODM 3.6.2 Mavic 3M orthophoto:

  • Raster Calculator with an output file (GeoTIFF): with the expression from my post the result is correct – the area outside the mapped field is NoData and NDVI goes from −0.997 to 1.000. Same with the Processing algorithm Raster calculator.
  • I could reproduce your values only with “Create on-the-fly raster instead of writing layer to disk” (or the Processing algorithm Raster calculator (virtual)). That on-the-fly layer has no NoData value, so QGIS’s internal NoData (−3.4·10³⁸) shows up as a real value and the layer range becomes −3.4·10³⁸ … 1.

So please untick that option and write the result to a file (e.g. ndvi.tif), then set Symbology Min −1 / Max 1. If you weren’t using the on-the-fly option, could you tell me your QGIS version and which calculator you used? Then I’ll look again.

For future ODM versions I’ve submitted a fix that writes a NoData value into multispectral orthophotos and removes the negative edge values, so a plain (@3 − @1) / (@3 + @1) will work directly: Set NoData on float (reflectance) orthophotos and clamp negative reflectance by Ghost7K · Pull Request #2090 · OpenDroneMap/ODM · GitHub

I processed the image again just to be sure, but the output remains exactly the same. This time, I made sure not to select the option to create an on-the-fly raster, yet it did not make any difference.

For reference, I’m using QGIS 3.44.8 (LTR).

You can download the file exported from ODM below.
Hopefully, this will make it easier to track down the underlying issue.

Thank you for taking the time to investigate this issue and for already submitting the fix for future ODM builds.

Thanks for the file, that helped. I ran your ODM_output.tif through QGIS 3.44 (LTR) here.

1. Raster Calculator – “Create on-the-fly raster” unticked, output to a GeoTIFF file, with the masked expression:

2. Result: NDVI from −1.000 to 0.999, everything outside the field is NoData, and QGIS sets the legend to the expected range by itself (shown here with Min −1 / Max 1):

3. How I can reproduce what you see: exactly the same result, but with the NoData flag removed from the layer. QGIS then treats its internal NoData value (−3.4·10³⁸) as a real value: the legend runs from −340,282,346,638,… to 0.999 and the map shows just two colours:

So the calculation itself works with your file and QGIS 3.44; somewhere on your side the result layer loses its NoData setting. Quick fix: in the result layer’s Properties → Transparency, enter -3.4028235e+38 as “Additional no data value”, or set Symbology to Min −1 / Max 1. If that doesn’t help, a screenshot of that Transparency tab and of your Raster Calculator dialog would show where it differs.

(For future ODM versions the fix that writes a proper NoData value into multispectral orthophotos is here: Set NoData on float (reflectance) orthophotos and clamp negative reflectance by Ghost7K · Pull Request #2090 · OpenDroneMap/ODM · GitHub)

I investigated this a little further and noticed that the selected project/output CRS affects the results of the raster calculator.

  1. When I import the ODM geotiff (the project CRS will automatically be EPSG:32631) and select output CRS => EPSG:28992 in the raster calculator, the generated geotiff is incorrect (see image below).

  2. When I import the ODM geotiff, then set my project CRS to EPSG:28992 and set the output CRS in the raster calculator to EPSG:28992, the generated layer is as it should be but with the “-340/+340”-range.

  3. When I import the ODM geotiff, then set my project CRS to EPSG:28992 and leave the output CRS in the raster calculator as is (EPSG:32631), the generated layer is as it should be with the perfect range.

Hi @StephMo,

nice find, that may explain it. The raster calculator’s output CRS isn’t just a label. If it differs from the layer’s CRS, QGIS reprojects the input bands on the fly before calculating. Two things go wrong on that path:

  • The extent and cell size in the dialog belong to one CRS but get applied in the other. That gives you the striped result in case 1.
  • The NoData flag doesn’t survive the on-the-fly reprojection, so −3.4·10³⁸ comes through as a real value. That’s your ±340 range in case 2, and it’s the same effect as in my screenshot above.

Case 3 works because nothing gets reprojected there.

So the safe workflow is: calculate in the native CRS of the ODM file (EPSG:32631), then reproject the finished NDVI separately. Use Raster → Projections → Warp (Reproject) with:

  • Target CRS: EPSG:28992
  • Source no-data value: -3.4028235e+38, or leave it empty if your NDVI layer already has NoData set
  • Resampling: bilinear for NDVI, or nearest if you need the exact original values

Warp handles NoData properly. Alternatively, you can reproject the ODM GeoTIFF to 28992 with Warp first and then run the raster calculator on that. The main thing is that input and output CRS of the calculator are the same.

Great.
Thank you for thinking along!

Best
Steph