matlab——图像配准

来源:互联网 发布:xftp连接linux失败 编辑:程序博客网 时间:2024/06/01 10:28

只介绍两种方法:

第一种为手动选关键点:

function on2 = registerImages1(MOVING,FIXED,type)    cpselect(FIXED, MOVING)   %选择关键点    flag = input('Hit the Enter key after you finished control points selection');        mytform = cp2tform(input_points,base_points, 'projective');%求出投影变化的矩阵    registered = imtransform(MOVING, mytform, 'bicubic');%进行变化    on2=registered;%输出变换结果end

第二种为image process toolbox中的自动feature-based 函数中的SURF 函数:

function on2 = registerImages1(MOVING,FIXED,type)% This function can be used to image registration% moving is image A, fixed is image B, % type is the method used% type 'no'do not use image registration % type 'auto' use the automatic image registration.% type 'user' use the user defined control points to registration         %registerImages  Register grayscale images using auto-generated code from Registration Estimator app.        %  [MOVINGREG] = registerImages(MOVING,FIXED) Register grayscale images        %  MOVING and FIXED using auto-generated code from the Registration        %  Estimator App. The values for all registration parameters were set        %  interactively in the App and result in the registered image stored in the        %-----------------------------------------------------------        % Feature-based techniques require license to Computer Vision System Toolbox        checkLicense()        % Default spatial referencing objects        fixedRefObj = imref2d(size(FIXED));        movingRefObj = imref2d(size(MOVING));        % Detect SURF features        fixedPoints = detectSURFFeatures(FIXED,'MetricThreshold',750.000000,'NumOctaves',3,'NumScaleLevels',5);        movingPoints = detectSURFFeatures(MOVING,'MetricThreshold',750.000000,'NumOctaves',3,'NumScaleLevels',5);        % Extract features        [fixedFeatures,fixedValidPoints] = extractFeatures(FIXED,fixedPoints,'Upright',false);        [movingFeatures,movingValidPoints] = extractFeatures(MOVING,movingPoints,'Upright',false);        % Match features        indexPairs = matchFeatures(fixedFeatures,movingFeatures,'MatchThreshold',50.000000,'MaxRatio',0.500000);        fixedMatchedPoints = fixedValidPoints(indexPairs(:,1));        movingMatchedPoints = movingValidPoints(indexPairs(:,2));        MOVINGREG.FixedMatchedFeatures = fixedMatchedPoints;        MOVINGREG.MovingMatchedFeatures = movingMatchedPoints;        % Apply transformation - Results may not be identical between runs because of the randomized nature of the algorithm        tform = estimateGeometricTransform(movingMatchedPoints,fixedMatchedPoints,'projective');        MOVINGREG.Transformation = tform;        MOVINGREG.RegisteredImage = imwarp(MOVING, movingRefObj, tform, 'OutputView', fixedRefObj, 'SmoothEdges', true);        on2=MOVINGREG.RegisteredImage;endfunction checkLicense()% Check for license to Computer Vision System ToolboxCVSTStatus = license('test','video_and_image_blockset');if ~CVSTStatus    error(message('images:imageRegistration:CVSTRequired'));endend

 

第二种其实就是工具箱函数的输出,如果需要使用,直接用工具箱就好。


0 0