Works with nearest neighbor interpolation