-
Notifications
You must be signed in to change notification settings - Fork 0
/
waterindex.m
54 lines (51 loc) · 2.3 KB
/
waterindex.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function [cir_index]=waterindex(cir, waterIndex, ~)
% [cir_index]=waterindex(cir, waterIndex, ~)
% Function to return various banmd ratios and indexes from an input image.
% For this paper, the Normalized Diffewrence Water Ind3ex (NDWI) and
% infrared (IR, band 1) was used.
% cir is 3-band int image
% cir_index is single precision
% bw is binary threshold with certain sensitivity
fprintf('Creating water index: %s\n', waterIndex)
cir=im2single(cir);
switch waterIndex
case 'NDWI'
cir_index=(cir(:,:,3)-cir(:,:,1))./(cir(:,:,3)+cir(:,:,1));
case 'BNDWI'
% woij
case 'MNDWI'
% cir_ndwi=(cir(:,:,3)-cir(:,:,1))./(cir(:,:,3)+cir(:,:,1));
case 'NDVI'
% cir_ndwi=(cir(:,:,2)-cir(:,:,1))./(cir(:,:,2)+cir(:,:,1));
cir_index=(.5*(cir(:,:,2)+cir(:,:,3))-cir(:,:,1))./(.5*(cir(:,:,2)+cir(:,:,3))+cir(:,:,1));
case 'WI'
cir_index=(cir(:,:,3)-cir(:,:,1));
case 'MAXNDWI'
cir_index=(max(cir(:,:,2), cir(:,:,3))-cir(:,:,1))./(max(cir(:,:,2), cir(:,:,3))+cir(:,:,1));
case 'SPAN'
u1=[.353, .522, .463]; %Yukon color
u2=[.106, .192, .212]; %Dark color
cir_index=-min(spangle_3(u2, cir),spangle_3(u2, cir));
level=graythresh(cir_index);
bw=imbinarize(cir_index, level);
case 'MAXWI'
cir_index=(max(cir(:,:,2), cir(:,:,3))-cir(:,:,1));
case 'MINNDWI'
cir_index=(min(cir(:,:,2), cir(:,:,3))-cir(:,:,1))./(min(cir(:,:,2), cir(:,:,3))+cir(:,:,1));
case 'MINWI'
cir_index=(min(cir(:,:,2), cir(:,:,3))-cir(:,:,1));
case 'BNDWI_3_100'
cir_index=(100*cir(:,:,3)-cir(:,:,1))./(100*cir(:,:,3)+cir(:,:,1));
% cir_ndwi=im2single((cir_ndwi+abs(min(min(cir_ndwi))))./(max(max(cir_ndwi))...
% +abs(min(min(cir_ndwi)))));
case 'BNDWI_1_100'
cir_index=(cir(:,:,3)-100*cir(:,:,1))./(cir(:,:,3)+100*cir(:,:,1));
% cir_ndwi=im2double((cir_ndwi+abs(min(min(cir_ndwi))))./(max(max(cir_ndwi))...
% +abs(min(min(cir_ndwi)))));
case 'BNDWI_1_10'
cir_index=(cir(:,:,3)-10*cir(:,:,1))./(cir(:,:,3)+10*cir(:,:,1));
case 'AWEI'
cir_index=1*cir(:,:,3)-2.5*cir(:,:,2)-3*cir(:,:,1);
case 'IR'
cir_index=1-cir(:,:,1); % makes high IR correspond to high NDWI by subtracting from 255
end