1

I have image (RGBA) data that needs to convert values ​​using an existing palette. I have the palette available to get each RGB(A) -value translated to a correct value.

I need to convert RGB value into one band. After that I need to use palette and convert each RGB value to palette value.

Example I have red color pixel (RGB 255, 0,0) in original image. Then I have value 12 in palette which has correct value to convert red pixel to value 12.

How to do that?

RGB data

The palette has total 25 values and looks like this:

RGB24
1 97,100,101
2 148,147,148
3 195,204,209
4 166,159,255
5 17,37,250
6 52,92,255
8 6,231,255
10 54,199,6
12 255,0,0
.
.

current FME transformers

I have tried the followed FME process but its wrong.

Which transformers should be used in FME?

final result of raster palette adder

1
  • What does the RasterBandInterpretationCoercer do? Is it converting the original RGB to a numeric value? Because I don't think you can add an RGB palette to an existing RGB image. Commented May 6, 2021 at 20:28

1 Answer 1

1

So the main issue is that the RasterBandInterpretationCoercer transformer converts RGB values into uint8 values. Those values can be from 0-255, and yet you've only got 25 entries in the palette.

The other issue is that the RasterBandInterpretationCoercer transformer converts 3 RGB bands into 3 more uint8 values. I don't really know what colour you'd get if you have 3 bands all with a palette applied.

Either way, I think that a RasterExpressionEvaluator transformer will help. For example, here I use it to turn the rgb into a single uint value:

enter image description here

I just averaged the three RGB values into one uint8.

Now, because you've only got 25 entries in your palette, I suspect you should group cells into groups of 10. For example: 0-9 = 0, 10-19 = 1, 20-29 = 2, and so on. You could instead expand the palette to 255 values, but I don't think that's such a great method.

The easiest way to do that is to divide by 30 instead of 3 in the RasterExpressionEvaluator:

(A[0]+A[1]+A[2])/30

I tried this and it seemed to work fine. Of course, it depends on how you want to map the source to the destination cells, but if you've got 25 palette entries then they'll need the source cells grouping in some way and this seems the best to me.

3
  • Example I have red color pixel (RGB 255, 0,0) in original image. Then I have value 12 in palette which has correct value to convert red pixel to value 12. How to do that?
    – Mickeler
    Commented May 7, 2021 at 6:38
  • Thanks Mark for yours answer! Do you have any idea to convert RGB value into one band. Like Band 0 (255, 0, 0). Then palette "finds" that value 12 is correct for RGB(255,0,0). Overall using the palette and convert each RGB value to palette value. Is it possible?
    – Mickeler
    Commented May 7, 2021 at 9:25
  • Well, that's pretty much what the RasterExpressionEvaluator is doing. Above it's turning it into one band by using the average of R+G+B (A0+A1+A2). But you could certainly vary how it does that. For example, you could just create a new uint8 band with the expression A[0] - that way you're simply copying the red value. Then you need a palette of 255 values. It all depends on how you're planning to map the RGB to the palette values. Commented May 7, 2021 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.