Login  Register

Re: Replace NaN in 32-bit images with 0

Posted by Jeffrey B. Woodward on Mar 23, 2011; 7:01pm
URL: http://imagej.273.s1.nabble.com/Replace-NaN-in-32-bit-images-with-0-tp3685307p3685309.html

The best (most readable) option is to use Double.isNaN(v); however, if
you are looking for a "clever" inequality that is "more correct" and
simpler than the one suggested by Michael Schmid, you can simply test
whether or not v == v...which is only false for NaN. In summary:

Best option:
     if (Double.isNaN(v)) v = 0;

"Clever"/obscure option:
     if (v != v) v = 0;

-Woody


On 3/23/2011 1:40 PM, Michael Schmid wrote:

> Hi anonymous,
>
> this may look stupid, but it works at least with the NaN created by
> division by zero:
> Enter in the Process>Math>Macro
>     if (!(v<1) && !(v>0)) v=0;
>
> A NaN value fulfills no inequality; all 'true' numbers are either <1
> or >0 or both.
> Of course, a macro function 'isNaN(value)' would be nice to have...
>
> Michael
> ________________________________________________________________
>
> On 23 Mar 2011, at 18:03, mjlm wrote:
>
>> Hi there,
>>
>> Is there a simple way to "reset" all pixels with the value "NaN" to a
>> specified numeric value, e.g. 0?
>>
>> I couldn't find a way to do this properly in ImageJ...one ugly
>> workaround I
>> came up with is to save the image as text and then simply find &
>> replace all
>> occurences of NaN, but that's not a feasible option for large
>> stacks...there
>> MUST be a better way.
>>
>> Thanks!


--
This email, including attachments, may include confidential information and is intended solely for the use of the individual or entity to which it is addressed.  If you are not the intended recipient, be advised that any dissemination, distribution or copying of this email is prohibited.  If you have received this email in error, please notify the sender via telephone or by replying to this message, and destroy this message immediately.