RGB图像的缩放
源码仓库:https://github.com/LampsAsarum/RGBScale
最近邻插值法
目标像素的色值 等于 等比原图距离最近像素点的色值。
for (int dst_y = 0; dst_y < dst_height; dst_y++)
{
for (int dst_x = 0; dst_x < dst_width; dst_x++)
{
int src_x = (int)(dst_x / scale);
int src_y = (int)(dst_y / scale);
for (int k = 0; k < channel; k++) {
*(dst_rgb + dst_y * dst_line_byte_num + dst_x * channel + k) =
*(src_rgb + src_y * src_width * channel + src_x * channel + k);
}
}
}
双线性插值
目标像素的色值 等于 等比原图像素点周围的四个像素点色值的双线性插值。
线性插值:
像素转换:
双线性插值应用公式推导:
for (int k = 0; k < channel; k++)
{
dst_rgb[pixel_point + k] =
src_rgb[point_a + k] * (1 - distance_x) * (1 - distance_y) +
src_rgb[point_b + k] * distance_x * (1 - distance_y) +
src_rgb[point_c + k] * distance_y * (1 - distance_x) +
src_rgb[point_d + k] * distance_y * distance_x;
}