资源描述:
《matlab经典代码大全》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、哈哈哈MATLAB显示正炫余炫图:plot(x,y1,'*r',x,y2,'ob')定义【0,2π】;t=0:pi/10:2*pi;定义函数文件:function[返回变量列表]=函数名(输入变量列表)顺序结构:选择结构1)if-else-end语句其格式为:if逻辑表达式程序模块1;else程序模块2;End图片读取:%选择图片路径[filename,pathname]=...uigetfile({'*.jpg';'*.bmp';'*.gif'},'选择图片');%合成路径+文件名str=[pathname,filename];%为什
2、么pathname和filename要前面出现的位置相反才能运行呢???%读取图片im=imread(str);%使用图片axes(handles.axes1);%显示图片imshow(im);边缘检测:globalimstr=get(hObject,'string');axes(handles.axes1);switchstrcase'原图'imshow(im);case'sobel'BW=edge(rgb2gray(im),'sobel');imshow(BW);case'prewitt'BW=edge(rgb2gray(im),'
3、prewitt');imshow(BW);case'canny'BW=edge(rgb2gray(im),'canny');imshow(BW);Canny算子边缘定位精确性和抗噪声能力效果较好,是一个折中方案end;开闭运算:se=[1,1,1;1,1,1;1,1,1;1,1,1];%StructuringElementI=rgb2gray(im);imshow(I,[]);title('OriginalImage');I=double(I);[im_height,im_width]=size(I);[se_height,se_wid
4、th]=size(se);halfheight=floor(se_height/2);halfwidth=floor(se_width/2);[se_origin]=floor((size(se)+1)/2);image_dilation=padarray(I,se_origin,0,'both');%Imagetobeusedfordilationimage_erosion=padarray(I,se_origin,256,'both');%Imagetobeusedforerosion%%%%%%%%%%%%%%%%%%%%%Dil
5、ation%%%%%%%%%%%%%%%%%%%%%fork=se_origin(1)+1:im_height+se_origin(1)forkk=se_origin(2)+1:im_width+se_origin(2)dilated_image(k-se_origin(1),kk-se_origin(2))=max(max(se+image_dilation(k-se_origin(1):k+halfheight-1,kk-se_origin(2):kk+halfwidth-1)));endendfigure;imshow(dilat
6、ed_image,[]);title('ImageafterDilation');%%%%%%%%%%%%%%%%%%%%Erosion%%%%%%%%%%%%%%%%%%%%se=se';fork=se_origin(2)+1:im_height+se_origin(2)forkk=se_origin(1)+1:im_width+se_origin(1)eroded_image(k-se_origin(2),kk-se_origin(1))=min(min(image_erosion(k-se_origin(2):k+halfwidt
7、h-1,kk-se_origin(1):kk+halfheight-1)-se));endendfigure;imshow(eroded_image,[]);title('ImageafterErosion');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Opening(Erosionfirst,thenDilation)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%se=se';image_dilation2=eroded_i
8、mage;%Imagetobeusedfordilationfork=se_origin(1)+1:im_height-se_origin(1)forkk=se_origin(2)+1:im_width-s