2012-04-21 120 views
4

我必须从低分辨率图像获取高分辨率图像。这可以使用插值方法来实现。我知道在matlab imresizeinterp2函数将执行任务,但我必须编写代码,而不使用任何内置函数。我理解双线性插值如何工作,但我似乎无法将它拼凑在我的代码中。我会很感激任何帮助和建议。如何使用Matlab执行双线性插值

这是到目前为止我的代码:

clear all; close all; clc; 

input_im=imread('superman.png'); 
im=rgb2gray(input_im); 
%subplot(1,2,1), imshow(input_im), title('Original Image'); 
%subplot(1,2,2), imshow(im), title('Gray Scale Input Image'); 

[m,n]=size(im); %obtain the size of gray scale image 
S = input(' Now Enter Value : '); 
Scale1 = floor(S); 
Scale2 = floor(S); 
scale = [Scale1, Scale2]; 

Oim=size(im); 
Nim=max(floor(scale.*Oim(1:1)),1); 

for i=1:Nim-1 
    for j=1:Nim-1 

     Q11= 
     Q21= 
     Q12= 
     Q22= 
     R1=((x2-x)/(x2-x1))*Q11+((x-x1)/(x2-x1))*Q21; 
     R2=((x2-x)/(x2-x1))*Q12+((x-x1)/(x2-x1))*Q22; 
     P=((y2-y)/(y2-y1))*R1+((y-y1)/(y2-y1))*R2; 
    end 
end 
+1

最好不要在matlab中使用'i'和'j'作为变量名称(http://stackoverflow.com/questions/14790740/using-i-and-j-as-variables-in- MATLAB) – Shai 2013-05-16 07:31:12

回答

-1

背后interp2的代码是可用的。只需在命令窗口中输入>> edit interp2,就可以查看它们是如何实现的。