[Gdal-dev] nodata in VRTKernelFilteredSource

Asger Sigurd Petersen ASP at blominfo.dk
Wed Jul 25 08:21:39 EDT 2007


Hi list,

I'm having some issues with the filter in VRTKernelFilteredSource.

Firstly I think it would be great, if it handled nodata values and
secondly I am confused about the "Normalized" attribute.
 
At the moment nodata values are not recognized and are therefore
included in the convolution like any other value. I guess there are a
lot of different ways to handle nodata when filtering, but I think the
current is the least optimal.

Regarding the "normalized" attribute I think the naming is
counterintuitive when looking at how it is actually implemented in
vrtfilters.cpp. Actually the kernel is only normalized if "Normalized"
is true.

Below I have tried to sketch up a suggestion of a possible solution to
both issues. My c++ skills leave room for improvement so please consider
it some kind of pseudo code :-)

vrtfilters.cpp from line 455:

for( iY = 0; iY < nYSize; iY++ )
{
  for( iX = 0; iX < nXSize; iX++ )
  {
    int  iYY, iKern = 0;
    double dfSum = 0.0, dfKernSum = 0.0;
    float fResult;
    bool bNormalize = !bNormalized;

    // Check if center srcpixel is NoData
    if( ((float *)pabySrcData)[(iY+nKernelSize/2 + 1) *
(nXSize+2*nExtraEdgePixels) + iX + nKernelSize/2 +1 != dfNoDataValue)
    {
     for( iYY = 0; iYY < nKernelSize; iYY++ )
     {
       int i;
       float *pafData = ((float *)pabySrcData) 
         + (iY+iYY) * (nXSize+2*nExtraEdgePixels) + iX;

       for( i = 0; i < nKernelSize; i++, pafData++, iKern++ )
       {
         if(*pafData != dfNoDataValue)
         {
          dfSum += *pafData * padfKernelCoefs[iKern];
          dfKernSum += padfKernelCoefs[iKern];
         }
         else
          bNormalize = true; // Force normalization when only using part
of the kernel
       }
     }

     if( bNormalize )
     {
       if( dfKernSum != 0.0 )
         fResult = (float) (dfSum / dfKernSum);
       else
         fResult = 0.0;
     }
     else
       fResult = (float) dfSum;

     ((float *) pabyDstData)[iX + iY * nXSize] = fResult;
    }
    else
     ((float *) pabyDstData)[iX + iY * nXSize] = dfNoDataValue;
  }
}

I hope the ideas are clear from the above.

Best regards
Asger




More information about the Gdal-dev mailing list