Solved

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

  • 12 October 2018
  • 5 replies
  • 12 views

Badge +7

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
icon

Best answer by jdh 12 October 2018, 16:46

View original

5 replies

Badge +22

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])

Badge +7

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 occurred. Check 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

 

Badge +22
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 occurred. Check 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

 

 

Userlevel 2
Badge +17
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 occurred. Check 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.

 

 

Badge +7

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