vsl*_*lzl 4 matlab image-processing
我想矫正视前畸形的图像。我有很多问题,也有一种算法可以执行我需要的操作,但是执行速度很慢。它具有“ imtransform”和“ maketform”功能,而matlab对于这些操作具有更快的功能。所以我试图更换它们,但我做错了。任何帮助将不胜感激。
这是使这个问题更清晰的图像:
具有已知坐标(x,y)的输入图像:
和所需的输出:
该过程以2秒的间隔执行,我需要通过新的matlab函数替换该过程,但我做不到。
旧的算法是:
%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]);
Run Code Online (Sandbox Code Playgroud)
如果有帮助,这是我生成“ A”矩阵和U矩阵的方式:
使用内置的MATLAB函数(fitgeotrans
,imref2d
和imwarp
),以下代码在笔记本电脑上的运行时间为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);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
211 次 |
最近记录: |