1

Has a problem. I have an tiff image (that have 4 layers). My tasks is to make small changes in pixel's color to make image better. In this case I use GDAL library. My source is:

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? } } 

So I dont know how to get pixel color in cycle. Can you give me advice pleasae?

1 Answer 1

2

You need to request needed bands and extent into the buffer using GDALRasterIO method (see http://www.gdal.org/classGDALRasterBand.html#a30786c81246455321e96d73047b8edf1). The usage example here: http://www.gdal.org/gdal_tutorial.html

char* pabBuff = (char *) CPLMalloc(nBufXSize * nBufYSize); band->RasterIO(GF_Read, nXOff, nYOff, nXSize, nYSize, pabBuff, nBufXSize, nBufYSize, GDT_Byte, 0, 0, NULL); for(int i = 0; i < nBufXSize; ++i) { for (j = 0; j < nBufYSize; ++j) { char pixel = pabBuff[i * nBufXSize + j]; } } 
2
  • Thanks for help, Dmitry, but I'm still not fully understand how to retrieve information that I need. Don't think that I lazy, I tried this incide cycle: band->RasterIO(GF_Read, i, j, 1, 1, buff, 1, 1, GDT_UInt16, 0, 0); Please contact with me, because I have a deadline and this problem is very important to me. Thanks for your help once more. Commented Sep 15, 2016 at 18:40
  • Add code example to the post Commented Sep 15, 2016 at 19:03

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.