Skip to main content
Question

How to assign lookup table to GRAY8 image


Forum|alt.badge.img+1

 

I have a shapefile of polygons where every polygon represents a vegetation class with attributes like the  class code, class description and (R,G,B) values.

I can rasterize with ImageRasterizer to generate a 4 band RGBA32 geotiff file with (R,G,B,A) values correctly assigned. 

The different vegetation classes is stored in a lookup table with this structure (no more than 50 entries):

ID,CODE_CLASS,DESCRIPTION_CLASS,R,G,B
1,100,Description class 1,255,255,0
2,200,Description class 2,24,95,205
...

To reduce the size of geotiff file I have generated 1 Band Greyscale (GRAY8) Geotiff (also with ImageRasterizer).  The result is correct, but I don't have any control about the value stored in band 0 and my lookup table describing vegetation class.

 

QUESTION: How can assign the lookup table in rasterization process to 1 Band Greyscale (GRAY8) ?

Is there a way to do this ? 

 

Than you very much in advanced !

4 replies

jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • May 9, 2019

You should be able to create a palette, either using the PaletteGenerator->PaletteExtractor on the RGB image, or by manipulating the lookup table directly.

 

 

You can then use the PaletteAdder to add the palette to the greyscale image.

 

 

You could alternatively using a string palette to add the class(or description) rather than the the RGB values, but that limits the output formats you can use, as not all of them accept string palettes.

Forum|alt.badge.img+1
  • Author
  • May 22, 2019

Thanks a lot @jdh !

You are right, It is possible to create or extract a palette from RGB image.

But in my case, it is not correct to add palette directly with PaletteAdder, because ImageRasterizer assign values to grayscale image that probably not match with palette classification. It is very important to maintain color classification because identifies vegetation class.

 

I have found the solution using fme_color attribute.

In the same way that in RGB image I assign fme_color=(R,G,B) values before use ImageRasterizer, in greyscale image I assign fme_color=(CODE_CLASS,CODE_CLASS,CODE_CLASS) to ensure that PaletteAdder assigns correctly class values.

Before ask this question I tried fme_color = CODE_CLASS (having in mind that grayscale image has only one band) but it doesn't work in that way. The trick is the way to assign values to fme_color, that's all !

 

Regards,


Forum|alt.badge.img+1
  • Author
  • May 22, 2019

Also you are right about that there are raster output formats that not accept string palettes, for ex. geoTIFF (with which I work).


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • May 22, 2019
ari wrote:

Thanks a lot @jdh !

You are right, It is possible to create or extract a palette from RGB image.

But in my case, it is not correct to add palette directly with PaletteAdder, because ImageRasterizer assign values to grayscale image that probably not match with palette classification. It is very important to maintain color classification because identifies vegetation class.

 

I have found the solution using fme_color attribute.

In the same way that in RGB image I assign fme_color=(R,G,B) values before use ImageRasterizer, in greyscale image I assign fme_color=(CODE_CLASS,CODE_CLASS,CODE_CLASS) to ensure that PaletteAdder assigns correctly class values.

Before ask this question I tried fme_color = CODE_CLASS (having in mind that grayscale image has only one band) but it doesn't work in that way. The trick is the way to assign values to fme_color, that's all !

 

Regards,

If you want to rasterize a single band image, use the NumericRasterizer instead of the ImageRasterizer, but instead of having an fme_color attribute, you need to have the value as the Z (use a 3D forcer).


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