问题描述
我有一项作业,需要使用一些插值方法对图像进行上采样。我必须自己编写插值方法的代码,我认为我不能使用任何特殊的函数来为我神奇地做到这一点。所以首先这里是我的主要内容:
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 也有点陌生,所以可能有些事情我不知道。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)