image-processing - 如何使用拉格朗日插值对图像进行上采样
问题描述
我有一个任务,我需要使用一些插值方法对图像进行上采样。我必须自己编写插值方法的代码,而且我认为我不能使用任何特殊的函数来神奇地为我做这件事。所以首先这里是我的主要内容:
I = imread('image1.png');
%figure;
%imshow(I);
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
[w, h, d] = size(I)
scalex = 2;
scaley = 2;
lagrange = @lagrange_interpol
resized_w = scalex*w
resized_h = scaley*h
R_new = zeros([size(R,1)*scalex size(R,2)*scaley]);
R_new(1:scalex:end,1:scaley:end) = R;
% Code for interpolation
G_new = zeros([size(G,1)*scalex size(G,2)*scaley]);
G_new(1:scalex:end,1:scaley:end) = G;
% Code for interpolation
B_new = zeros([size(B,1)*scalex size(B,2)*scaley]);
B_new(1:scalex:end,1:scaley:end) = B;
% Code for interpolation
I = cat(3, R_new, G_new, B_new); % Re-combine the 2D matrices to get an image
figure, imagesc(I);
这是我的拉格朗日插值法代码:
function [y] = lagrange(x, x0, y0)
% x is the value we want to interpolate
% x0 vector is in the form [x0, x1, x2,...] and contains the points
% y0 vector contains the values. In this case I send the function
% the row vectors of R, G and B matrices
n = size(x0, 2);
y = 0
for i=1:n
res = 1
for j=1:n
if i == j
continue
endif
res *= ((x-x0(j)) / (x0(i)-x0(j)));
endfor
y += res * y0(i)
endfor
在这里困扰我的是我不知道如何将这两个部分结合起来。更具体地说,我不确定应该如何将函数发送到 x0 向量。我做这部分的尝试是这样的:
for i=1:w
for j=1:h
R_new(i,j) = lagrange(j, [1:h], R_new(i,:));
endfor
endfor
我知道这是一个非常糟糕的尝试,因为这种方法没有给我任何结果。代码出于某种原因一直在运行。如果您能帮助我,我将不胜感激。我对 Octave 也有点陌生,所以可能发生了一些我不知道的事情。
解决方案
推荐阅读
- angular - 如何使用 TestBed 和 Jasmine 在 NativeScript 中实现单元测试?
- html - 为什么我的下拉菜单需要点击两次才能打开?
- javascript - 使用JS在SVG中的组内绘制元素
- swift - CGAffineTransform - 使用后像素化
- node.js - POST请求在很长一段时间后被中止
- javascript - 如何在相扑选择下拉列表中显示 ajax 响应?
- java - 如何在 JUnit 测试中将 MockWebServer 端口设置为 WebClient?
- java - 使用 while 循环验证布尔输入
- python - Groupby 序列计数和序列持续时间
- codeigniter - 如何在没有 csrf 令牌的情况下将值发布到控制器函数以进行 paytm 回调响应?