I want to calculate an index and can't figure out why 2 seemingly identical scripts produce very different results. The input raster is a multiband GeoTiff (32-bit float) and I need to use the RGB bands as inputs. The RGB bands first need to be normalized to a scale of 0-1 (e.g. Red/Red_max), then the chromatic coordinates need to be determined (e.g. red/red+green+blue), and finally the index (ExG = 2*green-red-blue).
Since my data are already on the 0-1 scale, I can skip that step but still encounter problems. Can someone please explain why this:
red = Float(Raster(inraster+"/Band_1")/(Raster(inraster+"/Band_1")+Raster(inraster+"/Band_2")+Raster(inraster+"/Band_6")))
green = Float(Raster(inraster+"/Band_2")/(Raster(inraster+"/Band_1")+Raster(inraster+"/Band_2")+Raster(inraster+"/Band_6")))
blue = Float(Raster(inraster+"/Band_6")/(Raster(inraster+"/Band_1")+Raster(inraster+"/Band_2")+Raster(inraster+"/Band_6")))
ExG = 2*green - red - blue<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
produces the correct output. But the following does not:
red = Raster(inraster+"/Band_1")
green = Raster(inraster+"/Band_2")
blue = Raster(inraster+"/Band_6")
red_cc = Float(red/red+green+blue)
green_cc = Float(green/red+green+blue)
blue_cc = Float(blue/red+green+blue)
ExG = 2*green_cc - red_cc - blue_cc<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I did the math for a single pixel by hand and the former is definitely correct. Eg.
The original inputs prior to finding the chromatic coordinates are: Red = 0.427023, Green = 0.405449, Blue =0.349515
The ExG calculates to 0.02907.
When using the first method, I get 0.029070, but using the second I get 0.080466.