image - 非均匀插值

标签 image matlab image-processing interpolation

我一直在阅读关于超分辨率图像重建的主题,该领域的目的是从多个移位(亚像素)低分辨率(LR)图像创建高分辨率(HR)图像。以下代码从一个 HR 图像创建 4 个 LR 图像。然后使用非均匀插值法在高分辨率网格上对4张LR图像进行插值,得到两边比LR图像大4倍的HR图像。

ma​​in.m

im=double(imread('lena.bmp'));

figure,imshow(uint8(im)),title('original HR image');
shifts=[ 0,         0;
        4.1,    2.68;
       -3.7,    7.8;
       -1.1,  -6.5];

factor=4;

im1=create_low(im,shifts(1,1),shifts(1,2),factor);
im2=create_low(im,shifts(2,1),shifts(2,2),factor);
im3=create_low(im,shifts(3,1),shifts(3,2),factor);
im4=create_low(im,shifts(4,1),shifts(4,2),factor);

LR_images={im1,im2,im3,im4};

estimated_image =  interpolate(LR_images,shifts,factor);
figure,imshow(uint8(estimated_image)),title('reconstructed image');

create_low.m 此函数创建 4 个 LR 图像。

function [ low ] = create_low(im,x_shift,y_shift,factor)

 low = shift(im,x_shift,y_shift);

 low=downsample(low,factor);
 low=low';
 low = downsample(low,factor);
 low=low';

end

shift.m该函数通过线性插值进行亚像素偏移。

interpolate.m 将 4 张 LR 图像插值到 HR 网格上。

function rec = interpolate(s,shifts,factor)                                   

n=length(s);
ss = size(s{1});
if (length(ss)==2) ss=[ss 1]; end

% compute the coordinates of the pixels from the N images.
for k=1:ss(3) % for each color channel
  for i=1:n % for each image
    s_c{i}=s{i}(:,:,k);
    s_c{i} = s_c{i}(:);     
    r{i} = [1:factor:factor*ss(1)]'*ones(1,ss(2)); % create matrix with row indices
    c{i} = ones(ss(1),1)*[1:factor:factor*ss(2)]; % create matrix with column indices
    r{i} = r{i}+factor*shifts(i,2);     %% the problem is here.
    c{i} = c{i}+factor*shifts(i,1);     %% the problem is here.
    rn{i} = r{i}((r{i}>0)&(r{i}<=factor*ss(1))&(c{i}>0)&(c{i}<=factor*ss(2)));
    cn{i} = c{i}((r{i}>0)&(r{i}<=factor*ss(1))&(c{i}>0)&(c{i}<=factor*ss(2)));
    sn{i} = s_c{i}((r{i}>0)&(r{i}<=factor*ss(1))&(c{i}>0)&(c{i}<=factor*ss(2)));
 end

 s_ = []; r_ = []; c_ = []; sr_ = []; rr_ = []; cr_ = [];
 for i=1:n % for each image
    s_ = [s_; sn{i}];
    r_ = [r_; rn{i}];
    c_ = [c_; cn{i}];
 end
 clear s_c r c coord rn cn sn

 % interpolate the high resolution pixels using cubic interpolation
 rec_col = griddata(c_,r_,s_,[1:ss(2)*factor],[1:ss(1)*factor]','cubic'); 
 rec(:,:,k) = reshape(rec_col,ss(1)*factor,ss(2)*factor);
end
rec(isnan(rec))=0;

我使用 griddata 函数进行插值(三次),重建的图像太糟糕了,因为我认为“griddata”的参数值是错误的。如何纠正?

注意:当我更改此代码时

r{i} = r{i}+factor*shifts(i,2);     %% the problem is here.
c{i} = c{i}+factor*shifts(i,1);     %% the problem is here. 

r{i} = r{i}-shifts(i,2);     %% the problem is here.
c{i} = c{i}-shifts(i,1);     %% the problem is here.

我得到了一个很好的图像,但我不知道为什么!

编辑 lena.bmp

enter image description here

最佳答案

在 create_low 中,您应用高分辨率坐标中的位移。因此,在插值中,您还应应用高分辨率坐标中的偏移。因此,您不应该将它们乘以因数是完全有道理的——正如您已经发现的那样。

关于image - 非均匀插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19989378/

相关文章:

matlab - 乳液在滚筒之间 split

java - java中图像的视觉相似度

java - 使用 Xuggle 时在 Eclipse 中检测到 fatal error

python - 如何将数组划分为段,然后使用 python numpy 执行段的子段?

python - 频率响应:Matlab Vs Python

python - 如何在 python 中分块读取大图像?

c++ - 如何检测并在眼睛的虹膜区域周围画一个圆圈?

python - ffmpeg VS opencv有什么不同的视频分割?

Java,我怎样才能弹出一个只有图像的对话框?

matlab - 在 Matlab 中绘制球体时如何定义半径?