⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blended_horizontalstitch.m

📁 Please read your package and describe it at least 40 bytes. System will automatically delete the di
💻 M
字号:
function Istblend=blended_horizontalstitch(I,dx)
%produces blended mosaic from an array of Ni images  
%using the distances provided in the vector dx (length Ni-1)
%works for images with dimensions 2^N+1, color or b/w
%Homework2 - Computer Vision - Benjamin Berger - Part 1.3.a
%CISC 689 - University of Delaware - 03/16/03

[dummy Ni]=size(I);
%dx(1:2)=[132 136];
%Ni=3;

for i=1:Ni
  %I{i} = imread(['../mh',char(sym(i)),'.png']);
  [r(i) c(i) d(i)]=size(I{i});
  if rem(log2(c(i)-1),1)~=0 
    bottom(1,:,1:d(i))=I{i}(r(i),:,1:d(i));
    I{i}=[I{i}; bottom];
    [r(i) c(i) d(i)]=size(I{i});
  end
end

%calculate length of combined image:
ccomb=ceil(c(1)/2)+sum(dx)+floor(c(Ni)/2);
%fill image with zeros until nearest 2^N+1 (if width~=2^N+1)
cpad=2^ceil(log2(ccomb-1))+1;

%calculate offset of transition lines for each image:
a(1)=1;
b(Ni)=c(Ni);
for i=1:Ni-1
  a(i+1)=ceil(c(i+1)/2)-floor(dx(i)/2);
  b(i)=ceil(c(i)/2)+floor(dx(i)/2);
end;

%initialize cells and constants
N=floor(log2(r(1)-1));
G = cell(Ni,N,d(1));
L = cell(Ni,N,d(1));
LS = cell(1,N,d(1));
Ip = cell(1,Ni,d(1));
xt(1,1)=0;
rgb=1;i=1;
dx=[0,dx];

%create Gaussian and Laplacian Pyramids...
for rgb=1:d(1) %...for each color
  for i=1:Ni   %...for each part of the mosaic
    xt(1,i+1)=sum(b(1:i))-sum(a(1:i))+1; %transistion lines for blending
    Ip{i}=im2double([zeros(r(i),sum(dx(1:i)),d(i)), I{i}(:,1:c(i),:), zeros(r(i),cpad-(sum(dx(1:i))+c(i)),d(i))]);
    %pad left and right border: (avoid blurring)
    if i<Ni 
       cr=sum(dx(1:i))+c(i);
        %Ip{i}(:,cr+1:cr+2,:)=[(2*Ip{i}(:,cr,:)-Ip{i}(:,cr-1,:)), (2*Ip{i}(:,cr,:)-Ip{i}(:,cr-2,:))];
       Ip{i}(:,cr+1:cr+ceil((cpad-cr)/2),:)=repmat(Ip{i}(:,cr,:),1,ceil((cpad-cr)/2));
    end
    if i>1 
       cl=sum(dx(1:i));
       Ip{i}(:,cl-ceil(dx(i)/2):cl,:)=repmat(Ip{i}(:,cl+1,:),1,ceil(dx(i)/2)+1);
    end
    G(i,:,rgb)=gaussian_pyramid(Ip{i}(:,:,rgb));
    L(i,:,rgb)=laplacian_pyramid(G(i,:,rgb));
  end 
  xt(1,Ni+1)=cpad;

  %blend Laplacian Pyramids together:
  for j=1:N
    xt(j+1,:)=ceil(xt(j,:)/2);
    xt(j,Ni+1)=xt(j,Ni+1)+1; %adjust end of mosaic
    [rows cols]=size(G{1,j,1});
    tline{1}=zeros(rows,0);  
    LS{1,j,rgb}=zeros(rows,0);
    for i=1:Ni %append pyramids of single pictures piecewise to mosaic
      if i<Ni 
        tline{i+1}=0.5*( L{i,j,rgb}(:,xt(j,i+1))+L{i+1,j,rgb}(:,xt(j,i+1)) );
      end
      %simple version with one averaged centerline:  
      LS{1,j,rgb}=[LS{1,j,rgb}, tline{i}, L{i,j,rgb}(:,xt(j,i)+1:xt(j,i+1)-1)];
   
      %"apple&orange" version with 3 blended lines as described in paper: 
      %  leftmidline=0.75*LA{1,i,c}(:,cmid(i)-1)+0.25*LB{1,i,c}(:,cmid(i)-1);
      %  rightmidline=0.25*LA{1,i,c}(:,cmid(i)+1)+0.75*LB{1,i,c}(:,cmid(i)+1);
      %  LS{1,i,c}=[LA{1,i,c}(:,1:cmid(i)-2), leftmidline, midline, rightmidline, LB{1,i,c}(:,cmid(i)+2:2*cmid(i)-1)];
    end
  end;    
  Ispline(:,:,rgb)=synthesize_image(LS(:,:,rgb));
end %rgb

Istblend=Ispline(:,1:ccomb,:);

%imshow(Istblend)
%imwrite(Istblend, ['mh_blended_hst.png'],'png');



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -