Using OpenCvSharp wrapper, I've been using this function to resize the images (preserving the aspect ratio)
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 div = changeMaxLength ? Math.Max(w, h) : Math.Min(w, h);
double w1 = (w / div) * length;
double h1 = (h / div) * length;
Cv2.Resize(mat, dst, new Size(w1, h1), 0d, 0d, st);
}
When resizing an image having a width of 1920 pixels to a size of 200 pixels I realized that the result looks bad even if I use Cubic interpolation. I have tried this code that does not use OpenCV resize directly, but use PyrDown first:
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);
}
}
The result is:
Is this normal, or is there something wrong with the OpenCV Resize function (or the wrapper)?
Edit:
What I'm actually asking is, are these results normal?
Edit2
According to this and this my downsampling results are normal.