1、机器视觉2机器视觉与图像处理 实验报告学院名称 : 电气工程学院 专业班级 : 自动F1205 学生姓名 : 王国顺 学 号 : 201223911018 实验一实验内容:Matlab软件的使用1.打开MATLAB软件,了解菜单栏、工具栏、状态栏、命令窗口等;2.了解帮助文档help中演示内容demo有哪些;3.找到工具箱类里面的Image Processing工具箱,并进行初步学习,为后续实验做准备。实验步骤:实验二实验内容:图像的增强技术1.了解图像增强技术/方法的原理;2.利用matlab软件,以某一用途为例,实现图像的增强;3.通过程序的调试,初步了解图像处理命令的使用方法。实验步骤:
2、pout = imread(pout.tif);tire = imread(tire.tif);X map = imread(shadow.tif);shadow = ind2rgb(X,map); % convert to truecolorwidth = 210;images = pout, tire, shadow;for k = 1:3 dim = size(imagesk); imagesk = imresize(imagesk,width*dim(1)/dim(2) width,bicubic);Endpout = images1;tire = images2;shadow = i
3、mages3;pout_imadjust = imadjust(pout);pout_histeq = histeq(pout);pout_adapthisteq = adapthisteq(pout);imshow(pout);title(Original);figure, imshow(pout_imadjust);title(Imadjust);figure, imshow(pout_histeq);title(Histeq);figure, imshow(pout_adapthisteq);title(Adapthisteq); 实验三实验内容:图像特征提取1.了解图像特征提取的方法;
4、2.利用matlab软件,编程实现图像中长度、角度、半径、边界等特征的提取测量;3.通过程序的调试,初步了解图像特征提取命令的使用方法。实验步骤:1.load pendulum;immovie(frames);nFrames = size(frames,4);first_frame = frames(:,:,:,1);first_region = imcrop(first_frame,rect);frame_regions = repmat(uint8(0), size(first_region) nFrames);for count = 1:nFrames frame_regions(:,:
5、,:,count) = imcrop(frames(:,:,:,count),rect);endimmovie(frame_regions);seg_pend = false(size(first_region,1) size(first_region,2) nFrames);centroids = zeros(nFrames,2);se_disk = strel(disk,3);for count = 1:nFrames fr = frame_regions(:,:,:,count); imshow(fr) pause(0.2) gfr = rgb2gray(fr); gfr = imcom
6、plement(gfr); imshow(gfr) pause(0.2) bw = im2bw(gfr,.7); % threshold is determined experimentally bw = imopen(bw,se_disk); bw = imclearborder(bw); seg_pend(:,:,count) = bw; imshow(bw) pause(0.2)endfor count = 1:nFrames lab = bwlabel(seg_pend(:,:,count); property = regionprops(lab,Centroid); pend_cen
7、ters(count,:) = property.Centroid;endx = pend_centers(:,1);y = pend_centers(:,2);figureplot(x,y,m.), axis ij, axis equal, hold on;xlabel(x);ylabel(y);title(pendulum centers);abc = x y ones(length(x),1) -(x.2 + y.2);a = abc(1); b = abc(2); c = abc(3);xc = -a/2;yc = -b/2;circle_radius = sqrt(xc2 + yc2
8、) - c);pendulum_length = round(circle_radius)circle_theta = pi/3:0.01:pi*2/3;x_fit = circle_radius*cos(circle_theta)+xc;y_fit = circle_radius*sin(circle_theta)+yc;plot(x_fit,y_fit,b-);plot(xc,yc,bx,LineWidth,2);plot(xc x(1),yc y(1),b-);text(xc-110,yc+100,sprintf(pendulum length = %d pixels, pendulum
9、_length);实验结果: 2.RGB = imread(pillsetc.png);imshow(RGB);I = rgb2gray(RGB);threshold = graythresh(I);bw = im2bw(I,threshold);imshow(bw)% remove all object containing fewer than 30 pixelsbw = bwareaopen(bw,30);% fill a gap in the pens capse = strel(disk,2);bw = imclose(bw,se);% fill any holes, so that
10、 regionprops can be used to estimate% the area enclosed by each of the boundariesbw = imfill(bw,holes);imshow(bw)B,L = bwboundaries(bw,noholes);% Display the label matrix and draw each boundaryimshow(label2rgb(L, jet, .5 .5 .5)hold onfor k = 1:length(B) boundary = Bk; plot(boundary(:,2), boundary(:,
11、1), w, LineWidth, 2)endstats = regionprops(L,Area,Centroid);threshold = 0.94;% loop over the boundariesfor k = 1:length(B) % obtain (X,Y) boundary coordinates corresponding to label k boundary = Bk; % compute a simple estimate of the objects perimeter delta_sq = diff(boundary).2; perimeter = sum(sqr
12、t(sum(delta_sq,2); % obtain the area calculation corresponding to label k area = stats(k).Area; % compute the roundness metric metric = 4*pi*area/perimeter2; % display the results metric_string = sprintf(%2.2f,metric); % mark objects above the threshold with a black circle if metric threshold centro
13、id = stats(k).Centroid; plot(centroid(1),centroid(2),ko); end text(boundary(1,2)-35,boundary(1,1)+13,metric_string,Color,y,. FontSize,14,FontWeight,bold);endtitle(Metrics closer to 1 indicate that ,. the object is approximately round);实验结果: 3.RGB = imread(gantrycrane.png);imshow(RGB);text(size(RGB,2
14、),size(RGB,1)+15,Image courtesy of Jeff Mather,. FontSize,7,HorizontalAlignment,right);line(300 328,85 103,color,1 1 0);line(268 255,85 140,color,1 1 0);text(150,72,Measure the angle between these beams,Color,y,. FontWeight, bold);% you can obtain the coordinates of the rectangular region using% pix
15、el information displayed by imtoolstart_row = 34;start_col = 208;cropRGB = RGB(start_row:163, start_col:400, :);imshow(cropRGB)% Store (X,Y) offsets for later use; subtract 1 so that each offset will% correspond to the last pixel before the region of interestoffsetX = start_col-1;offsetY = start_row
16、-1;I = rgb2gray(cropRGB);threshold = graythresh(I);BW = im2bw(I,threshold);BW = BW; % complement the image (objects of interest must be white)imshow(BW)dim = size(BW);% horizontal beamcol1 = 4;row1 = min(find(BW(:,col1);% angled beamrow2 = 12;col2 = min(find(BW(row2,:);boundary1 = bwtraceboundary(BW
17、, row1, col1, N, 8, 70);% set the search direction to counterclockwise, in order to trace downward.boundary2 = bwtraceboundary(BW, row2, col2, E, 8, 90,counter);imshow(RGB); hold on;% apply offsets in order to draw in the original imageplot(offsetX+boundary1(:,2),offsetY+boundary1(:,1),g,LineWidth,2
18、);plot(offsetX+boundary2(:,2),offsetY+boundary2(:,1),g,LineWidth,2);实验结果: 4.RGB = imread(tape.png);imshow(RGB);text(15,15,Estimate radius of the roll of tape,. FontWeight,bold,Color,y);I = rgb2gray(RGB);threshold = graythresh(I);BW = im2bw(I,threshold);imshow(BW)dim = size(BW);col = round(dim(2)/2)-
19、90;row = find(BW(:,col), 1);connectivity = 8;num_points = 180;contour = bwtraceboundary(BW, row, col, N, connectivity, num_points);imshow(RGB);hold on;plot(contour(:,2),contour(:,1),g,LineWidth,2)x = contour(:,2);y = contour(:,1);% solve for parameters a, b, and c in the least-squares sense by% usin
20、g the backslash operatorabc = x y ones(length(x),1) -(x.2+y.2);a = abc(1); b = abc(2); c = abc(3);% calculate the location of the center and the radiusxc = -a/2;yc = -b/2;radius = sqrt(xc2+yc2)-c)% display the calculated centerplot(xc,yc,yx,LineWidth,2);% plot the entire circletheta = 0:0.01:2*pi;%
21、use parametric representation of the circle to obtain coordinates% of points on the circleXfit = radius*cos(theta) + xc;Yfit = radius*sin(theta) + yc;plot(Xfit, Yfit);message = sprintf(The estimated radius is %2.3f pixels, radius);text(15,15,message,Color,y,FontWeight,bold);实验结果: 实验四实验内容:图像变换1.了解图像变
22、换的原理;2.利用matlab软件,编程实现投影数据的图像重构;3.通过程序的调试,初步了解图像投影变换的应用。实验步骤:P = phantom(256);imshow(P)theta1 = 0:10:170;R1,xp = radon(P,theta1);num_angles_R1 = size(R1,2)theta3 = 0:2:178;R3,xp = radon(P,theta3);num_angles_R3 = size(R3,2)N_R1 = size(R1,1)N_R2 = size(R2,1)N_R3 = size(R3,1)P_128 = phantom(128);R_128,
23、xp_128 = radon(P_128,theta1);N_128 = size(R_128,1)figure, imagesc(theta3,xp,R3)colormap(hot)colorbarxlabel(Parallel Rotation Angle - theta (degrees);ylabel(Parallel Sensor Position - xprime (pixels);% Constrain the output size of each reconstruction to be the same as the% size of the original image,
24、 |P|.output_size = max(size(P);dtheta1 = theta1(2) - theta1(1);I1 = iradon(R1,dtheta1,output_size);figure, imshow(I1)dtheta2 = theta2(2) - theta2(1);I2 = iradon(R2,dtheta2,output_size);figure, imshow(I2)dtheta3 = theta3(2) - theta3(1);I3 = iradon(R3,dtheta3,output_size);figure, imshow(I3)D = 250;dse
25、nsor1 = 2;F1 = fanbeam(P,D,FanSensorSpacing,dsensor1);dsensor2 = 1;F2 = fanbeam(P,D,FanSensorSpacing,dsensor2);dsensor3 = 0.25;F3, sensor_pos3, fan_rot_angles3 = fanbeam(P,D,. FanSensorSpacing,dsensor3);figure, imagesc(fan_rot_angles3, sensor_pos3, F3)colormap(hot)colorbarxlabel(Fan Rotation Angle (
26、degrees)ylabel(Fan Sensor Position (degrees)Ifan1 = ifanbeam(F1,D,FanSensorSpacing,dsensor1,OutputSize,output_size);figure, imshow(Ifan1)Ifan2 = ifanbeam(F2,D,FanSensorSpacing,dsensor2,OutputSize,output_size);figure, imshow(Ifan2)Ifan3 = ifanbeam(F3,D,FanSensorSpacing,dsensor3,OutputSize,output_size
27、);figure, imshow(Ifan3)实验结果: 实验五实验内容:摄像机标定实验实验步骤:1 读取一幅画像并显示。2 检查内存中的画像。3 实现图像直方图均衡化4 读取图像中像素的坐标值5 保存图像6 检查新生成文件信息7 使用阈值操作将图像转换为二维图像8 根据RGB图像创建一幅灰度图像9 调节图像的对比度10 在同一个窗口内显示两幅图像11 掌握matlab命令及函数,获取标定块图像的特征点坐标12 根据摄像机标定方法原理,编写matlab程序,估计摄像机内参数和外参数实验总结 通过实验我学习掌握了许多知识,首先是对matlab有了一个全新的认识,了解了其在图像处理方面的巨大作用,对matlab的更多操作和命令的使用有了更高的掌握,最重要的事对matlab的处理能力有了一个更高的飞跃尤其是对相关函数的使用及相关问题的处理。相信在以后的学习和工作当中matlab将成为我非常有用的帮忙工具和好伙伴。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1