Downsampling and Lanczos
If I'm not understanding it wrong, according to this Lanczos should generate good results for downscaling. However my tries and this shows that it does not. Why?
Can you recommend me a good way to downscale an image which would produces nice looking thumbnails. Should I use Area Interpolation? I there any other alternative in OpenCV?
cv2 resize with Lanczos4
cv2 resize with Area
And using PryDown first I've got a smoother result:
Code:
public static void Resize_PreserveAspectRatio(this Mat mat, Mat dst, int length, InterpolationFlags st = InterpolationFlags.Cubic, bool changeMaxLength = true)
{
double w = mat.Width;
double h = mat.Height;
double len2x = length * 2d;
double div = changeMaxLength ? Math.Max(w, h) : Math.Min(w, h);
if (div > len2x)
{
using (Mat mat1 = mat.Clone())
{
while (div > len2x)
{
Cv2.PyrDown(mat1, mat1);
w = mat1.Width;
h = mat1.Height;
div = changeMaxLength ? Math.Max(w, h) : Math.Min(w, h);
}
double w1 = (w / div) * length;
double h1 = (h / div) * length;
Cv2.Resize(mat1, dst, new Size(w1, h1), 0d, 0d, st);
}
}
else
{
double w1 = (w / div) * length;
double h1 = (h / div) * length;
Cv2.Resize(mat, dst, new Size(w1, h1), 0d, 0d, st);
}
}
and the message is: don't believe arbitrary blogposts ?