Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#340 closed task (fixed)

[raster] ST_AsJPEG

Reported by: mloskot Owned by: Bborie Park
Priority: medium Milestone: PostGIS 2.0.0
Component: raster Version: master
Keywords: history Cc:

Description (last modified by pracine)

This tasks belongs to the Objective 0.1.6f specified in the WKT Raster roadmap

As stated at the end of the comment 5 of the "Specification Comments following the Code Sprint" section of the working specifications, this function should be a PL/pgSQL wrapper around a more general ST_AsImage(format, params) function using GDAL to convert any raster to an image.

The function should return a bytea.

This function is particularly sensible to the number of band present in the raster as it normally needs 3 band (r,g,b).

It is also very sensible to the pixel type of the raster since JPEG supports only values in the 0-255 range.

See the working specifications for more details/questions.

Priority should be given to these variants:

ST_AsJPEG(raster, integer)
ST_AsJPEG(raster, integer, integer, integer, integer)
ST_AsJPEG(raster, integer, "GRAYSCALE", integer, min, max, text)

Attachments (3)

st_asjpeg.patch (6.4 KB) - added by Bborie Park 10 years ago.
Adds ST_AsJPEG capability
st_asjpeg.2.patch (6.4 KB) - added by Bborie Park 10 years ago.
No changes made. Update diff due to incremental changes in ST_MinMax.
st_asjpeg.3.patch (6.4 KB) - added by Bborie Park 10 years ago.
Updated to follow error messaging guidelines

Download all attachments as: .zip

Change History (19)

comment:1 Changed 11 years ago by mloskot

Owner: changed from pracine to mloskot
Status: newassigned

comment:2 Changed 11 years ago by pracine

Version: trunk

comment:3 Changed 11 years ago by pracine

Description: modified (diff)

comment:4 Changed 11 years ago by pracine

Description: modified (diff)

comment:5 Changed 10 years ago by pracine

Milestone: WKTRaster 0.1.6WKTRaster Future

A more general ST_AsImage invoking GDAL should be implemented first. ST_AsJPEG should be a wrapper around this more generic function.

comment:6 Changed 10 years ago by pracine

Summary: [wktraster] Implement ST_AsJPEG function for raster[raster] Implement ST_AsJPEG function for raster

comment:7 Changed 10 years ago by pracine

Status: assignednew

comment:8 Changed 10 years ago by Bborie Park

The JPEG format has several limitations:

  1. JPEG only allows 1 (greyscale) or 3 (RGB) bands of data
  1. JPEG only supports 8BUI pixeltype
  1. JPEG cannot embed spatial reference information within the file

To address the limitations:

  1. Use ST_Band to specify which band(s) should be passed to the ST_AsJPEG function. Variations of ST_AsJPEG are made available that allows specifying a band index. If a raster whose number of specified bands does not equal 1 or 3 is provided, a warning is raised and the first or the first three bands are used.
  1. Throw an exception if any of the specified bands is not 8BUI. The user should use ST_Reclass to convert any non-8BUI bands to 8BUI.
  1. Nothing can be done.

A proposed set of variations of the ST_AsJPEG function:

  1. ST_AsJPEG(rast raster, options text[])

rast: the raster with one or three bands in 8BUI pixel type to generate a JPEG image from

options: array of creation options to pass to the GDAL JPEG driver

ST_AsJPEG(rast, ARRAY['QUALITY=90', 'PROGRESSIVE=ON'])
  1. ST_AsJPEG(rast raster)

Like #1 above but use the driver's default creation options

  1. ST_AsJPEG(rast raster, nbands int[], options text[])

nbands: an integer array specifying the band indices of the raster to include in the JPEG file

ST_AsJPEG(rast, ARRAY[1,3,6], ARRAY['QUALITY=50'])
  1. ST_AsJPEG(rast raster, nbands int[])

Like #3, but use the default creation options

ST_AsJPEG(rast, ARRAY[1,3,6])
  1. ST_AsJPEG(rast raster, compression int)

compression: number between 10 and 100 indicating image quality

ST_AsJPEG(rast, 90)
  1. ST_AsJPEG(rast raster, nbands int[] compression int)
ST_AsJPEG(rast, ARRAY[1,2,3], 90)
  1. ST_AsJPEG(rast raster, nband int, options text[])

nband: index of the band to include

ST_AsJPEG(rast, 2, ARRAY['QUALITY=25'])
  1. ST_AsJPEG(rast raster, nband int, compression int)
ST_AsJPEG(rast, 5, 75)
  1. ST_AsJPEG(rast raster, nband int)
ST_AsJPEG(rast, 4)

In looking over the working spec's ST_AsJPEG, I don't believe the GREYSCALE variations are usable as the JPEG driver automatically creates a greyscale image if the raster passed to it has one band.

comment:9 Changed 10 years ago by pracine

I would just rename the "compression" parameter to "quality".

comment:10 Changed 10 years ago by pracine

Just for the record, JPEG cannot embed spatial reference information within the file but an application can get a sister wordfile with this query: SELECT ST_Georeference(rast) FROM mytable.

comment:11 Changed 10 years ago by Bborie Park

Owner: changed from mloskot to Bborie Park
Status: newassigned

Changed 10 years ago by Bborie Park

Attachment: st_asjpeg.patch added

Adds ST_AsJPEG capability

comment:12 Changed 10 years ago by Bborie Park

Attached incremental patch for adding ST_AsJPEG. Patch can be applied with the following in the base postgis source directory.

patch -p1 < st_asjpeg.patch

Patches for ST_Band, ST_MinMax, ST_Reclass and ST_AsGDALRaster must be applied first in the order listed.

comment:13 Changed 10 years ago by Bborie Park

Summary: [raster] Implement ST_AsJPEG function for raster[raster] ST_AsJPEG

Changed 10 years ago by Bborie Park

Attachment: st_asjpeg.2.patch added

No changes made. Update diff due to incremental changes in ST_MinMax.

Changed 10 years ago by Bborie Park

Attachment: st_asjpeg.3.patch added

Updated to follow error messaging guidelines

comment:14 Changed 10 years ago by Bborie Park

Add ST_AsJPEG. Merges cleanly against r7145.

The following patches must be merged first for this patch to merge cleanly:

  1. ST_Band
  1. ST_SummaryStats
  1. ST_Mean
  1. ST_StdDev
  1. ST_MinMax
  1. ST_Histogram
  1. ST_Quantile
  1. ST_Reclass
  1. ST_AsGDALRaster
  1. ST_AsTIFF

comment:15 Changed 10 years ago by Bborie Park

Keywords: history added
Resolution: fixed
Status: assignedclosed

Added in r7157

comment:16 Changed 10 years ago by robe

Milestone: PostGIS Raster FuturePostGIS 2.0.0
Note: See TracTickets for help on using tickets.