qt c语言双三次线性插值
用chatgpt 生成的 测试了比较卡
for (int y = 0; y < enlargedHeight; y++) {
for (int x = 0; x < enlargedWidth; x++) {
// 计算原始图像中对应的浮点坐标
float originalX = (float)x / (float)enlargedWidth * (float)originalWidth;
float originalY = (float)y / (float)enlargedHeight * (float)originalHeight;
// 进行双三次线性插值计算
QRgb interpolatedPixel = bicubicInterpolation(*img1, originalX, originalY);
// 将计算得到的像素值赋给新图像
newImg->setPixel(x, y, interpolatedPixel);
}
}
// 原始图像大小
const int originalWidth = 32;
const int originalHeight = 24;
// 放大后的图像大小
const int enlargedWidth = 640;
const int enlargedHeight = 480;
// 双三次线性插值函数
QRgb bicubicInterpolation(const QImage& image, float x, float y) {
// 计算四个最近的像素点的坐标
int x1 = qFloor(x);
int y1 = qFloor(y);
int x2 = x1 + 1;
int y2 = y1 + 1;
// 计算插值权重
float dx = x - x1;
float dy = y - y1;
// 获取四个最近的像素点的颜色值
QRgb p11 = image.pixel(x1, y1);
QRgb p12 = image.pixel(x1, y2);
QRgb p21 = image.pixel(x2, y1);
QRgb p22 = image.pixel(x2, y2);
// 对四个像素点进行双三次线性插值计算
float r = qRed(p11) * (1 - dx) * (1 - dy) + qRed(p21) * dx * (1 - dy) + qRed(p12) * (1 - dx) * dy + qRed(p22) * dx * dy;
float g = qGreen(p11) * (1 - dx) * (1 - dy) + qGreen(p21) * dx * (1 - dy) + qGreen(p12) * (1 - dx) * dy + qGreen(p22) * dx * dy;
float b = qBlue(p11) * (1 - dx) * (1 - dy) + qBlue(p21) * dx * (1 - dy) + qBlue(p12) * (1 - dx) * dy + qBlue(p22) * dx * dy;
return qRgb(r, g, b);
}

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
2019-01-05 Java开发工程师面试题1
2018-01-05 压缩打包介绍/gzip压缩工具/bzip2压缩工具/xz压缩工具