资源简介

基于sift算法的图像拼接matlab代码,经过测试,可以运行,对有重叠部分的图像进行拼接,效果不错

资源截图

代码片段和文件信息

function [Him1_inliersim2_inliers] = ComputeH(im1_matches im2_matches nb_iter epsilon)
%
% ComputeH
%   -> robust estimation of the homography using RANSAC
%
% function [Him1_inliersim2_inliers] = ComputeH(im1_matches im2_matches nb_iter epsilon)

% Input
%   - im1_matches im2_points : points matching in the two images
%       im2 = Him1
%   - nb_iter : number of iterations for the RANSAC algorithm

% Output
%   - H : computed homography

% @author: JB Fiot
% @Version: Nov08


    nb_points = size(im1_matches1);
    Best_nb_inliers = 0;

    for iter=1:nb_iter
        selected_points = [];
        im1_inliers=[]; im2_inliers=[];
        while size(unique(selected_points)1)~=4
            selected_points = random(‘discrete uniform‘ nb_points [4 1]);
        end
        
        A=[];
        
for i=1:4
x1 = im1_matches(selected_points(i)1);
y1 = im1_matches(selected_points(i)2);
x2prime = im2_matches(selected_points(i)1);
y2prime = im2_matches(selected_points(i)2);

ax = [-x1-y1-1 000 x2prime*x1x2prime*y1x2prime];
ay = [000 -x1-y1-1 y2prime*x1y2prime*y1y2prime];

            A = [A;ax;ay];
        end
            
  [USV] = svd(A);
  h = V(:end);
        
        H = reshape(h [33])‘;
        H = H/H(33);
        
        nb_inliers = 0;
        for i=1:nb_points
            Hi = H*[im1_matches(i1);im1_matches(i2);1];
         %   invHi=inv(H)*[im1_matches(i1);im1_matches(i2);1];
          %  if (Hi(3) ~= 0 && invHi(3)~=0)
           %     if ((Hi(1)/Hi(3)-im2_matches(i1))^2+(Hi(2)/Hi(3)-im2_matches(i2))^2+(invHi(1)/invHi(3)-im1_matches(i1))^2+(invHi(2)/invHi(3)-im1_matches(i2))^2)            if Hi(3) ~= 0
                if ((Hi(1)/Hi(3)-im2_matches(i1))^2+(Hi(2)/Hi(3)-im2_matches(i2))^2)                    nb_inliers = nb_inliers + 1;
                    im1_inliers = [im1_inliers;im1_matches(i:)];
                    im2_inliers = [im2_inliers;im2_matches(i:)];
                end
            end

        end
        
        if nb_inliers>Best_nb_inliers
            Best_nb_inliers = nb_inliers;
            Best_im1_inliers=im1_inliers;
            Best_im2_inliers=im2_inliers;
        end
              
    end
    im1_inliers=Best_im1_inliers;
    im2_inliers=Best_im2_inliers;
    
    %Re-estimation of the homographies with all inliers.
    A=[];
    for i=1:size(im1_inliers1)
x1 = im1_inliers(i1);
        y1 = im1_inliers(i2);
        x2prime = im2_inliers(i1);
        y2prime = im2_inliers(i2);

ax = [-x1-y1-1 000 x2prime*x1x2prime*y1x2prime];
ay = [000 -x1-y1-1 y2prime*x1y2prime*y1y2prime];
            
        A = [A;ax;ay];
    end


    [USV] = svd(A);
    h = V(:end);
    H = reshape(h [33])‘;
    t=H(1:);
    H(1:)=H(2:);
    H(2:)=t;
    t=H(:1);
    H(:1)=H(:2);
    H(:2)=t;
    
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2990  2009-06-04 23:19  492216156 Image_stitching\acomputeH.m

     文件        846  2009-06-04 23:19  492216156 Image_stitching\adist2.m

     文件       1267  2009-06-04 23:19  492216156 Image_stitching\aGetDescriptors.m

     文件       1171  2009-06-04 23:19  492216156 Image_stitching\aharris.m

     文件        642  2009-06-04 23:19  492216156 Image_stitching\aLessHarrisPoints.m

     文件       1306  2009-06-04 23:19  492216156 Image_stitching\aMatchDescriptors.m

     文件       5762  2009-06-04 23:19  492216156 Image_stitching\aStitcher.m

     文件       3001  2009-06-04 23:19  492216156 Image_stitching\avgg_warp_H.m

     文件         30  2013-04-25 11:07  492216156 Image_stitching\read.txt

     目录          0  2013-04-25 11:06  492216156 Image_stitching\data

     目录          0  2013-04-25 11:07  492216156 Image_stitching

----------- ---------  ---------- -----  ----

                17015                    11


评论

共有 条评论