2023-11-22 12:02:25 +01:00
|
|
|
-- NDWI
|
2023-11-17 18:18:26 +01:00
|
|
|
|
|
|
|
|
function init()
|
|
|
|
|
--create an empty image for the LUT
|
|
|
|
|
img_lut = image8.new()
|
|
|
|
|
--load the LUT
|
|
|
|
|
img_lut:load_png(get_resource_path("lut/NDWI.png"))
|
|
|
|
|
--return 3 channels, RGB
|
|
|
|
|
return 3
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function process()
|
|
|
|
|
for x = 0, rgb_output:width() - 1, 1 do
|
|
|
|
|
for y = 0, rgb_output:height() - 1, 1 do
|
|
|
|
|
|
|
|
|
|
--get channels from satdump.json
|
|
|
|
|
|
2023-12-09 20:26:21 -03:00
|
|
|
local cch2 = get_calibrated_value(1, x, y, true)
|
|
|
|
|
local cch3a = get_calibrated_value(2, x, y, true)
|
2023-11-17 18:18:26 +01:00
|
|
|
|
2023-11-18 09:03:48 +01:00
|
|
|
|
|
|
|
|
--perform NDWI
|
2023-11-17 18:18:26 +01:00
|
|
|
local ndwi = (cch2-cch3a)/(cch2+cch3a)
|
|
|
|
|
|
|
|
|
|
--range convert from -1 -> 1 to 0 -> 256
|
2023-11-18 09:03:48 +01:00
|
|
|
local ndwi_lutval = (((ndwi-(-1))*256) / (1-(-1)))
|
2023-11-17 18:18:26 +01:00
|
|
|
|
2023-11-18 09:03:48 +01:00
|
|
|
--sanity checks (noise)
|
|
|
|
|
if ndwi_lutval < 0 then
|
|
|
|
|
ndwi_lutval = 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if ndwi_lutval > 255 then
|
|
|
|
|
ndwi_lutval = 255
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2023-11-17 18:18:26 +01:00
|
|
|
--don't forget to create a table!
|
|
|
|
|
local lut_result = {}
|
|
|
|
|
|
|
|
|
|
--send the ndwi_lutval to the LUT, retrieve it back in the table as 3 R,G,B channels
|
|
|
|
|
lut_result[0] = img_lut:get(0 * img_lut:height() * img_lut:width() + ndwi_lutval * img_lut:width() + ndwi_lutval) / 255.0
|
|
|
|
|
lut_result[1] = img_lut:get(1 * img_lut:height() * img_lut:width() + ndwi_lutval * img_lut:width() + ndwi_lutval) / 255.0
|
|
|
|
|
lut_result[2] = img_lut:get(2 * img_lut:height() * img_lut:width() + ndwi_lutval * img_lut:width() + ndwi_lutval) / 255.0
|
2023-11-18 09:03:48 +01:00
|
|
|
|
2023-11-17 18:18:26 +01:00
|
|
|
--return RGB 0=R 1=G 2=B
|
|
|
|
|
set_img_out(0, x, y, lut_result[0])
|
|
|
|
|
set_img_out(1, x, y, lut_result[1])
|
|
|
|
|
set_img_out(2, x, y, lut_result[2])
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
--set the progress bar accordingly
|
|
|
|
|
set_progress(x, rgb_output:width())
|
|
|
|
|
end
|
|
|
|
|
end
|