とらりもんHOME  Index  Search  Changes  Login

GeoTiffのカラーテーブルを変更する/ change color table of a GeoTiff file

2017/04/26 Jin Katagi

gdaldemコマンドを使う場合 / use gdaldem command.

多分これが一番お手軽。

I think this way is the most easy.

vim color_table.txt # 4 column is alpha channel?
0. 255 255 255 0
1. 255 0 0 0
2. 180 0 0 0
gdaldem color-relief -of GTiff input.tif color_table.txt output.tif

GRASS GISのr.colorsコマンドを使い場合 / use GRASS GIS command.

一旦GRASSの環境にtiffを読み込む必用がある。GRASS 6.X系と7.X系でコマンドの使い方が若干違う。

vim color_table.txt
0  255:255:255
1  255 0 0
2  180 0 0
grass # start GRASS envirionment
r.in.gdal input=input.tif output=input # import tif to GRASS
g.region rast=input # set region to the image
cat color_table.txt | r.colors map=input rules=- # For GRASS 7.X.
# cat color_table.txt | r.colors map=input color=rules # For GRASS 6.X
r.out.gdal input=input output=input_change_color.tif # save as GeoTiff

gdalbuildvrtコマンドを使う場合 / use gdalbuildvrt command.

gdalbuildvrtでvrtを書き出し、直接vrtを変更して、tiffに戻す。

Last modified:2017/04/26 21:34:54
Keyword(s):
References:[とらりもんHOME]