Classification of RGB png (or tiff) using [red] [green] [blue]

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Classification of RGB png (or tiff) using [red] [green] [blue]

Agnès Tellez-Arenas

Dear all,

 

I am trying to classify a PNG (could be a tiff) which has the 3 bands (red, green, blue), each from 0..255.

I need to classify (not just display it as it is), because I have used those 3 bands to “code” elevation values (it’s a hightmap).

 

I am using a PNG to encode the elevation value on those r,g,b bands, rather than one tiff containing directly the elevation on the pixel, because the size of the PNG is smaller than tiff (and I need to store a big amount of images…).

The formula to “encode” the elevation is

#min=-50, max=1000 ((r * 256 + g + b / 256) *  (Zmax-Zmin)/(65536)) + Zmin*  

Which I translated as

CLASS #min=-50, max=1000 ((r * 256 + g + b / 256) *  (Zmax-Zmin)/(65536)) + Zmin*

                                               EXPRESSION ( ((( (red]*256) +[green] +([blue]/256)) * (1050/65536)) - 50) <= 0)

                                               STYLE

                                                               COLOR 100 195 215

                                                               OPACITY 35

                                               END

                               END      

But, [red]=[green]=[blue]= the value of the first band (red). Always.

 

In documentation I can see (http://mapserver.org/mapfile/expressions.html)

For Raster Data layers special attributes have been defined that can be used for classification, for example:

  • [PIXEL] ... will become the pixel value as number
  • [RED], [GREEN], [BLUE] ... will become the color value for the red, green and blue component in the pixel value, respectively.

And (http://mapserver.org/el/input/raster.html)

There is no need to specify a CLASSITEM. The raw pixel value itself (“[pixel]”) and, for paletted images, the red, green and blue color associated with that pixel value (“[red]”, “[green]” and “[blue]”) are available for use in classifications.

 

Hope someone can help me on that!

Thanks!

 

 

Here is my MapFile.

 

MAP

                NAME "test"

                STATUS OFF

                SIZE 256 256

                MAXSIZE 4096

                RESOLUTION 96               

                EXTENT 253999.500 6884000.500 254999.500 6885000.500

                UNITS DD           

                IMAGETYPE png

                IMAGECOLOR 255 255 255

PROJECTION

        "init=epsg:2154"

             END

                WEB

                               TEMPLATE "../etc/html_template/getcapabilities_wms_130.html"

                               METADATA

                               (…)

                               END

                END

               

                LAYER

                  NAME  "test"

                 TYPE   RASTER

                  DATA   "/mnt/nemesis_resultats/flood/v3/v4_1m/RGEALTI_FXX_0224_6753_MNT_LAMB93_IGN69_png.png"

                  #PROCESSING "BANDS=1,2,3" #this line crashes with a “drawGDAL(): Unable to access file. Attempt to classify 24bit image, this is unsupported.”

 

                  STATUS ON

                  PROJECTION

                     "init=epsg:2154"

                  END

                  METADATA

                                (…)                       

                  END

                 

                               CLASS #min=-50, max=1000 ((r * 256 + g + b / 256) *  (Zmax-Zmin)/(65536)) + Zmin*

                                               EXPRESSION ( ((( (red]*256) +[green] +([blue]/256)) * (1050/65536)) - 50) <= 0)

                                               STYLE

                                                               COLOR 100 195 215

                                                               OPACITY 35

                                               END

                               END      

                              

                              

                END #LAYER

   

END 

# End of MapFile


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Classification of RGB png (or tiff) using [red] [green] [blue]

jratike80

Hi,

 

You have an interesting theoretical challenge but I would still make it in another way. First, it would be easier to use single band 16-bit png instead of 3-band 8-bit png. And second, compressed tiff is not much bigger than png. Use the deflate method which is the same method that png is using. For DEMs I would recommend to use the option “predictor=2”.

 

Here are numbers from a quick test with 16-bit DEM file.

gdal_translate -of GTiff -co compress=deflate –co tiled=yes -co predictor=2 dem.png dem.tif

 

 

png:  1326381 bytes

tiff:   1394597 bytes

 

Tiled tiff with overviews added with the gdaladdo utility is also much better (=faster) format for MapServer that png files. Overviews add 25% to the file size but it is worth it.

 

-Jukka Rahkonen-

 

 

 

Lähettäjä: mapserver-users [mailto:[hidden email]] Puolesta Tellez-Arenas Agnes
Lähetetty: 4. tammikuuta 2018 16:40
Vastaanottaja: [hidden email]
Aihe: [mapserver-users] Classification of RGB png (or tiff) using [red] [green] [blue]

 

Dear all,

 

I am trying to classify a PNG (could be a tiff) which has the 3 bands (red, green, blue), each from 0..255.

I need to classify (not just display it as it is), because I have used those 3 bands to “code” elevation values (it’s a hightmap).

 

I am using a PNG to encode the elevation value on those r,g,b bands, rather than one tiff containing directly the elevation on the pixel, because the size of the PNG is smaller than tiff (and I need to store a big amount of images…).

The formula to “encode” the elevation is

#min=-50, max=1000 ((r * 256 + g + b / 256) *  (Zmax-Zmin)/(65536)) + Zmin*  

Which I translated as

CLASS #min=-50, max=1000 ((r * 256 + g + b / 256) *  (Zmax-Zmin)/(65536)) + Zmin*

                                               EXPRESSION ( ((( (red]*256) +[green] +([blue]/256)) * (1050/65536)) - 50) <= 0)

                                               STYLE

                                                               COLOR 100 195 215

                                                               OPACITY 35

                                               END

                               END      

But, [red]=[green]=[blue]= the value of the first band (red). Always.

 

In documentation I can see (http://mapserver.org/mapfile/expressions.html)

For Raster Data layers special attributes have been defined that can be used for classification, for example:

  • [PIXEL] ... will become the pixel value as number
  • [RED], [GREEN], [BLUE] ... will become the color value for the red, green and blue component in the pixel value, respectively.

And (http://mapserver.org/el/input/raster.html)

There is no need to specify a CLASSITEM. The raw pixel value itself (“[pixel]”) and, for paletted images, the red, green and blue color associated with that pixel value (“[red]”, “[green]” and “[blue]”) are available for use in classifications.

 

Hope someone can help me on that!

Thanks!

 

 

Here is my MapFile.

 

MAP

                NAME "test"

                STATUS OFF

                SIZE 256 256

                MAXSIZE 4096

                RESOLUTION 96               

                EXTENT 253999.500 6884000.500 254999.500 6885000.500

                UNITS DD           

                IMAGETYPE png

                IMAGECOLOR 255 255 255

PROJECTION

        "init=epsg:2154"

             END

                WEB

                               TEMPLATE "../etc/html_template/getcapabilities_wms_130.html"

                               METADATA

                               (…)

                               END

                END

               

                LAYER

                  NAME  "test"

                 TYPE   RASTER

                  DATA   "/mnt/nemesis_resultats/flood/v3/v4_1m/RGEALTI_FXX_0224_6753_MNT_LAMB93_IGN69_png.png"

                  #PROCESSING "BANDS=1,2,3" #this line crashes with a “drawGDAL(): Unable to access file. Attempt to classify 24bit image, this is unsupported.”

 

                  STATUS ON

                  PROJECTION

                     "init=epsg:2154"

                  END

                  METADATA

                                (…)                       

                  END

                 

                               CLASS #min=-50, max=1000 ((r * 256 + g + b / 256) *  (Zmax-Zmin)/(65536)) + Zmin*

                                               EXPRESSION ( ((( (red]*256) +[green] +([blue]/256)) * (1050/65536)) - 50) <= 0)

                                               STYLE

                                                               COLOR 100 195 215

                                                               OPACITY 35

                                               END

                               END      

                              

                              

                END #LAYER

   

END 

# End of MapFile


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Classification of RGB png (or tiff) using [red] [green] [blue]

Agnès Tellez-Arenas

Thanks a lot for this answer, I will certainly find a solution with your suggestions, will probably try both!

 

Thanks

Agnès

 

De : Rahkonen Jukka (MML) [mailto:[hidden email]]
Envoyé : jeudi 4 janvier 2018 16:04
À : Tellez-Arenas Agnes <[hidden email]>; [hidden email]
Objet : Re: [mapserver-users] Classification of RGB png (or tiff) using [red] [green] [blue]

 

Hi,

 

You have an interesting theoretical challenge but I would still make it in another way. First, it would be easier to use single band 16-bit png instead of 3-band 8-bit png. And second, compressed tiff is not much bigger than png. Use the deflate method which is the same method that png is using. For DEMs I would recommend to use the option “predictor=2”.

 

Here are numbers from a quick test with 16-bit DEM file.

gdal_translate -of GTiff -co compress=deflate –co tiled=yes -co predictor=2 dem.png dem.tif

 

 

png:  1326381 bytes

tiff:   1394597 bytes

 

Tiled tiff with overviews added with the gdaladdo utility is also much better (=faster) format for MapServer that png files. Overviews add 25% to the file size but it is worth it.

 

-Jukka Rahkonen-

 

 

 

Lähettäjä: mapserver-users [[hidden email]] Puolesta Tellez-Arenas Agnes
Lähetetty: 4. tammikuuta 2018 16:40
Vastaanottaja: [hidden email]
Aihe: [mapserver-users] Classification of RGB png (or tiff) using [red] [green] [blue]

 

Dear all,

 

I am trying to classify a PNG (could be a tiff) which has the 3 bands (red, green, blue), each from 0..255.

I need to classify (not just display it as it is), because I have used those 3 bands to “code” elevation values (it’s a hightmap).

 

I am using a PNG to encode the elevation value on those r,g,b bands, rather than one tiff containing directly the elevation on the pixel, because the size of the PNG is smaller than tiff (and I need to store a big amount of images…).

The formula to “encode” the elevation is

#min=-50, max=1000 ((r * 256 + g + b / 256) *  (Zmax-Zmin)/(65536)) + Zmin*  

Which I translated as

CLASS #min=-50, max=1000 ((r * 256 + g + b / 256) *  (Zmax-Zmin)/(65536)) + Zmin*

                                               EXPRESSION ( ((( (red]*256) +[green] +([blue]/256)) * (1050/65536)) - 50) <= 0)

                                               STYLE

                                                               COLOR 100 195 215

                                                               OPACITY 35

                                               END

                               END      

But, [red]=[green]=[blue]= the value of the first band (red). Always.

 

In documentation I can see (http://mapserver.org/mapfile/expressions.html)

For Raster Data layers special attributes have been defined that can be used for classification, for example:

  • [PIXEL] ... will become the pixel value as number
  • [RED], [GREEN], [BLUE] ... will become the color value for the red, green and blue component in the pixel value, respectively.

And (http://mapserver.org/el/input/raster.html)

There is no need to specify a CLASSITEM. The raw pixel value itself (“[pixel]”) and, for paletted images, the red, green and blue color associated with that pixel value (“[red]”, “[green]” and “[blue]”) are available for use in classifications.

 

Hope someone can help me on that!

Thanks!

 

 

Here is my MapFile.

 

MAP

                NAME "test"

                STATUS OFF

                SIZE 256 256

                MAXSIZE 4096

                RESOLUTION 96               

                EXTENT 253999.500 6884000.500 254999.500 6885000.500

                UNITS DD           

                IMAGETYPE png

                IMAGECOLOR 255 255 255

PROJECTION

        "init=epsg:2154"

             END

                WEB

                               TEMPLATE "../etc/html_template/getcapabilities_wms_130.html"

                               METADATA

                               (…)

                               END

                END

               

                LAYER

                  NAME  "test"

                 TYPE   RASTER

                  DATA   "/mnt/nemesis_resultats/flood/v3/v4_1m/RGEALTI_FXX_0224_6753_MNT_LAMB93_IGN69_png.png"

                  #PROCESSING "BANDS=1,2,3" #this line crashes with a “drawGDAL(): Unable to access file. Attempt to classify 24bit image, this is unsupported.”

 

                  STATUS ON

                  PROJECTION

                     "init=epsg:2154"

                  END

                  METADATA

                                (…)                       

                  END

                 

                               CLASS #min=-50, max=1000 ((r * 256 + g + b / 256) *  (Zmax-Zmin)/(65536)) + Zmin*

                                               EXPRESSION ( ((( (red]*256) +[green] +([blue]/256)) * (1050/65536)) - 50) <= 0)

                                               STYLE

                                                               COLOR 100 195 215

                                                               OPACITY 35

                                               END

                               END      

                              

                              

                END #LAYER

   

END 

# End of MapFile


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users