http://www.mathworks.com/products/demos/shipping/images/ipexaerial.html?product=IP
Registering an Aerial Photo to an Orthophoto
Two images of the same scene can only be compared directly if they are in the same coordinate system. Image registration is the process of transforming one image into the coordinate system of another image.
=============
Step 1: Read Images
The image westconcordorthophoto.png is an orthophoto that has already been registered to the ground. The image westconcordaerial.png is unregistered as it was taken from an airplane and is distorted relative to the orthophoto.
unregistered = imread('westconcordaerial.png');
figure, imshow(unregistered)
text(size(unregistered,2),size(unregistered,1)+15, ...
'Image courtesy of mPower3/Emerge', ...
'FontSize',7,'HorizontalAlignment','right');
注意:
由于在matlab中有两套坐标系统,所以要注意不要混淆,参见Image Processing Toolbox pp2-37
简单的说,对于pixel coordinate system (r,c) r--向下为增加 c--向右为增加
对于 spatial coordinate system (x,y) x--向右为增加, y--向下为增加
|--------c 第二坐标
|
|
|
|r 第一坐标
|--------x 第一坐标
|
|
|
|y 第二坐标
text(size(unregistered,2),size(unregistered,1)+15, ...
这句话使得pixel coordinate system 转换到spatial coordinate system,即在图片右下角偏下15个坐标单位的地方写上一条注释。由于HorizontalAlignment被选择为right,所以这条注释的最后一个字出现在这个坐标的位置上。为理解它,不妨试试下面的两条命令的效果
>> text(size(unregistered,2),size(unregistered,1)+15, ...
'Image courtesy of mPower3/Emerge', ...
'FontSize',7,'HorizontalAlignment','left');
>> text(size(unregistered,2),size(unregistered,1)+15, ...
'Image courtesy of mPower3/Emerge', ...
'FontSize',7,'HorizontalAlignment','center');
这样一来,我们对这段代码就有了透辟的理解.
registeredOriginal = imread('westconcordorthophoto.png');
figure, imshow(registeredOriginal)
text(size(registeredOriginal,2),size(registeredOriginal,1)+15, ...
'Image courtesy of Massachusetts Executive Office of Environmental Affairs', ...
'FontSize',7,'HorizontalAlignment','right');
这段代码无需解释,是以完全同样的方式打开另外一幅图像.
===========
Step 2: Load and Add Control Points
Four pairs of control points have already been picked. Load these points from a MAT-file. If you want to proceed with these points, go to Step 3: Infer Geometric Transformation.
load westconcordpoints
Optionally, edit or add to the pre-picked points using the Control Point Selection Tool (cpselect). cpselect helps you pick pairs of corresponding control points. Control points are landmarks that you can find in both images, like a road intersection, or a natural feature. The unregistered image is an RGB image but cpselect only takes grayscale images, so you will pass it one plane of the RGB image.
cpselect(unregistered(:,:,1),'westconcordorthophoto.png',...
input_points,base_points)
Save control points by choosing the File menu, then the Save Points to Workspace option. Save the points, overwriting variables input_points and base_points.
利用工具,选择对应点,已经选好四对.
顺便说一句,cpselect中cp的意思是control point.
========
四个非特殊位置的点决定一个projective变换,下面就利用我们选就的四对点来求出这个变换。
Step 3: Infer Geometric Transformation
Because we know that the unregistered image was taken from an airplane, and the topography is relatively flat, it is likely that most of the distortion is projective. cp2tform will find the parameters of the projective distortion that best fits the stray input_points and base_points you picked.
t_concord = cp2tform(input_points,base_points,'projective');
顺便指出,利用
>>t_concord.tdata.T
,可以得到
ans =
0.9109 0.1412 -0.0001
-0.1323 0.8718 0.0001
65.8746 13.5141 0.9955
这就是依赖这四对点,求出的变换关系.
========
Step 4: Transform Unregistered Image
Even though the points were picked on one plane of the unregistered image, you can transform the entire RGB image. imtransform will apply the same transformation to each plane. Note that the choice of 'XData' and 'YData' values ensures the registered image will be aligned with the orthophoto.
info = imfinfo('westconcordorthophoto.png');
registered = imtransform(unregistered,t_concord,...
'XData',[1 info.Width], 'YData',[1 info.Height]);
=============
Step 5: View Registered Image
figure, imshow(registered)
Compare this visually to the orthophoto and to the unregistered image. Try going back to Step 2: Choose Control Points and using more than four pairs of points. Are the results better? What if the points are clumped together?
If you want to experiment with larger images, follow the steps above to register concordaerial.png to concordorthophoto.png.
Friday, November 23, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment