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

Jorge Arevalo jorgearevalo at libregis.org
Thu Dec 13 12:49:26 PST 2012


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.rouault at 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


More information about the gdal-dev mailing list