[gdal-dev] Change color to TIF file with GDAL

Joaquim Manuel Freire Luís jluis at ualg.pt
Fri Mar 8 08:01:11 PST 2019



|>Hello everyone
|>I have a tif file named ndvi.tif that contains values between 1 and 1. The file is
|>with one band.
|>In addition, I have a ndvi.vrt file which I am trying to edit.
|>My goal is to change the color of the image according to green-orange color
|>values. Currently the picture is black and white
 
Hi,

Some concept first. What you have is a grid not an image. You don't have any colors (nor black, nor orange or other). What you have is a matrix of float numbers ranging between -1 and 1.

Now, to visualize the contents of that grid, we assign colors to those numbers and we can assign any color we want, but that is during the visualization process. And you can off course save an image representation of that grid. Since I don't do these types of things with GDAL I don't know if it has one tool to do it, but the software you are using to visualize knows how to do that. Basically, you will be doing what is called an indexed image where a correspondence is made between the float value and a color scale. Changing the color scales, changes from grayscale to color images. But the trick is entirely on the color scale being used.

Joaquim

|>
|>I run the command:
|>gdal_translate -of GTiff -ot Float32 C:\Users\oze\test.vrt
|>C:\Users\oze\modified_palette.tif -scale -1 1
|>
|>The resulting output is between 69 and 241 and the colors are still in black and
|>white rather than green-orange as I requested.
|>
|>This is test.vrt file:
|>
|><VRTDataset rasterXSize="1271" rasterYSize="3179">
|>  <SRS>PROJCS["WGS 84 / UTM zone 36N",GEOGCS["WGS
|>84",DATUM["WGS_1984",SPHEROID["WGS
|>84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG",
|>"6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",
|>0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"
|>]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PA
|>RAMETER["central_meridian",33],PARAMETER["scale_factor",0.9996],PARAME
|>TER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,
|>AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AU
|>THORITY["EPSG","32636"]]</SRS>
|>  <GeoTransform>  7.3790000000000000e+05,  1.0000000000000000e+01,
|>0.0000000000000000e+00,  3.6828200000000000e+06,
|>0.0000000000000000e+00, -1.0000000000000000e+01</GeoTransform>
|>  <Metadata>
|>    <MDI key="AREA_OR_POINT">Area</MDI>
|>  </Metadata>
|>  <VRTRasterBand dataType="Float32" band="1">
|><ColorInterp>Green</ColorInterp>
|>
|>    <SimpleSource>
|>      <SourceFilename
|>relativeToVRT="0">C:\Users\oze\test.tif</SourceFilename>
|>      <SourceBand>1</SourceBand>
|>      <SourceProperties RasterXSize="1271" RasterYSize="3179"
|>DataType="Float32" BlockXSize="1271" BlockYSize="1" />
|>      <SrcRect xOff="0" yOff="0" xSize="1271" ySize="3179" />
|>      <DstRect xOff="0" yOff="0" xSize="1271" ySize="3179" />
|>    </SimpleSource>
|>  </VRTRasterBand>
|></VRTDataset>
|>
|>
|>That's how it looks before everything:
|><http://osgeo-org.1560.x6.nabble.com/file/t384615/aaaa.jpg>
|>
|>
|>This is how it looks after the command is run:
|><http://osgeo-org.1560.x6.nabble.com/file/t384615/bbbbbbbbb.jpg>
|>
|>It's important to me that the colors look like this:
|><http://osgeo-org.1560.x6.nabble.com/file/t384615/ccccccccc.jpg>
|>
|>
|>These are the values before:
|><http://osgeo-org.1560.x6.nabble.com/file/t384615/ddddddddd.jpg>
|>
|>
|>These are the values after:
|><http://osgeo-org.1560.x6.nabble.com/file/t384615/zzzzzzzzzzz.jpg>
|>
|>
|>That's what it's important for me to see:
|><http://osgeo-org.1560.x6.nabble.com/file/t384615/asasasasa.jpg>
|>
|>Thanks to everyone who has read and wants to help
|>
|>
|>
|>--
|>Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
|>_______________________________________________
|>gdal-dev mailing list
|>gdal-dev at lists.osgeo.org
|>https://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list