comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: divide by zero problems
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: divide by zero problems [message #15333] Thu, 13 May 1999 00:00
edward.s.meinel is currently offline  edward.s.meinel
Messages: 12
Registered: May 1999
Junior Member
C'mon guys, this is IDL not C...

Mark Rehbein <mrehbein@aims.gov.au> wrote:

> Basically, my images have cloud pixels that I have changed to a zero
> value.

OK so far...

> I also have a mask of the image that has values 1 for good pixel
> and 0 for bad pixels (cloud).

So you have new_image = image*mask

> I then add all my images together to get
> a "sum image" and add all my masks together to get a "sum mask".


Oh, then its

FOR i = 0, number_of_images-1 DO BEGIN
image_ sum = image_sum + image[*, *, i]*mask[*, *, i]
mask_sum = mask_sum + mask[*, *, i]
END

> Now to composite or average the images I do the following:
>
> composite=sum image/ sum mask.

i.e., you want to normalize the result. The you should use
something like:

composite = image_sum/(mask_sum + (mask_sum EQ 0))

> In fact I get whole image of
> NaN's in my composite even though my sum image and sum mask have
> decent values in them.

What is the TYPE of image? How many images? image_sum should be declared
at least one TYPE higher than image (if image is BYTE then image_sum
should be INTEGER; if image is INTEGER then image_sum should be LONG;
etc.). If there are more than 256 images then mask_sum should be
declared INTEGER.

Ed Meinel


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
Re: divide by zero problems [message #15335 is a reply to message #15333] Thu, 13 May 1999 00:00 Go to previous message
&lt;asowter is currently offline  &lt;asowter
Messages: 5
Registered: March 1999
Junior Member
I also had a similar problem but I used the FINITE function to test the
result. FINITE(variable) returns false if you have a NaN and true
otherwise - it's a nice test and allows you to skip or assign another value
based on the input values (say if you know that there a tendency to a
limit).

Andy
Re: divide by zero problems [message #15355 is a reply to message #15333] Tue, 11 May 1999 00:00 Go to previous message
korpela is currently offline  korpela
Messages: 59
Registered: September 1993
Member
In article <3737C79C.372FA82E@aims.gov.au>,
Mark Rehbein <mrehbein@aims.gov.au> wrote:
> composite=sum image/ sum mask.
>
> sometimes my images are very cloudy and as such my "sum mask" has zero's
> in it and likewise for my "sum image". So I get divide by zero's and
> NaN's in my resultant composite image. In fact I get whole image of
> NaN's in my composite even though my sum image and sum mask have decent
> values in them.

Rather than using 0 in the mask image you could use a small non-zero value
like 1e-6.

Another option is after the division you can set the NaN values to another
value. The following statement will set NaN pixels in an image to 0.

image(where(image ne image))=0

Eric
--
Eric Korpela | An object at rest can never be
korpela@ssl.berkeley.edu | stopped.
<a href="http://setiathome.ssl.berkeley.edu/~korpela">Click for home page.</a>
Re: divide by zero problems [message #15358 is a reply to message #15355] Tue, 11 May 1999 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Mark Rehbein (mrehbein@aims.gov.au) writes:

> I'm having problems with floating point divide by zero's. The
> application I'm using IDL for is image composition and masking.
> Now to composite or average the images I do the following:
>
> composite=sum image/ sum mask.
>
> sometimes my images are very cloudy and as such my "sum mask" has zero's
> in it and likewise for my "sum image". So I get divide by zero's and
> NaN's in my resultant composite image. In fact I get whole image of
> NaN's in my composite even though my sum image and sum mask have decent
> values in them.

Usually, something like this works:

composite = sum_image / (sum_mask > 10E-6)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Making an array of structures containing pointers
Next Topic: coherence test implementation

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:27:32 PDT 2025

Total time taken to generate the page: 0.00604 seconds