Changes between Version 83 and Version 84 of WKTRaster/SpecificationWorking03


Ignore:
Timestamp:
05/24/11 11:13:43 (14 years ago)
Author:
dustymugs
Comment:

expired old notes for ST_AsJPEG

Legend:

Unmodified
Added
Removed
Modified
  • WKTRaster/SpecificationWorking03

    v83 v84  
    104104
    105105'''ST_AsJPEG(raster, quality) -> JPEG as "bytea"'''[[BR]]
    106 Return the raster as a JPEG encoded as a PostgreSQL bytea. By default quality is set to 75, but this option can be used to select other values. Values must be in the range 10-100. Low values result in higher compression ratios, but poorer image quality. Values above 95 are not meaningfully better quality but can but substantially larger. (copied from http://www.gdal.org/frmt_jpeg.html)
    107 
    108 
    109 '''Open Question:''' Is JPEG export limited to raster having 8 bit unsigned integer pixeltype (8BUI)?
    110 
    111 [http://www.gdal.org/frmt_jpeg.html See how GDAL do it]. It converts only 8 bits rasters. Should we do the same?
    112 
    113 Otherwise, how do we convert other types to 8BUI? e.g. 16BUI or 8BSI?
    114 
    115 Pierre: It might be more simple to ignore pixeltypes other than 8BUI but it would be very convenient to have a way to quickly export elevation data for example as a JPEG. It would be nice to have an elegant solution to this. Maybe something inspired from !MapServer.
    116 
    117 Proposition one (Pierre): ST_AsJPEG could simply (optionally when the pixeltype is not 8BUI) map the ST_Maximum() and ST_Minimum() value to 0-255. ST_Maximum() and ST_Minimum() are not in the spec yet but this could be on nice usage of it. They will imply caching the min and max when importing and editing. Both function should ignore the !NoDataValues. They could also be two parameters passed to ST_AsJPEG(raster, quality, min, max).
    118 
    119 Proposition two: There could also be just one parameter (string) defining a mapping method:
    120 
    121  * Method "None": No mapping. This is possible only for 8BUI.
    122 
    123  * Method "!MaxMinValue": Use the Max and the Min cached in the raster. e.g. for 16BSI (min, max) -> (-2033, 2456) -> (round((-2033 - -2033)/(2456 - -2033)*255), round((2456 - -2033)/(2456 - -2033)*255)) -> (0, 255).[[BR]]
    124 [[BR]]This is equivalent to ST_AsJPEG(raster, quality, ST_Minimum(rast), ST_Maximum(rast))
    125 
    126  * Method "!MaxMinType": Use the Max and the Min allowed by the type. e.g. for 16BSI (min, max) -> (-2033, 2456) -> (round((-2033 - -32768)/(32767 - -32768)*255), round((2456 - -32768)/(32767 - -32768)*255)) -> (120, 137)[[BR]]
    127 [[BR]]This would be equivalent to ST_AsJPEG(raster, quality, ST_BandPixelTypeMin(rast), ST_BandPixelTypeMax(rast)). Both functions (ST_BandPixelTypeMin & ST_BandPixelTypeMax) are not yet planned and I could not find an SQL query that returns the equivalent range for a type. [http://groups.google.nl/group/microsoft.public.sqlserver.programming/browse_thread/thread/46512c2691da4607/6743f4aea485c6d1 One possible solution.]
    128 
    129 
    130 mloskot: ATM, I have no thoughts on this issue.
    131 
    132 '''Open Question:''' Is JPEG export limited to raster having 1 or 3 bands?
    133 
    134 [http://www.gdal.org/frmt_jpeg.html See how GDAL do it]. It converts only 1 or 3 band rasters. Should we do the same? In this case 1 band rasters would be exported as a greyscale JPEG having R G and B identical and 3 band rasters would be interpreted as R, G and B.
    135 
    136 Pierre: I think the answer should be yes. I don't see how we could have a 2 band raster fit into RGB.
    137 
    138 mloskot: I agree, the answer should be yes.
    139 
    140 '''Here is an attempt to define the different versions of the function:'''
    141 
    142 The most minimalistic versions of the function should assume band 1, 2 and 3 as being r, g, b and the quality equal to 75:
    143 
    144  ST_AsJPEG(raster) -quality = 75
    145 
    146 A variant allow specifying the quality:
    147 
    148  ST_AsJPEG(raster, integer)
    149 
    150 Another variant should enable us to specify which band correspond to the r, the g and the b:
    151 
    152  ST_AsJPEG(raster, integer, integer, integer) - raster, rband, gband, bband, quality=75
    153 
    154  ST_AsJPEG(raster, integer, integer, integer, integer) - raster, rband, gband, bband, quality
    155 
    156 Another version should be designed to be used with a future ST_Band(raster) function. In this case there is no attempt to extract r, g or b band from any passed raster:
    157 
    158  ST_AsJPEG(raster, raster, raster)
    159 
    160  ST_AsJPEG(raster, raster, raster, integer) -with the quality param
    161 
    162 Another series should allow converting 1 band raster with pixel of type 8BUI to a grayscale JPEG (Carefull study of the GDAL behavior when converting a single band to JPEG should be done before confirming these functions):
    163 
    164  ST_AsJPEG(raster, "GRAYSCALE") - convert only band 1 with quality = 75
    165 
    166  ST_AsJPEG(raster, "GRAYSCALE", integer) - convert only band 1 with specified quality
    167 
    168  ST_AsJPEG(raster, integer, "GRAYSCALE") - allow specifying the band number to convert
    169 
    170  ST_AsJPEG(raster, integer, "GRAYSCALE", integer) - allow specifying the band number to convert and the quality
    171 
    172 Another series should allow converting 1 band raster of ANY pixel type to a grayscale JPEG. Pixel types different than 8BUI should be mapped according to specified min, max values and a mapping mode: "!MaxMinValue" (default) or "!MaxMinType".
    173 
    174  ST_AsJPEG(raster, "GRAYSCALE", min, max, text) - convert only band 1 with quality = 75
    175 
    176  ST_AsJPEG(raster, "GRAYSCALE", integer, min, max, text) - convert only band 1 with specified quality
    177 
    178  ST_AsJPEG(raster, integer, "GRAYSCALE", min, max, text) - allow specifying the band number to convert
    179 
    180  ST_AsJPEG(raster, integer, "GRAYSCALE", integer, min, max, text) - allow specifying the band number to convert and the quality
    181 
    182 Bborie: The JPEG format has several limitations:
     106
     107The JPEG format has several limitations:
    183108
    184109  1. JPEG only allows 1 (greyscale) or 3 (RGB) bands of data
     
    255180ST_AsJPEG(rast, 4)
    256181}}}
     182
     183''OLD NOTES''
     184
     185~~Return the raster as a JPEG encoded as a PostgreSQL bytea. By default quality is set to 75, but this option can be used to select other values. Values must be in the range 10-100. Low values result in higher compression ratios, but poorer image quality. Values above 95 are not meaningfully better quality but can but substantially larger. (copied from http://www.gdal.org/frmt_jpeg.html)~~
     186
     187
     188~~'''Open Question:''' Is JPEG export limited to raster having 8 bit unsigned integer pixeltype (8BUI)?~~
     189
     190~~[http://www.gdal.org/frmt_jpeg.html See how GDAL do it]. It converts only 8 bits rasters. Should we do the same?~~
     191
     192~~Otherwise, how do we convert other types to 8BUI? e.g. 16BUI or 8BSI?~~
     193
     194~~Pierre: It might be more simple to ignore pixeltypes other than 8BUI but it would be very convenient to have a way to quickly export elevation data for example as a JPEG. It would be nice to have an elegant solution to this. Maybe something inspired from !MapServer.~~
     195
     196~~Proposition one (Pierre): ST_AsJPEG could simply (optionally when the pixeltype is not 8BUI) map the ST_Maximum() and ST_Minimum() value to 0-255. ST_Maximum() and ST_Minimum() are not in the spec yet but this could be on nice usage of it. They will imply caching the min and max when importing and editing. Both function should ignore the !NoDataValues. They could also be two parameters passed to ST_AsJPEG(raster, quality, min, max).~~
     197
     198~~Proposition two: There could also be just one parameter (string) defining a mapping method:~~
     199
     200~~ * Method "None": No mapping. This is possible only for 8BUI.~~
     201
     202~~ * Method "!MaxMinValue": Use the Max and the Min cached in the raster. e.g. for 16BSI (min, max) -> (-2033, 2456) -> (round((-2033 - -2033)/(2456 - -2033)*255), round((2456 - -2033)/(2456 - -2033)*255)) -> (0, 255).[[BR]]~~
     203~~[[BR]]This is equivalent to ST_AsJPEG(raster, quality, ST_Minimum(rast), ST_Maximum(rast))~~
     204
     205~~ * Method "!MaxMinType": Use the Max and the Min allowed by the type. e.g. for 16BSI (min, max) -> (-2033, 2456) -> (round((-2033 - -32768)/(32767 - -32768)*255), round((2456 - -32768)/(32767 - -32768)*255)) -> (120, 137)[[BR]]~~
     206~~[[BR]]This would be equivalent to ST_AsJPEG(raster, quality, ST_BandPixelTypeMin(rast), ST_BandPixelTypeMax(rast)). Both functions (ST_BandPixelTypeMin & ST_BandPixelTypeMax) are not yet planned and I could not find an SQL query that returns the equivalent range for a type. [http://groups.google.nl/group/microsoft.public.sqlserver.programming/browse_thread/thread/46512c2691da4607/6743f4aea485c6d1 One possible solution.]~~
     207
     208
     209~~mloskot: ATM, I have no thoughts on this issue.~~
     210
     211~~'''Open Question:''' Is JPEG export limited to raster having 1 or 3 bands?~~
     212
     213~~[http://www.gdal.org/frmt_jpeg.html See how GDAL do it]. It converts only 1 or 3 band rasters. Should we do the same? In this case 1 band rasters would be exported as a greyscale JPEG having R G and B identical and 3 band rasters would be interpreted as R, G and B.~~
     214
     215~~Pierre: I think the answer should be yes. I don't see how we could have a 2 band raster fit into RGB.~~
     216
     217~~mloskot: I agree, the answer should be yes.~~
     218
     219~~'''Here is an attempt to define the different versions of the function:'''~~
     220
     221~~The most minimalistic versions of the function should assume band 1, 2 and 3 as being r, g, b and the quality equal to 75:~~
     222
     223~~ ST_AsJPEG(raster) -quality = 75~~
     224
     225~~A variant allow specifying the quality:~~
     226
     227~~ ST_AsJPEG(raster, integer)~~
     228
     229~~Another variant should enable us to specify which band correspond to the r, the g and the b:~~
     230
     231~~ ST_AsJPEG(raster, integer, integer, integer) - raster, rband, gband, bband, quality=75~~
     232
     233~~ ST_AsJPEG(raster, integer, integer, integer, integer) - raster, rband, gband, bband, quality~~
     234
     235~~Another version should be designed to be used with a future ST_Band(raster) function. In this case there is no attempt to extract r, g or b band from any passed raster:~~
     236
     237~~ ST_AsJPEG(raster, raster, raster)~~
     238
     239~~ ST_AsJPEG(raster, raster, raster, integer) -with the quality param~~
     240
     241~~Another series should allow converting 1 band raster with pixel of type 8BUI to a grayscale JPEG (Carefull study of the GDAL behavior when converting a single band to JPEG should be done before confirming these functions):~~
     242
     243~~ ST_AsJPEG(raster, "GRAYSCALE") - convert only band 1 with quality = 75~~
     244
     245~~ ST_AsJPEG(raster, "GRAYSCALE", integer) - convert only band 1 with specified quality~~
     246
     247~~ ST_AsJPEG(raster, integer, "GRAYSCALE") - allow specifying the band number to convert~~
     248
     249~~ ST_AsJPEG(raster, integer, "GRAYSCALE", integer) - allow specifying the band number to convert and the quality~~
     250
     251~~Another series should allow converting 1 band raster of ANY pixel type to a grayscale JPEG. Pixel types different than 8BUI should be mapped according to specified min, max values and a mapping mode: "!MaxMinValue" (default) or "!MaxMinType".~~
     252
     253~~ ST_AsJPEG(raster, "GRAYSCALE", min, max, text) - convert only band 1 with quality = 75~~
     254
     255~~ ST_AsJPEG(raster, "GRAYSCALE", integer, min, max, text) - convert only band 1 with specified quality~~
     256
     257~~ ST_AsJPEG(raster, integer, "GRAYSCALE", min, max, text) - allow specifying the band number to convert~~
     258
     259~~ ST_AsJPEG(raster, integer, "GRAYSCALE", integer, min, max, text) - allow specifying the band number to convert and the quality~~
    257260
    258261----
     
    263266compression=[JPEG/LZW/PACKBITS/DEFLATE/CCITTRLE/CCITTFAX3/CCITTFAX4/NONE]: Set the type of compression to use. None is the default. The CCITT compression should only be used with 1bit (NBITS=1) data. JPEG should only be used with Byte data. When using JPEG add a number specifying the quality. 75 is the default. e.g. ST_AsTIFF(raster, "JPEG60") (copied from http://www.gdal.org/frmt_gtiff.html)
    264267
    265 Bborie: A proposed implementation of the ST_AsTIFF functions.
     268A proposed implementation of the ST_AsTIFF functions.
    266269
    267270The TIFF format is probably the most robust available for converting rasters to GDAL rasters. Not only does it support all PostGIS Raster pixel types, it also provides plenty of creation options and possibly no issues with the number of bands. The only limitation found is that there can only be one NODATA value for all bands.