I have a tiff raster with values from 0 to 255 (one band) and 7 colors. I would like to change colors of my tiff.
I tried with QGIS but I can't save it with new colors.
Somebody have an idea ?
Convert your image into GDAL virtual raster http://www.gdal.org/gdal_vrttut.html with gdal_translate.
gdal_translate -of vrt test.tif test.vrt
GDAL VRT raster is a small XML file than contains instructions about how to handle the source data and it contains also the palette as plain text.
<VRTRasterBand dataType="Byte" band="1">
<ColorInterp>Palette</ColorInterp>
<ColorTable>
<Entry c1="120" c2="120" c3="120" c4="255" />
<Entry c1="72" c2="72" c3="72" c4="255" />
<Entry c1="176" c2="176" c3="184" c4="255" />
<Entry c1="160" c2="136" c3="200" c4="255" />
<Entry c1="120" c2="184" c3="224" c4="255" />
<Entry c1="152" c2="152" c3="152" c4="255" />
<Entry c1="152" c2="200" c3="248" c4="255" />
<Entry c1="208" c2="240" c3="224" c4="255" />
<Entry c1="176" c2="224" c3="248" c4="255" />
<Entry c1="240" c2="200" c3="216" c4="255" />
<Entry c1="224" c2="224" c3="224" c4="255" />
<Entry c1="0" c2="0" c3="0" c4="255" />
Edit the RGBA values in the palette entries as you wish, save the VRT file and open that with QGIS. You should see your edited colors. What't the best is that you have still the original image left because you have not touched it at all so you even have the same physical image opened as several differently colored versions. But if you want to materialize the new version use gdal_translate once again:
gdal_translate -of GTiff test.vrt modified_palette.tif