# Glint in WorldView 2 Image

8061
33
01-11-2012 06:05 PM
New Contributor
Hello All,

I got my hands on an 8 band WorldView 2 image, sadly the entire image is covered with sun glint since its a marine image... i would like to know of how to remove this glint problem... Thanks
Tags (3)
33 Replies
MVP Regular Contributor
Have a read of this paper: Hedley et al. (2005) Simple and robust removal of sun glint for mapping shallow-water
benthos. International Journal of Remote Sensing Vol. 26, No. 10, 2107�??2112.

Step by step instructions to implement this method are available for ENVI (not ArcGIS sorry).

I use some IDL code from ENVI to do this instead of the above manual method, though I do generate the samples with the ROI tool by hand):
```nirs=samples[*,*,7]
nird=data[*,*,7]
d=size(nirs,/dim)
i=where(nirs gt 0)
o=where(nird eq 0)
m=min(nirs)
m=nirs
m = m[(sort(m))[5 * N_ELEMENTS(m) / 100] ]
out=0
help, m

foreach b, bindgen(6) do begin

band=samples[*,*,b]
r=linfit(nirs,band)
band=data[*,*,b]
deglint=long(band - r[1] * (nird - m)+0.5)

deglint=0
if size(out, /n_dimensions) eq 0 then                 \$  ;Image stack doesn't exist yet
out=temporary(deglint)                                 \$
else                                                  \$  ;Concatenate image to stack
out=[[[temporary(out)]],[[temporary(deglint)]]]

endforeach

out=[[[temporary(out)]],[[data[*,*,6]]]]
out=[[[temporary(out)]],[[data[*,*,7]]]]

end
```

Again note that these methods are for ENVI, not ArcGIS. You could probably reimplement the code in numpy though.
New Contributor
Thanks lpinner, Now i got more to go on than before... as for the cook book i saw it before, and read it, sadly didnt understand much with what to do... considering that I'm still a beginner with all of this... I'll them out and see what i can come up with... BTW, as for the script that you attached, In Envi, where would i input it?
MVP Regular Contributor
It requires a full ENVI+IDL install, not just the ENVI runtime.  It also requires you have enough memory to load the entire image into RAM as I didn't bother writing any sort of tiling code, it was just a very rough hack that I whipped up to meet an immediate need.

To use my code:

• Save the code to a file with a ".pro" extension

• Start "ENVI + IDL" (not ENVI)

• In the main ENVI toolbar click File-> Export to IDL variable and export the WV2 as variable called "data"

• Create an ROI of a variety of deep ocean areas

• In the ROI tool dialog, select File->Subset data via ROIs

• In the main ENVI toolbar click File-> Export to IDL variable and export the subset as variable called "samples"

• At the ENVI> command prompt in the IDL workbench, type
`.r <path to>\<script>.pro`
i.e
`.r C:\Temp\deglint.pro`

• After the script completes you can get the image back into ENVI using  File-> Import from IDL variable (select the "out" variable)

New Contributor
Thanks again for your valuable input in regards to this matter... I preformed the procedure that you recommended, sadly i got the following error:

```
% Syntax error.
ENVI> .r C:\Temp\Glint.pro

foreach b, bindgen(6) do begin
^
% Syntax error.
At: C:\TEMP\Glint.pro, Line 12
% 1 Compilation error(s) in module \$MAIN\$.

```

MVP Regular Contributor
Works for me.

I just realised I left in some code I shouldn't have. Try the below (also attached):.
```nirs=samples[*,*,7]
nird=data[*,*,7]
d=size(nirs,/dim)
i=where(nirs gt 0)
o=where(nird eq 0)
m=min(nirs)
out=0
help, m

foreach b, bindgen(6) do begin

band=samples[*,*,b]
r=linfit(nirs,band)
band=data[*,*,b]
deglint=long(band - r[1] * (nird - m)+0.5)

deglint=0
if size(out, /n_dimensions) eq 0 then                 \$  ;Image stack doesn't exist yet
out=temporary(deglint)                                 \$
else                                                  \$  ;Concatenate image to stack
out=[[[temporary(out)]],[[temporary(deglint)]]]

endforeach

out=[[[temporary(out)]],[[data[*,*,6]]]]
out=[[[temporary(out)]],[[data[*,*,7]]]]

end
```

An example using the above code:
Before
[ATTACH=CONFIG]11237[/ATTACH]

After
[ATTACH=CONFIG]11238[/ATTACH]
New Contributor
Thanks again lpinner, I'll give it a go and let you know how it goes... BTW, from your experience, the three methods that you shared with me, which did you prefer? in terms of results?

I know the IDL looks to be the easiest of them all...
MVP Regular Contributor
What three methods? I only recall two.  Both the "cookbook" method and my IDL code implement the algorithm detailed in the paper by Hedley et al. (2005) that I linked to.
I have not used the "cookbook" method. But it should give the same results, it's doing the same thing.

By the way... if you have any land in your image, this method will make it look terrible. As is noted in the paper:
the algorithm is valid only for submerged pixels
.
New Contributor
Ahh, i see, well that's good to know... but sadly yet again it didn't work,even with the file that you gave me...

```foreach b, bindgen(6) dobegin
^
% Syntax error.
At: C:\TEMP\deglint.pro, Line 10
% 1 Compilation error(s) in module \$MAIN\$.
% No valid main program present.
```

BTW, i have attached a photo of what the area I'm dealing with looks like...

[ATTACH=CONFIG]11246[/ATTACH]

So i guess I'm good, since there isn't much land, except for that narrow strip... BTW, does this image look to you beyond reparable?
MVP Regular Contributor
That's a different error to your previous post. Are you typing it in or copying it? There should be a space between "do" and "begin".