Matlab参照角点校正图像 [英] Matlab Rectify image with reference of corner points

查看:270
本文介绍了Matlab参照角点校正图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想校正具有透视畸变的图像.我遇到了麻烦,也有一种算法可以执行我需要的操作,但是执行速度非常慢.它具有"imtransform"和"maketform"功能,而matlab在执行这些操作时具有更快的功能.所以我试图更换它们,但我做错了.任何帮助将不胜感激.

I want to rectify an image with perspectival distorsion. I have points of the corners and I have also have an algorithm that perfoms what I need but it executes really slow. It has 'imtransform' and 'maketform' functions which matlab has faster functions for these actions. So I tried to replace them but I couldn't make it right. Any helps will be appreciated.

以下是使问题更清晰的图片:

Here is the Images to make this question clearer:

具有已知坐标(x,y)的输入图像:

Input Image with known Coordinates(x,y):

和所需的输出:

此过程以2秒的间隔执行,我需要通过新的Matlab函数替换此过程,但我做不到.

This process executed with the interval of 2 seconds, I need to replace this process via new matlab functions but I couldn't make it.

旧的算法是:

%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矩阵的方法:

if it helps, here is how I generated "A" matrix and U matrix:

链接

推荐答案

使用内置的MATLAB函数(fitgeotransimref2dimwarp),以下代码在笔记本电脑上的运行时间为0.06秒:

using the builtin MATLAB functions (fitgeotrans, imref2d, and imwarp) the following code runs in 0.06 seconds on my laptop:

% 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);

这篇关于Matlab参照角点校正图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆