Skip to main content
Solved

Change all raster values of one pixel if all bands all three bands are 0


jeroen
Contributor
Forum|alt.badge.img+8

I'm trying to merge different raster features to one image using the overlap value option in the RasterMosaicker. My end goal is to merge these images based on how the look in RGB. The order of the layers is done using the sorter just before the merge. Using the transparency is key because you need to see the different layers when there is "a NoData pixel"

The problem i'm facing now is that the NoData values differs with each raster or even that some rasters do not even have a NoData value (even do it should). For the last situation i want to translate the raster a bit so the can be used for a NoData value of 255. By visual inspection i could see that that only the withe (r=0,g=0,b=0)colour needs to be replaced with transparency.

My first step is converting all 255 values in RED8, GREEN8 and BLUE8 to 254 so 255 is freed. For the next step i would like to do covert only the RED8, GREEN8 and BLUE8 values of a pixel that all three have the 0 value to 255. I tried using the RasterCellValueReplacer with the settings with and between  0 and 0  to be set to 255 and then setting the NoData value to 255 but the problem is that all 0 values are converted. Meaning that a red area (254,0,0) changes colour. 

TLDR: Is there a value mapper kind of tool that could do the following (sudocode) trick:

IF pixel == RED8 = 0 AND GREEN8 = 0 and BLUE8 = 0
	RED8 = 255 AND GREEN8 = 255 AND BLUE8 = 255 
otherwise:
	Do nothing

Best answer by jdh

You can do that with a RasterExpressionEvaluator conditional statement

 

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[0])

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[1])

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[2])

View original
Did this help you find an answer to your question?

5 replies

jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • Best Answer
  • October 12, 2018

You can do that with a RasterExpressionEvaluator conditional statement

 

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[0])

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[1])

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[2])


jeroen
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • October 12, 2018
jdh wrote:

You can do that with a RasterExpressionEvaluator conditional statement

 

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[0])

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[1])

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[2])

Got an error saying that it only accepts 3 arguments. 

 

2018-10-12 17:06:25|  20.2|  0.5|ERROR |Expression Evaluator: The 'if' function requires 3 argument(s)but was provided with 4 argument(s)

2018-10-12 17:06:26|  20.5|  0.0|ERROR |A fatal error has occurredCheck the logfile above for details
So i changed it to:

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[0])

 

 

But without a good result. How should i set the interpretation? Both the following settings did not work:

 

0684Q00000ArMGGQA3.png

 


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • October 12, 2018
jeroen wrote:
Got an error saying that it only accepts 3 arguments. 

 

2018-10-12 17:06:25|  20.2|  0.5|ERROR |Expression Evaluator: The 'if' function requires 3 argument(s)but was provided with 4 argument(s)

2018-10-12 17:06:26|  20.5|  0.0|ERROR |A fatal error has occurredCheck the logfile above for details
So i changed it to:

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[0])

 

 

But without a good result. How should i set the interpretation? Both the following settings did not work:

 

0684Q00000ArMGGQA3.png

 

It should work.  I tend to use Preserve Interpretation, unless I have a reason not to.

 

conditionalallbands.fmw

 

 


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • October 12, 2018
jeroen wrote:
Got an error saying that it only accepts 3 arguments. 

 

2018-10-12 17:06:25|  20.2|  0.5|ERROR |Expression Evaluator: The 'if' function requires 3 argument(s)but was provided with 4 argument(s)

2018-10-12 17:06:26|  20.5|  0.0|ERROR |A fatal error has occurredCheck the logfile above for details
So i changed it to:

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[0])

 

 

But without a good result. How should i set the interpretation? Both the following settings did not work:

 

0684Q00000ArMGGQA3.png

 

Try changing the order of bands to Red8, Green8, Blue8.

 

 


jeroen
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • October 12, 2018
jdh wrote:

You can do that with a RasterExpressionEvaluator conditional statement

 

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[0])

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[1])

 

If (A[0] == 0 && A[1] == 0 && A[2] == 0, 255, A[2])

 

Setting it on Preserve did the trick. Thanks a million!

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings