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! |
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! |
Hi Michael & anonymous,
Can't you simply write "if (v != v) v = 0;" since NaN is not even equal to itself? It's funny—in older versions of Java, the "v != v" test was much faster than "Double.isNaN(v)" due to the overhead of method calls, but the JIT has since overcome this problem. -Curtis On Wed, Mar 23, 2011 at 12:40 PM, Michael Schmid <[hidden email]>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! >> > |
In reply to this post by mjlm
Hi,
On Mar 23, 2011, at 1:03 PM, 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? > A simple way is to use this macro... newValue = 0.0; counter = 0; for (y = 0; y < getHeight(); y++){ for (x = 0; x < getWidth(); x++){ p = getPixel(x,y); if (isNaN(p)) { setPixel(x, y, newValue); counter++; } } } print("" + counter + " pixels replaced"); Cheers, Ben > 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! > > -- > View this message in context: http://imagej.588099.n2.nabble.com/Replace-NaN-in-32-bit-images-with-0-tp6201020p6201020.html > Sent from the ImageJ mailing list archive at Nabble.com. |
In reply to this post by Michael Schmid
See http://rsbweb.nih.gov/ij/developer/macro/functions.html#isNaN
-----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Michael Schmid Sent: Wednesday, March 23, 2011 1:40 PM To: [hidden email] Subject: Re: Replace NaN in 32-bit images with 0 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 message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email. ================================= |
In reply to this post by Michael Schmid
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. |
Free forum by Nabble | Edit this page |