10 Aug 2009 02:10 PM 

Using band math is there a way that I could assign all values that equal zero to another value without affecting the other digital numbers.
For example how could I write if b1=0 make equal to 100?
Thanks




Deleted User New Member
Posts:
10 Aug 2009 03:15 PM 

There is a way to do this and the Help docs provide an example similar to what you are undertaking. Consider the following excerpt:
For example, to find all pixels with a negative value and replace them with the value 999, you could use the following Band Math expression:
(b1 lt 0) * (999) + (b1 ge 0) * b1
The relational operators return a one for true and a zero for false, so the portion of the expression that reads (b1 lt 0) will return an array of the same dimensions as b1 filled with ones where b1 was negative and zeros everywhere else. Multiplying this by the replacement value (999) affects only those pixels that met the criterion of being negative. The second relational operator (b1 ge 0) is the complement to the first, finding all of the pixels that are positive or zero, which is multiplied by their original value and added to the replacement value array.




Deleted User New Member
Posts:
10 Aug 2009 05:58 PM 

great, thank you!




Deleted User New Member
Posts:
15 Jan 2010 08:40 AM 

This earlier post below was very helpful in describing the use of conditional statements in band math. I have a followon question that I hope someone can address. Using this earlier post as an example, I expanded this to produce 999 as a background, and to calculate a more complex expression for my nonbackground values:
exp = '(b1 eq 0) * (999) + (b1 gt 0 )*(float(b2) + float(b1))'
This works great  I can add/multiply/subtract those bands in the expression for my nonbackground pixels, and all original background zeros become 999. However, if I DIVIDE the bands in the expression, all of my background values become NaN. I understand that I would get NaN's for a divide by zero, but zeros should not be encountered since those cases fall under the first condition.
Any suggestions would be greatly appreciated.
[QUOTE]area_51 wrote
There is a way to do this and the Help docs provide an example similar to what you are undertaking. Consider the following excerpt:
For example, to find all pixels with a negative value and replace them with the value 999, you could use the following Band Math expression:
(b1 lt 0) * (999) + (b1 ge 0) * b1
The relational operators return a one for true and a zero for false, so the portion of the expression that reads (b1 lt 0) will return an array of the same dimensions as b1 filled with ones where b1 was negative and zeros everywhere else. Multiplying this by the replacement value (999) affects only those pixels that met the criterion of being negative. The second relational operator (b1 ge 0) is the complement to the first, finding all of the pixels that are positive or zero, which is multiplied by their original value and added to the replacement value array.
[/QUOTE]




MariM Veteran Member
Posts:2396
30 Mar 2010 12:05 PM 

Which part of the equation are you dividing? I find it always helps to break down each section of my equation and output these files from band math. Then I can see exactly what the math is doing as I go through each section.




MariM Veteran Member
Posts:2396
30 Mar 2010 12:08 PM 

Try this:
(9999 * finite(b1, /nan)) + ( finite(b1) * (b1 > (1e+34) ) )
will produce a result where all nonNaN data values are preserved and all pixels with NaN values are assigned the value 9999.




Krista West New Member
Posts:8
18 Jul 2023 02:22 PM 

I am attempting to use Band Math with individual bands to assign... #1 ... all negative pixel values with 0.000001, and #2 ... all pixel values greater than 100 to 100. I do not want to mask these negative or 100+ values; they still need to be included in my analyses. The above Band Math expression: (b1 lt 0) * (999) + (b1 ge 0) * b1 (from 10 Aug 2009) helps me with #1, but I'm continuing to struggle with #2. What expression can I use to identify all pixel values that are greater than 100, and assign them as (or replace or set them to) 100? Thank you! Krista




Krista West New Member
Posts:8
19 Jul 2023 12:30 PM 

[quote] Posted By Krista West on 18 Jul 2023 02:22 PM I am attempting to use Band Math with individual bands to assign... #1 ... all negative pixel values with 0.000001, and #2 ... all pixel values greater than 100 to 100. I do not want to mask these negative or 100+ values; they still need to be included in my analyses. The above Band Math expression: (b1 lt 0) * (999) + (b1 ge 0) * b1 (from 10 Aug 2009) helps me with #1, but I'm continuing to struggle with #2. What expression can I use to identify all pixel values that are greater than 100, and assign them as (or replace or set them to) 100? Thank you! Krista [/quote] I believe I figured this out. I need to run it as two operations: First, I can use (b1 lt 0) * (0.0001) + (b1 ge 0) * b1 to identify all negative pixel values and assign them as something very close to 0 (in my case, 0.0001). Second, I can use (b1 gt 100) * (100) + (b1 le 100) * b1 to identify all values greater than 100 and assign them as 100. Note: Using ((b1 lt 0) * (0.0001) + (b1 ge 0) * b1) and ((b1 gt 100) * (100) + (b1 le 100) * b1) just results in values greater than 100 being assigned a value of 100, but the negative values remain. I compared this to my original image and the number of pixels is the same, so I think I'm doing this correctly. However, if anyone sees a glaring error, please let me know. Thank you!




Marcos Montes New Member
Posts:33
15 Sep 2023 07:51 AM 

Krista: Running it as two operations (if using band math) sounds like the correct way to proceed. I don't see a glaring error in that process. M



