[gdal-dev] Pixel remap using the warp api question

Martin Chapman chapmanm at pixia.com
Sat Feb 9 11:38:44 PST 2013


Even,

Thanks for the response.  In my case the target image uses zero for the 8bit 
transparency color.  When I initialize the target image I set the entire 
image to all transparent, or all zeros using INIT_DEST.  Then I warp / 
mosaic in the source imagery.  If the source imagery does NOT have 
transparency I have to remap all zeros to ones in the source image before 
the warp occurs because after the warp I have no way of distinguishing 
between black transparent values and valid black values in the target image. 
If only a small portion of the source image intersects the target image I 
want to avoid having to make a copy and remap all zeros because that slows 
down the process dramatically.  Also, if I just extract a small portion of 
the source image, then the warp from UTM to wgs84 (utm is source srs and 
wgs84 is target srs) then the warp is not as accurate.

Thus, to make the remap, warp and mosaic as efficient and accurate as 
possible I want the remap to happen in the warp kernel just after the read 
from the source image but before the warp and write to the target image.  I 
couldn't find a way to do it with the current gdal warp api parameters so I 
modified the warp kernel to do it and it works awesome.  I did it by using 
some of the existing parameters of the warp options that wouldn't affect 
other warp operations although this is still a hack.  What I would like to 
do is officially add the options to the warp api but I would need your help 
to make sure it is correct.  I can send you the code on Monday when I get 
back to the office if you are interested.  Does this sound like a feature 
you would like to add to the warp api or is it too much of a one off 
solution?

Best regards,
Martin

-----Original Message-----
From: Even Rouault [mailto:even.rouault at mines-paris.org]
Sent: Saturday, February 09, 2013 6:36 AM
To: gdal-dev at lists.osgeo.org
Cc: Martin Chapman
Subject: Re: [gdal-dev] Pixel remap using the warp api question

Le vendredi 08 février 2013 23:35:26, Martin Chapman a écrit :
> I asked the following a couple of weeks ago and never got a reply.
> Frank, can you comment on this please?
>
>
>
> .
>
>
>
> I am trying to remap all "0" value pixels in the source images to the
> value "1" in the output image using gdalwarp like so:
>
>
>
> warpOptions->padfSrcNoDataReal[bandIndex] = 0;
>
> warpOptions->padfSrcNoDataImag[bandIndex] = NULL;
>
> warpOptions->padfDstNoDataReal[bandIndex] = 1;
>
> warpOptions->padfDstNoDataImag[bandIndex] = NULL;
>
>
>
> 1. I am setting INIT_DEST=0.

That might be the issue actually. Try with INIT_DEST=1 or INIT_DEST=NO_DATA

Using the warper to do that is however a bit overkill. You could just 
RasterIO(GF_Read, ) each line/block, patch values, and then write back with 
RasterIO(GF_Write).

>
> 2. not setting UNIFIED_SRC_NODATA.
>
> 3. the source images have no defined nodata value.
>
> 4. the output image has no defined nodata value.
>
>
>
> with no luck.  My question is:  Is gdalwarp supposed to do this?  When
> I look at the pixel value of the output image the black pixels are still 
> "0"
> and not "1".
>
>
>
> My input and output are both 8-bit 3 band images.  I am using gdal 1.9.2.
>
>
>
> Best regards,
>
> Martin


More information about the gdal-dev mailing list