In the past (maybe FME 2012 and earlier), the RasterExpressionEvaluator had only one field for entering expressions, and semicolons were used to separate multiple expressions for each band.
Â
But the interface has been changed. Currently you have to enter expressions seperately for each row associated to a band, if your raster has multiple bands. When you used semicolons in an expression, such an error occurs.
Â
Â
I guess you are going to calculate a value for one band.
Â
i.e.
Â
If A>0] == 0 Then 3
Â
Else If Ae0] == 1 Then 4
Â
Else If As0] == 2 Then 5 ... and so on.
Â
Â
If my understanding is correct, you can use a nested "if" statement.
Â
e.g.
Â
@if (A 0] == 0, 3,
Â
@if (AÂ0] == 1, 4,
Â
@if (A>0] == 2, 5,
Â
@if (Ap0] == 3, 6,
Â
@if (A<0] == 4, 7,
Â
@if (A,0] == 5, 8,
Â
@if (A80] == 6, 9,
Â
@if (A 0] == 7, 10,
Â
@if (A 0] == 8, 11, 12)))))))))
Â
Â
However, the error says your expression is going to calculate values for 546 entries. It means that you have 546 conditions in fact.
Â
Although it may be possible theoretically to write a nested "if" statement for such many conditions, it would be too complicated and also troublesome.
Â
Â
There could be more simple way. For example, if the requirement is to just add 3 to the original pixel value, this expression would be enough.
Â
Ao0] + 3
Â
Â
If you explain the requirement concretely, we could consider a workaround.
Thanks again.
Â
Â
What i've tried was using an older raster expression evaluator that had the text box input for interpretations and was able to copy paste the correct number of matching interpretations to the expressions. i.e 546 interpretations, 546 evaluations.
Â
The problem with that was, after processing every pixel contained 546 bands.
Â
Â
Just to describe what I have in further detail. The histogram matching has the source image and target image broken up into R,G,B and the percentage of occuring decimal values 0-255 across both images is calculated. Comparing these percentage values, I can determine, for example, when my target image has a Red8 value of 50, this is equivalent to source image Red8 30. So i've created a mapping of new RGB values for my target image. a30,50]Â
Â
Â
So with the mapping I need to change the target image's rgb values according to the new mapping
Â
Â
>6, 7, 8, 9, 10, 11, 11, 12, 13, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20, 21, 21, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 29, 29, 30, 30, 31, 32, 32, 33, 34, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 66, 67, 68, 69, 70, 71, 71, 72, 73, 74, 75, 75, 76, 77, 77, 78, 79, 79, 80, 81, 81, 82, 83, 83, 84, 84, 85, 85, 86, 87, 87, 88, 88, 89, 89, 90, 91, 91, 92, 93, 93, 94, 95, 95, 96, 97, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 117, 118, 120, 121, 122, 123, 125, 126, 127, 128, 130, 133, 135, 136, 138, 140, 142, 144, 147, 148, 149, 151, 152, 152, 154, 156, 156, 157, 157, 158, 160, 161, 161, 161, 161, 162, 162, 162]Â
Â
Â
The array above represents the mapping of a red channel. The index of the array would describe the decimal value. For example, Decimal 0 should be 6 instead. Decimal 1 should be 7.
Â
Â
Summary, I need a way to map new rgb values to a raster and write the new raster image out.
Â
Â
I'm now considering converting image to point cloud, change the red green blue component of the points, and then rasterize the point cloud.
I agree that it would be easy to generate the expression using a script.
Ok, so the nested expression works but I've now hit some type of limit with how many nestings it can support. I've reach about 130 nests, but it will not do the full 182 let alone 546, it simple says "error running translation" . I can work around this by dividing the script into two per channel, but ultimately costs me time.Â
I tried the palette approach.
Â
Firstly, create 3 pallete attributes with 256 entries for each band. Use "GRAY8" as the value interpretation for every pallete. These pallete attributes will be used as value mapping table for each band. See also the help doc of the RasterPaletteExtractor to learn about the format of pallete attribute.
Â
e.g.
Â
-----
Â
GRAY8
Â
0 6
Â
1 7
Â
2 8
Â
3 9
Â
4 10
Â
...
Â
254 ???
Â
255 ???
Â
-----
Â
Â
Divide the data flow into 3 streams and add these transformers seperately for each band.
Â
(1) RasterSelector - select 2 bands
Â
Band and Pallete List: 1;2 ("0;2" for green band, "0;1" for blue band)
Â
(2) RasterBandRemover - remove selected bands. i.e. keep one band
Â
(3) RasterSelector - select the first band
Â
Band and Pallete List: 0
Â
(4) RasterBandInterpretationCorercer
Â
Destination Interpretation Type: UInt8
Â
(5) RasterPaletteAdder
Â
Palette Attribute:
<specify the palette attribute for the band>Â
(6) RasterPaletteResolver
Â
(7) RasterBandInterpretationCoercer - restore the original band interpretation
Â
Destination Interpretation Type: Red8 ("Green8" for green band, "Blue8" for blue band)
Â
(8) AttributeCreator
Â
_order = 0 (1 for green band, 2 for blue band)
Â
Â
Send the 3 rasters to a Sorter to sort by "_order" ascending.
Â
Finally, add a RasterBandCombiner to re-create an RGB raster.
Â
Â
There could be smarter way...