名稱

ST_灰階 — 從來源網格和指定的紅、綠、藍波段建立一個新的單波段 8BUI 網格

概要

(1) raster ST_灰階(raster rast, integer redband=1, integer greenband=2, integer blueband=3, text extenttype=INTERSECTION);

(2) raster ST_灰階(rastbandarg[] rastbandargset, text extenttype=INTERSECTION);

描述

使用三個輸入波段(來自一個或多個網格)建立一個單波段 8BUI 網格。任何像素類型不是 8BUI 的輸入波段都將使用 ST_Reclass 重新分類。

[Note]

此函數與帶有 grayscale 關鍵字的 ST_ColorMap 不同,因為 ST_ColorMap 只對一個波段進行操作,而此函數需要三個 RGB 波段。此函數應用以下公式將 RGB 轉換為灰階:0.2989 * 紅 + 0.5870 * 綠 + 0.1140 * 藍

可用性:2.5.0

範例:變體 1

SET postgis.gdal_enabled_drivers = 'ENABLE_ALL';
SET postgis.enable_outdb_rasters = True;

WITH apple AS (
    SELECT ST_AddBand(
        ST_MakeEmptyRaster(350, 246, 0, 0, 1, -1, 0, 0, 0),
        '/tmp/apple.png'::text,
        NULL::int[]
    ) AS rast
)
SELECT
    ST_AsPNG(rast) AS original_png,
    ST_AsPNG(ST_Grayscale(rast)) AS grayscale_png
FROM apple;
                    

原始_png

灰階_png

範例:變體 2

SET postgis.gdal_enabled_drivers = 'ENABLE_ALL';
SET postgis.enable_outdb_rasters = True;

WITH apple AS (
    SELECT ST_AddBand(
        ST_MakeEmptyRaster(350, 246, 0, 0, 1, -1, 0, 0, 0),
        '/tmp/apple.png'::text,
        NULL::int[]
    ) AS rast
)
SELECT
    ST_AsPNG(rast) AS original_png,
    ST_AsPNG(ST_Grayscale(
        ARRAY[
            ROW(rast, 1)::rastbandarg, -- red
            ROW(rast, 2)::rastbandarg, -- green
            ROW(rast, 3)::rastbandarg, -- blue
        ]::rastbandarg[]
    )) AS grayscale_png
FROM apple;
                    

另請參閱

ST_AsPNGST_ReclassST_ColorMap