高80宽64的灰度图像reseize到高70宽56的双线性插值函数c语言实现
时间: 2023-03-16 21:44:30 浏览: 49
我可以提供一个简单的C语言实现:#include <stdio.h>
#include <stdlib.h> // 计算双线性插值
int bilinearInterpolation(int x, int y, int width, int height, int* image)
{
int x1 = x;
int x2 = x1 + 1;
int y1 = y;
int y2 = y1 + 1;
int f11 = image[y1 * width + x1];
int f12 = image[y2 * width + x1];
int f21 = image[y1 * width + x2];
int f22 = image[y2 * width + x2];
int t = x2 - x;
int u = y2 - y;
int result = (1 - t) * (1 - u) * f11 + t * (1 - u) * f21 + t * u * f22 + (1 - t) * u * f12;
return result;
} // 重新调整大小
int* resize(int width, int height, int newWidth, int newHeight, int* image)
{
int* result = (int*)malloc(sizeof(int) * newWidth * newHeight);
for (int j = 0; j < newHeight; j++) {
for (int i = 0; i < newWidth; i++) {
int x = (i * width) / newWidth;
int y = (j * height) / newHeight;
result[j * newWidth + i] = bilinearInterpolation(x, y, width, height, image);
}
}
return result;
}