实验三 MATLAB图像处理基本操作及摄像机标定(DLT) 实验三 Matlab图像处理基本操作及摄像机标定(DLT) (DLT)1、实验目的通过应用Matlab的图像处理基本函数,学习图像处理中的一些基础操作和处理。
理解摄像机标定(DLT)方法的原理,并利用程序实现摄像机内参数和外参数的估计。
2、实验内容:1) 读取一幅图像并显示。
2) 检查内存(数组)中的图像。
3) 实现图像直方图均衡化。
4) 读取图像中像素点的坐标值。
5) 保存图像。
6) 检查新生成文件的信息。
7) 使用阈值操作将图像转换为二值图像。
8) 根据RGB图像创建一幅灰度图像。
9) 调节图像的对比度。
10) 在同一个窗口内显示两幅图像。
11) 掌握matlab命令及函数,获取标定块图像的特征点坐标。
12) 根据摄像机标定(DLT)方法原理,编写Matlab程序,估计摄像机内参数和12) 外参数。
3、实验要求:1) 选取一幅图像,根据实验内容1)—10)给出结果。
2) 根据给定的标定块图像及实验内容11),12)进行编程实验。
3) 书写实验报告4、实验设备1) 微机。
2) Matlab软件。
5、实验原理DLT变换:Abdal-Aziz和Karara于70年代初提出了直接线性变换像机定标的方法,他们从摄影测量学的角度深入的研究了像机图像和环境物体之间的关系,建立了像机成像几何的线性模型,这种线性模型参数的估计完全可以由线性方程的求解来实现。
直接线性变换是将像点和物点的成像几何关系在齐次坐标下写成透视投影矩阵的形式:X,,wu,,,, Y,,w,,,svP 3,4,,,,Zw ,,1,,,,1,,为图像坐标系下的点的齐次坐标,为世界坐标系下的空其中,,,,u,v,1X,Y,Zwww间点的欧氏坐标, P为3*4的透视投影矩阵,为未知尺度因子。
消去S,可以得到方程组:pX,pY,pZ,p,puX,puY,puZ,pu,011w12w13w1431w32w33w34pX,pY,pZ,p,puX,puY,puZ,pu,021w22w23w1431w32w33w34当已知N个空间点和对应的图像上的点时,可以得到一个含有2*N个方程的方程组: AL,0其中A为(2N*12)的矩阵, L为透视投影矩阵元素组成的向量:T ,,p,p,p,p,p,p,p,p,p,p,p,p111213142122232431323334||AL||像机定标的任务就是寻找合适的L,使得为最小,即 min || AL || L给出约束: p,134'T,1T L,,(CC)CBL‘为L的前11个元素组成的向量, C为A前11列组成的矩阵, B为A前12列组成的向量。
6、程序代码I=imread ('DSCN0831.JPG');imshow(I);whosfigure,I1=rgb2gray(I);figure,imshow(I1)imhist(I1);I2=histeq(I1)figure,imshow(I2)figure,imhist(I2)a=imread('DSCN0831.JPG')imwrite(I1,'DSgray.jpg');imwrite(I2,'DSgrayeq.jpg');inf=imfinfo('DSCN0831.JPG') ?level=graythresh(I2);bw=im2bw(I2,level);figure,imshow(bw)whosI3=imadjust(I2,stretchlim(I2),[0 1]);figure,imshow(I3);a=imread('DSCN0831.JPG');b=imread('DSgray.jpg');subplot(1,2,1),imshow(a);subplot(1,2,2),imshow(b);clear;xpot=[];ypot=[];imshow('DSCN0831.JPG');hold on;n=input('Please input the number of pot:'); for i=1:n [x,y]=ginput(1);plot(x,y,'or');text(x+1,y+1,num2str(i));xpot=[xpot,x];ypot=[ypot,y];end[xpot;ypot][xw;yw;zw]a=[xw',yw',zw',ones([100 1]),zeros([1004]),(-1)*xpot'.*xw',(-1)*xpot'.*yw',(-1)*xpot'.*zw',-1*xpot';zeros([100 4]),xw',yw',zw',ones([100 1]),(-1)*ypot'.*xw',(-1)*ypot'.*yw',(-1)*ypot'.*zw',-1*ypot'];c=a(:,1:11);b=a(:,12);l=(-1)*(c'*c)^(-1)*c'*b7、运行结果, 图像信息:Filename: 'DSCN0831.JPG'FileModDate: '21-十月-2011 21:29:34'FileSize: 160501Format: 'jpg'FormatVersion: ''Width: 1024Height: 768BitDepth: 24ColorType: 'truecolor'FormatSignature: ''NumberOfSamples: 3CodingMethod: 'Huffman'CodingProcess: 'Sequential'Comment: {}ImageDescription: ' 'Make: 'NIKON 'Model: 'E990 'Orientation: 1XResolution: 300YResolution: 300 ResolutionUnit: 'Inch' Software: 'E990v1.0 ' DateTime: '0000:00:00 00:00:00 ' YCbCrPositioning: 'Co-sited' DigitalCamera: [1x1 struct], 检查内存中的图像:Name Size Bytes Class Attributes I 768x1024x3 2359296 uint8I1 768x1024 786432 uint8I2 768x1024 786432 uint8a 768x1024x3 2359296 uint8bw 768x1024 786432 logicalinf 1x1 12144 structlevel 1x1 8 double , 图像图一直方图图二均衡后的直方图图三调节对比度后的图像图四二进制图图五灰度图图六显示两幅图像图七标定图, 定块图像的特征点坐标Columns 1 through 9-0.0818 -0.3738 0.3232 0.8692 0.5916 0.1596 -0.5593 -1.1503 -0.91881.0132 1.2610 1.2829 0.8808 0.7317 0.8048 0.0446 0.3487 0.8531Columns 10 through 18-0.1365 -0.7079 -1.4787 -1.4430 -1.2126 -1.8520 -2.8819 -3.5305 -4.32890.4174 -0.1265 0.0022 0.5168 0.6806 1.8721 2.7697 3.0680 3.6265Columns 19 through 27-4.9902 -5.4902 -5.9902 -6.4902 -6.9672 -7.4556 -7.9556 -8.4556 -8.95564.1557 4.65575.1557 5.65576.1703 6.67037.1703 7.67038.1703Columns 28 through 364 -9.2702 -9.2702 -9.2702 -9.3865 -9.3796 -9.287-9.2702 -9.2759 -9.28178.7069 9.2727 9.7580 10.2580 10.7580 11.2580 11.7580 12.2654 12.7873Columns 37 through 45-9.2874 -9.2874 -9.2874 -9.2874 -9.2874 -9.2874 -9.2874 -9.2874 -9.287413.2946 13.7946 14.2946 14.7946 15.2946 15.7946 16.2946 16.794617.2946Columns 46 through 54-9.2874 -9.2874 -9.2874 -9.2874 -9.1319 -9.0801 -8.9706 -8.5455 -8.879617.7946 18.2946 18.7946 19.2946 19.2902 19.2317 19.0855 18.851618.2054Columns 55 through 63-9.1734 -9.7483 -9.6031 -9.2978 -8.8381 -8.7298 -9.0697 -9.6849 -10.213717.8297 18.0095 18.8896 18.8487 18.4320 17.8589 17.4174 16.917416.4247Columns 64 through 72-10.8174 -11.5421 -12.8646 -13.8704 -14.8589 -15.5248 -16.0467 -16.1262 -15.590416.0197 16.1221 16.4803 16.9262 17.7332 18.6382 19.6089 20.470020.4437Columns 73 through 81-15.1653 -15.1492 -15.6503 -16.4153 -16.9153 -16.4591 -15.9591 -15.5167 -16.559320.0855 19.7273 19.2712 19.3341 19.3633 19.3560 19.3560 19.3487 19.7727Columns 82 through 90-18.9315 -18.6146 -19.7033 -17.5651 -18.4268 -18.9672-20.3520 -20.8520 -20.372720.1776 19.8224 19.0665 18.3253 17.9905 17.841417.5636 17.5636 17.5636Columns 91 through 99-19.7402 -18.9061 -17.9349 -17.4706 -17.1377 -17.3796 -17.6734 -18.5132 -19.461417.5782 17.6294 17.9437 18.5285 19.6893 20.7478 21.7332 22.1849 22.3268Column 100-19.834722.1148ans =1.0e+003 *Columns 1 through 90.5020 0.5050 0.5065 0.5125 0.5080 0.5155 0.5125 0.5140 0.44800.7212 0.6492 0.5683 0.4797 0.3957 0.2982 0.2022 0.1047 0.6943Columns 10 through 180.4465 0.4465 0.4465 0.4465 0.4465 0.4465 0.4450 0.3880 0.33700.6178 0.5383 0.4557 0.3717 0.2832 0.1857 0.0957 0.0867 0.0837 Columns 19 through 270.2875 0.2455 0.2035 0.1705 0.1735 0.2065 0.2455 0.2890 0.3385 0.0747 0.0702 0.0627 0.0642 0.1332 0.1422 0.1482 0.1572 0.1662 Columns 28 through 360.3880 0.3910 0.3400 0.2935 0.2515 0.2110 0.1795 0.1780 0.2155 0.1797 0.2652 0.2532 0.2382 0.2292 0.2172 0.2082 0.2757 0.2892 Columns 37 through 450.2530 0.2950 0.3415 0.3910 0.3925 0.3415 0.2965 0.2560 0.2170 0.3027 0.3207 0.3357 0.3552 0.4347 0.4152 0.3957 0.3792 0.3582 Columns 46 through 540.1825 0.1885 0.2200 0.2590 0.2980 0.3445 0.3955 0.3940 0.3475 0.3447 0.4092 0.4302 0.4437 0.4662 0.4902 0.5112 0.5893 0.5623 Columns 55 through 630.3025 0.2635 0.2230 0.1900 0.2275 0.2680 0.3040 0.3475 0.3955 0.5367 0.5172 0.4962 0.4767 0.5577 0.5817 0.6042 0.6312 0.6597 Columns 64 through 720.5665 0.5725 0.5725 0.5740 0.5755 0.5800 0.5815 0.5860 0.6490 0.6943 0.6252 0.5473 0.4617 0.3762 0.2862 0.1932 0.0987 0.0927 Columns 73 through 810.6475 0.6430 0.6400 0.6370 0.6340 0.6280 0.6265 0.6820 0.6850 0.1827 0.2727 0.3627 0.4422 0.5232 0.5998 0.6687 0.6478 0.5757 Columns 82 through 900.6880 0.6940 0.6970 0.7015 0.7045 0.71351.1485 0.7285 0.73600.5037 0.4227 0.3447 0.2622 0.1767 0.0867 -0.2478 0.6222 0.5533 Columns 91 through 990.7390 0.7465 0.7495 0.7555 0.8065 0.8560 0.8350 0.8335 0.8455 0.4842 0.4122 0.3327 0.2517 0.2442 0.1587 0.3807 0.4452 0.3102 Column 1000.82150.5787, 转换为世界坐标ans =Columns 1 through 1760 60 60 60 100 100 100 100 100 120 140 140 140 140 140 140 140 0 0 0 0 0 0 0 0 0 0 0 0 20 20 20 20 6060 80 100 120 100 80 60 40 20 80 120 60 120 100 80 40 80 Columns 18 through 34140 140 140 140 140 140 140 140 20 20 20 20 60 60 60 60 6060 60 100 100 120 120 120 140 0 40 80 120 120 100 80 60 4060 40 60 120 120 100 60 40 140 140 140 140 140 140 140 140 140 Columns 35 through 50100 100 120 120 120 120 140 140 140 140 140100 80 60 40 2080 0 100 80 60 40 20 40 60 100 120 140 140 140 140 140140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140。