matlab经典代码大全.pdfVIP

  • 90
  • 0
  • 约4.69千字
  • 约 4页
  • 2020-09-04 发布于江苏
  • 举报
哈哈哈 MATLAB 显示正炫余炫图 : plot(x,y1,* r,x,y2,o b) 定义【 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]; %为什么 pathname 和 filename 要前面出现的位置相反才能运行呢??? %读取图片 im=imread(str); %使用图片 axes(handles.axes1); %显示图片 imshow(im); 边缘检测: global im str=get(hObject,string); axes (handles.axes1); switch str case 原图 imshow(im); case sobel BW = edge(rgb2gray(im),sobel); imshow(BW); case prewitt BW = edge(rgb2gray(im),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]; %Structuring Element I=rgb2gray(im); imshow(I,[]);title(Original Image); I=double(I); [im_height,im_width]=size(I); [se_height,se_width]=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); %Image to be used for dilation image_erosion=padarray(I,se_origin,256,both); %Image to be used for erosion %%%%%%%%%%%%%%%%%% %%% Dilation %%% %%%%%%%%%%%%%%%%%% for k=se_origin(1)+1:im_height+se_origin(1) for kk=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+halfh eight-1,kk-se_origin(2):kk+halfwidth-1))); end end figure;imshow(dilated_image,[]);title(Image after Dilation); %%%%%%%%%%%%%%%%% %%% Erosion %%% %%%%%%%%%%%%%%%%% se=se; for k=se_origin(2)+1:im_height+se_origin(2) for kk=se_origin(1)+1:im_width+se_origin(1) eroded_image(k-se_origin(2),kk-se_orig

文档评论(0)

1亿VIP精品文档

相关文档