matlab变换图片四个角黑色,如何根据角点做两幅图像之间的仿射变换

%% Read Frames from a Movie File

filename1 = '..\image\test3.bmp';

filename2 = '..\image\test4.bmp';

hVideoSrcA = vision.VideoFileReader(filename1, 'ImageColorSpace', 'Intensity');

hVideoSrcB = vision.VideoFileReader(filename2, 'ImageColorSpace', 'Intensity');

imgA = step(hVideoSrcA);

imgB = step(hVideoSrcB);

figure; imshowpair(imgA, imgB, 'montage');

title(['Frame A',repmat(' ',[1 70]), 'Frame B']);

figure; imshowpair(imgA, imgB, 'ColorChannels', 'red-cyan');

title('Color composite (frame A = red, frame B = cyan)')

%% Collect Salient Points from Each Frame

ptThresh = 0.1;

pointsA = detectFASTFeatures(imgA, 'MinContrast',ptThresh);

pointsB = detectFASTFeatures(imgB, 'MinContrast',ptThresh);

% Display corners found in images A and B

figure; imshow(imgA); hold on

plot(pointsA);

title('Corners in A');

figure; imshow(imgB); hold on

plot(pointsB);

title('Corners in B');

%% Select Correspondences Between Points

% Extract FREAK descriptors for the corners

[featuresA, pointsA] = extractFeatures(imgA, pointsA);

[featuresB, pointsB] = extractFeatures(imgB, pointsB);

indexPairs = matchFeatures(featuresA, featuresB);

pointsA = pointsA(indexPairs(:,1), :);

pointsB = pointsB(indexPairs(:,2), :);

figure; showMatchedFeatures(imgA, imgB, pointsA, pointsB);

legend('A','B');

%% Estimating Transform from Noisy Correspondences

[tform, pointsBm, pointsAm] = estimateGeometricTransform(pointsB, pointsA, 'affine');

imgBp = imwarp(imgB, tform, 'OutputView', imref2d(size(imgB)));

pointsBmp = transformPointsForward(tform, pointsBm.Location);

figure;

showMatchedFeatures(imgA, imgBp, pointsAm, pointsBmp);

legend('A', 'B');

%% Transform approximation and Smoothing

% Extract scale and rotation part sub-matrix

H = tform.T;

R = H(1:2, 1:2);

% Compute theta from mean of two possible arctangents

theta = mean([atan2(R(2),R(1)) atan2(-R(3),R(4))]);

% compute scale from mean of two stable mean calculations

scale = mean(R([1 4])/cos(theta));

% Translation remains the same:

translation = H(3, 1:2);

% Reconstitute new s-R-t transform:

HsRt = [[scale*[cos(theta) -sin(theta);sin(theta) cos(theta)];translation],[0 0 1]'];

tformsRT = affine2d(HsRt);

imgBold = imwarp(imgB, tform, 'OutputView', imref2d(size(imgB)));

imgBsRt = imwarp(imgB, tformsRT, 'OutputView', imref2d(size(imgB)));

figure

imshowpair(imgBold,imgBsRt,'ColorChannels','red-cyan');

axis image;

title('Color composite of affine and s-R-t transform outputs');

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值