2

gdal_translate has a parameter to resample the values based on the most frequent class in the output pixel (-r mode). However, this most frequent class does not necessary exist (when two or more of the most frequent classes have exactly the same number of pixels.

Does anyone know what happens to the output pixel value when two classes with the most pixels are exactly the same ? Does it take the first discovered value, the last one, the smallest one, the larger one, a random one or any other rule? At least it seems to select a value.

1

The source code is at https://github.com/OSGeo/gdal/blob/master/gdal/alg/gdalwarpkernel.cpp, rows 5989-6109. Unfortunately I can't read C++ well but on row 6091 I see

if( ++panVals[nVal+nBinsOffset] > nMaxVal )

The "greater than" makes me believe that the first of the equal frequencies gets selected and thus the lowest pixel value because the index in the pixel value loop is using ascending values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.