|
Re: envi/idl question from a newbie [message #16162 is a reply to message #16161] |
Fri, 02 July 1999 00:00  |
Peter Mason
Messages: 145 Registered: June 1996
|
Senior Member |
|
|
"Mark Amend" <mark.amend@hmsc.orst.edu> wrote:
> I'm using ENVI 3.1/IDL 5.1 and would like to set pixel values of 0.0
to NaN
> in order to carry out some analyses without including 0.0 values. Is
there
> an easy way to do this with the Band Math function of ENVI, or is
there a
> quick and dirty IDL solution?
Mark, I suggest, tentatively, that NaN may not be your best solution
here. Some IDL functions / routines are NaN-aware, but some aren't.
Some even crash, e.g., MEDIAN() (on WinNT, at least). IDL code that
uses straight arithmetic or any of the NaN-oblivious functions - and
doesn't filter out or deal with denormal values explicitly - can lead to
unexpected results when there are some NaNs in the data stream. I
stand to be corrected, but I think that ENVI includes some code like
this. (I've come unstuck once or twice with things like an MNF
transform of an image that had some NaN values.)
In some cases a MASK BAND can be used along with the input to an ENVI
function.
To make a mask band from a single-band image, use band math
with something like: B1 NE 0.0 and then map B1 to the image band on
which you want to run the test.
But note that (as pointed out by Martin Schultz in a recent post) exact
tests on floating-point numbers can be disappointing - it's often best
to test for an absolute difference within a small tolerance.
Or you could easily make an ENVI ROI from the mask band (or even the
original input band, though you might need to make 2 ROIs for your test)
with ENVI's "image threshold to ROI" function. This could then be used
in the many ENVI operations that accept spatial subsetting by ROI.
If you really do want to assign NaN to zero pixels then I'm not aware of
a straight way to do it in ENVI's band math. (Band math expressions
are equation RHS's, and ENVI unfortunately doesn't permit the use of
IDL's test?resultA:resultB expressions here.) But it is very easy to
write your own band math functions. You could do this task as
follows:
Write the following little routine. Call it zerotonan.pro and put it
in ENVI's save_add subdir.
FUNCTION ZeroToNan,B1
rv=b1 ;output=input, for now
j=where(b1 eq 0.0,tc) ;your test (remember about exact float tests!)
if (tc gt 0L) then rv[temporary(j)]=!VALUES.F_NAN
RETURN,rv
END
Then, in ENVI's band math, use the expression: ZEROTONAN(B1)
Good luck,
Cheers
Peter Mason
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
|
|
|
Re: envi/idl question from a newbie [message #16170 is a reply to message #16161] |
Thu, 01 July 1999 00:00  |
Mark Amend
Messages: 2 Registered: July 1999
|
Junior Member |
|
|
I forgot to add: the file is floating point, BSQ, and georeferenced, if that
matters any.
Regards,
Mark
----------
In article <7lg50d$m2c$1@news.NERO.NET>, "Mark Amend"
<mark.amend@hmsc.orst.edu> wrote:
> Dear IDL group-
>
> I'm using ENVI 3.1/IDL 5.1 and would like to set pixel values of 0.0 to NaN
> in order to carry out some analyses without including 0.0 values. Is there
> an easy way to do this with the Band Math function of ENVI, or is there a
> quick and dirty IDL solution?
>
> Thanks for any help
>
> Sincerely,
>
> Mark Amend
|
|
|