使用GDAL

时间:2019-03-08 11:47:13

标签: python tiff gdal

我有一个名为ndvi.tif的tif文件,其中包含介于-1和1之间的值。该文件具有一个波段。 另外,我有一个要编辑的ndvi.vrt文件。

我的目标是根据橙绿色颜色值更改图像的颜色。当前图片为黑白。

我运行命令:

gdal_translate -of GTiff -ot Float32 C:\Users\oze\test.vrt C:\Users\oze\modified_palette.tif -scale -1 1

结果输出在69-241之间,颜色仍然是黑白,而不是我所期望的橙橙色。

这是ndvi.vrt文件:

<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],PARAMETER["central_meridian",33],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["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>

这就是一切之前的样子:

Image 1

这是命令运行后的外观:

Image 2

颜色对我来说很重要:

Image 3

这些是之前的值:

Image 4

以下是这些值:

Image 5

那对我来说很重要:

Image 6

1 个答案:

答案 0 :(得分:0)

谢谢你,有些事情对我来说没用。

我使用以下命令创建了VRT文件:

gdal_translate -of VRT orig.tif orig.vrt

我将文件更改为以下内容-刚刚添加了<ColorTable>并更改为<ColorInterp> Palette </ ColorInterp>

我运行了以下命令:

gdal_translate orig.tif orig_new.tif

什么也没发生。输出文件与输入文件完全相同。

这是更新的VRT文件:

<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],PARAMETER["central_meridian",33],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["Easting",EAST],AXIS["Northing",NORTH],AUTHORITY["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>Palette</ColorInterp>
  <ColorTable>
    <Entry c1="203" c2="0" c3="23" c4="255"/>
    <Entry c1="131" c2="66" c3="37" c4="255"/>
    <Entry c1="201" c2="234" c3="157" c4="255"/>
    <Entry c1="137" c2="51" c3="128" c4="255"/>
    <Entry c1="255" c2="234" c3="0" c4="255"/>
    <Entry c1="167" c2="226" c3="226" c4="255"/>
    <Entry c1="255" c2="184" c3="184" c4="255"/>
    <Entry c1="218" c2="179" c3="214" c4="255"/>
    <Entry c1="209" c2="209" c3="209" c4="255"/>
    <Entry c1="207" c2="164" c3="142" c4="255"/>
</ColorTable>  <SimpleSource>
      <SourceFilename relativeToVRT="1">orig.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>