在四个角点之间显示图像Matlab [英] display image between four corner points Matlab

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

问题描述

假设我有4个角点:(x1,y1); (x2,y2);(x3,y3); (x4,y4)和矩形图像尺寸(m,n)
如何显示图像,使得显示的图像在所提到的四个点处有角。
换句话说,四个角可以控制图像旋转的角度(请记住图像边缘可能不平行)
谢谢!

Suppose I have 4 corner points : (x1, y1) ; (x2, y2) ;(x3, y3) ; (x4, y4) and a rectangular image size (m,n) How do I display the image such that the image when shown has its corners at the four mentioned points. In other words, four corners can control the angle at which the image is rotated (bear in mind the image edges might not be parallel) Thanks!

推荐答案

您需要对图像进行扭曲以获得通用解决方案。你可以这样做:

You need to warp the image for a generalized solution. You can do it as follows:

首先,阅读图片。

img=imread('cameraman.tif');
if size(img,3)==3
   img=rgb2gray(img);

指定转换点集(在您的情况下,(x1,y1) )...(x4,y4)),它们是 fixedPoints

Specify the set of transformed points (in your case, (x1,y1) ... (x4,y4)), they are fixedPoints.

movingPoints=[1 1;256 1; 256 256; 1 256] %(x,y) coordinate
fixedPoints=[25 25;250 12;255 200;30 180];

然后,估算转换。我选择投射变换。你也可以选择仿射。

Then, estimate the transformation. I choose projective transformation. You can choose affine as well.

TFORM = fitgeotrans(movingPoints,fixedPoints,'projective');

由于您希望图像转到指定的角落,您必须指定输出视图。可以通过如下构建参考二维图像来完成。

Since, you want the image to go to the specified corners, you have to specify the output view. It can be done by constructing a reference 2-D image as follows.

R=imref2d(size(img),[1 size(img,2)],[1 size(img,1)]);

最后,扭曲图像。

imgTransformed=imwarp(imread('cameraman.tif'),R,TFORM,'OutputView',R);

显示图片。

imshow(imgTransformed,[]);

您应该在指定点处拥有图像的角,并且包含图像的框将是原始图像的大小。

You should have the corners of your image at the specified points and the box which contains the image will be of the size of the original image.

这篇关于在四个角点之间显示图像Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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