簡體   English   中英

Matlab通過角點修正圖像

[英]Matlab Rectify image with reference of corner points

我想糾正一個透視扭曲的圖像。 我有角點,我也有一個算法,可以執行我需要的但它執行得很慢。 它具有'imtransform'和'maketform'功能,matlab可以為這些動作提供更快的功能。 所以我試圖替換它們,但我無法做到正確。 任何幫助將不勝感激。

以下是使這個問題更清晰的圖像:

輸入已知坐標(x,y)的圖像:

輸入已知坐標的圖像

和期望的輸出:

Oupput圖像(透視矯正)

這個過程以2秒的間隔執行,我需要通過新的matlab函數替換這個過程,但我無法做到。

老algorihm是:

%X has the clockwise X coordinates %Y has the clockwise Y coordinates    
A=zeros(8,8);
A(1,:)=[X(1),Y(1),1,0,0,0,-1*X(1)*x(1),-1*Y(1)*x(1)];
A(2,:)=[0,0,0,X(1),Y(1),1,-1*X(1)*y(1),-1*Y(1)*y(1)];

A(3,:)=[X(2),Y(2),1,0,0,0,-1*X(2)*x(2),-1*Y(2)*x(2)];
A(4,:)=[0,0,0,X(2),Y(2),1,-1*X(2)*y(2),-1*Y(2)*y(2)];

A(5,:)=[X(3),Y(3),1,0,0,0,-1*X(3)*x(3),-1*Y(3)*x(3)];
A(6,:)=[0,0,0,X(3),Y(3),1,-1*X(3)*y(3),-1*Y(3)*y(3)];

A(7,:)=[X(4),Y(4),1,0,0,0,-1*X(4)*x(4),-1*Y(4)*x(4)];
A(8,:)=[0,0,0,X(4),Y(4),1,-1*X(4)*y(4),-1*Y(4)*y(4)];

v=[x(1);y(1);x(2);y(2);x(3);y(3);x(4);y(4)];

u=A\v;
%transfer fonksiyonumuz

U=reshape([u;1],3,3)';

w=U*[X';Y';ones(1,4)];
w=w./(ones(3,1)*w(3,:));

T=maketform('projective',U');

%transform uygulayıp resmi düzleştiriyoruz
P2=imtransform(I,T,'XData',[1 n],'YData',[1 m]);

如果它有幫助,這是我如何生成“A”矩陣和U矩陣:

外鏈接

使用內置MATLAB函數( fitgeotransimref2dimwarp ),以下代碼在我的筆記本電腦上運行0.06秒:

% read the image
im = imread('paper.jpg');
tic
% set the moving points := the original image control points
x = [1380;2183;1282;422];
y = [727;1166;2351;1678];
movingPoints = [x,y];
% set the fixed points := the desired image control points
xfix = [1;1000;1000;1];
yfix = [1;1;1000;1000];
fixedPoints = [xfix,yfix];
% generate geometric transform
tform = fitgeotrans(movingPoints,fixedPoints,'projective');
% generate reference object (full desired image size)
R = imref2d([1000 1000]);
% warp image
outputImage = imwarp(im,tform,'OutputView',R);
toc
% show image
imshow(outputImage);

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM