3
我一直在閱讀一個關於超分辨率圖像重建的話題,該領域的目標是從多個移位(亞像素)低分辨率(LR)圖像創建高分辨率(HR)圖像。以下代碼從一幅HR圖像創建4個LR圖像。然後使用非單向插值對高分辨率網格上的4個LR圖像進行插值,以獲得兩側大於LR的4個LR圖像的HR圖像。非均勻插值
的main.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
你可以發佈你正在使用的'lena.bmp'嗎? – chappjc