Re: [gdal-dev] Modifying a raster pixel by pixel with GDAL

2012-12-13 Thread Even Rouault
Le jeudi 13 décembre 2012 19:58:50, Jorge Arevalo a écrit :
 Hello,
 
 I want to modify every single pixel of a 1 band GeoTiff file,
 following a formula (multiply each pixel for a value and then add
 another value).
 
 output_pixel[i][j] = input_pixel[i][j] * K[i][j] + C[i][j]
 
 I can't apply a linear scale (it would be as easier as -scale option
 in gdal_translate). Sounds more like applying a mask to the band's
 data.
 
 My first approach is to get every data block of the raster (IReadBlock
 call), apply the transformation to every single pixel ( = apply a mask
 to the data block), and put the block in the output raster.
 
 Is there any other faster/smarter approach?

I would follow exactly the same approach. If you don't do in-place update, be 
carefull that the source and target rasters have exactly the same block size 
and data type if you want to use directly ReadBlock() / WriteBlock(). If not, 
you must use ReadBlock() / RasterIO(GF_Write, )
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] Modifying a raster pixel by pixel with GDAL

2012-12-13 Thread Jorge Arevalo
Thanks for the response and the wise advice, Even. I'll do it in that way.

On Thu, Dec 13, 2012 at 8:06 PM, Even Rouault
even.roua...@mines-paris.org wrote:
 Le jeudi 13 décembre 2012 19:58:50, Jorge Arevalo a écrit :
 Hello,

 I want to modify every single pixel of a 1 band GeoTiff file,
 following a formula (multiply each pixel for a value and then add
 another value).

 output_pixel[i][j] = input_pixel[i][j] * K[i][j] + C[i][j]

 I can't apply a linear scale (it would be as easier as -scale option
 in gdal_translate). Sounds more like applying a mask to the band's
 data.

 My first approach is to get every data block of the raster (IReadBlock
 call), apply the transformation to every single pixel ( = apply a mask
 to the data block), and put the block in the output raster.

 Is there any other faster/smarter approach?

 I would follow exactly the same approach. If you don't do in-place update, be
 carefull that the source and target rasters have exactly the same block size
 and data type if you want to use directly ReadBlock() / WriteBlock(). If not,
 you must use ReadBlock() / RasterIO(GF_Write, )



-- 
Jorge Arevalo
http://www.krop.com/jorgearevalo
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev