[英]How i want to enlarge the image by using biliner interpolation in matlab
[英]How can I use Lagrange interpolation to upsample an image
我有一个任务,我需要使用一些插值方法对图像进行上采样。 我必须自己编写插值方法的代码,而且我认为我不能使用任何特殊的函数来神奇地为我做这件事。 所以首先这里是我的主要内容:
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
在这里困扰我的是我不知道如何将这两个部分结合起来。 更具体地说,我不确定应该如何将 function 发送到 x0 向量。 我做这部分的尝试是这样的:
for i=1:w
for j=1:h
R_new(i,j) = lagrange(j, [1:h], R_new(i,:));
endfor
endfor
我知道这是一个非常糟糕的尝试,因为这种方法没有给我任何结果。 代码出于某种原因一直在运行。 如果您能帮助我,我将不胜感激。 我对 Octave 也有点陌生,所以可能发生了一些我不知道的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.