How to choose pixel value in case of nearest neighbor image down scaling

109 Views Asked by At

I am working on implementing a fast algorithm for image resizing (more generally 2D array of numbers resizing).

It is supposed to be fast, and should not add new values (meaning the result 2D array should not contain numbers which are not present in the original array, so exit bilinear, bicubic interpolation etc).

With these specification, Nearest Neighbor algorithm seems like the way to go but there is something that tickles me in the case of downsizing:

When down-sizing by a factor N, the value of a given pixel in the destination array has to be picked from a given NxN region in the source array. With the classical approach of Nearest Neighbor algorithm, it is always the top left value of the NxN region which is picked regarless of the values in the region. Are algorithm know for handling this with a "finer" touch WITHOUT adding new values in the results ? (pick the median value of the region for instance).

Maybe an optimized way of downscaling could be:

  1. Median filter with NxN kernel on the original image
  2. Classical Nearest Neighbor downscaling

enter image description here