2016-09-15 179 views
0

有问题。我有一个tiff图像(有4层)。 我的任务是对像素的颜色进行细微更改以使图像更好。 在这种情况下,我使用GDAL库。我的来源是:GDAL获取像素颜色

GDALDataset *poDataset; 
GDALAllRegister(); 
poDataset = (GDALDataset *) GDALOpen(fileName.toStdString().c_str(), GA_ReadOnly); 
if (poDataset == NULL) { 
    QMessageBox::information(0, "error", "We have problems"); 
} else { 
    QMessageBox::information(0, "Message", "All is ok"); 
} 
int rasterCount = poDataset->GetRasterCount(); // Here is 4 raster images 
GDALRasterBand *band = poDataset->GetRasterBand(1); 
int width = band->GetXSize(); 
int height = band->GetYSize(); 


for (int i = 0; i < width; i++) { 
    for (int j = 0; j < height; j++) { 
     // cross all pixels 
     // How to get pixel color here? 
    } 
} 

所以我不知道如何获得像素颜色的循环。你能给我建议吗?

+1

这个问题可能更适合于http://gis.stackexchange.com – cartant

+0

补充说,感谢意见。 – lazexe

回答

0

我没有在GDAL API中的例子,但我已经在python库中完成了。您可以按照类似的逻辑做类似的事情,通过获取图像值数组并循环遍历它,同时对其应用一些条件更改。

import numpy as np 
from osgeo import gdal 
ds = gdal.Open("test.tif") 
myarray = np.array(ds.GetRasterBand(1).ReadAsArray()) 
...