# How to use Max() to turn NDVI to only 0 and 1

Hi, for customer NDVI index,
(nir-red)/(nir+red) + 0/max(0; (nir-red)/(nir+red) - 0.4)
This one to show any under 0.4 value to 0, over 0.4 are showing.

I need to do a further to show any over 0.4, change value to 1. Then only 0 and 1 will show in this index.
How can I do that? Thank you.

Hello,

this is not possible right now in Pix4Dfields. You can do a reclassification of the values in QGIS: Raster reclassify

Thank you.
Can you explain how max and min work? How does 0/min() work? Thank you.

Hello,

Did you try following the examples here Soil and plant masking w/ Pix4Dfields?

The clue under the workaround described in the community post I shared above is to produce a 0/0 that is defined as â€śNot a Numberâ€ť (NaN), and considered as transparent, or just sum 0, that leaves the value the same. Any number operated with NaN is NaN. There you are computing NDVI + 0 = NDVI for the valid points, and NDVI + NaN = NaN for the â€śinvalidâ€ť.

I am not sure if I understand your question. Do you want values between this range 0 to 1? If yes, you can take as example the community post I shared and do:

(nir-red)/(nir+red) + 0/max(0; (nir-red)/(nir+red) - 0)

Note: In this formula, using max() will mask everything lower 0. Since the NDVI goes up to 1 then you will get values from 0 to 1

Let us know if you have any question

Best,

1 Like

Hi, for costomer NDVI index,
(nir-red)/(nir+red) + 0/max(0; (nir-red)/(nir+red) - 0.4)
This one to show any under 0.4 value to 0, over 0.4 are showing.

I need to do a further to show any over 0.4, change value to 1. Then only 0 and 1 will show in this index.
How can I do that? Thank you.

No. I want if value lower 0.4, change it to 0; If value higher than 0.4, change value to 1.
Can we do that? Since we have Max(), I just canâ€™t find the details about to write a formula.

For (nir-red)/(nir+red) + 0/max(0; (nir-red)/(nir+red) - 0)

The first part is the ndvi value. the second pard 0/xxx how it works?
Can you explain more details or do you any support documents?

Hello,

Thanks for your patience. Changing values is not something we have tested. I would suggest then going with Juliusâ€™s suggestion trying with QGIS.

The second part of the formula 0/ xx is the clue under the index I explained above, but that workaround says to use values under, above, or in between. Not changing to another value.