数字图像分割与边缘检测实验附matlab代码 |
您所在的位置:网站首页 › 连通域分析算法Matlab › 数字图像分割与边缘检测实验附matlab代码 |
✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。 🍎个人主页:Matlab科研工作室 🍊个人信条:格物致知。 ⛄ 内容介绍 数字图像处理中几种常见的边缘检测算子,通过MATLAB进行实现;各个算子的边缘检测效果及抗噪能力分析,得出了各自的优缺点和适用范围. 问题1:编写程序实现一阶Sobel算子,进行图像的边缘提取; 问题2:编写程序实现一阶Prewitt算子,进行图像的边缘提取; 问题3:编写程序实现一阶Roberts算子,进行图像的边缘提取; 问题4:编写程序实现二阶Laplacian算子(3*3),进行图像的边缘提取。 ⛄ 部分代码diagram_row = 5; diagram_col = 6; for imgs = 1:5 img_name = [num2str(imgs),'.jpg']; img = imread(img_name); figure(imgs); img = rgb2gray(img); newPlot(diagram_row,diagram_col,img,1,"原图");
DrawHist(diagram_row, diagram_col, img, 2, '灰度直方图'); img_divided = HistThreshold(img); newPlot(diagram_row, diagram_col, img_divided, 3, '2值图像');
end function DrawHist(out_row, out_col, img, pos, tit) [height,width] = size(img); count = zeros(1,256); for i = 1:height for j = 1:width count(1,img(i,j)+1) = count(1,img(i,j)+1)+1; end end subplot(out_row,out_col,pos); bar(count); title(tit); end function result = HistThreshold(data) [height,width] = size(data); temp_img = data; count = zeros(1,256); for i = 1:height for j = 1:width count(1,data(i,j)+1) = count(1,data(i,j)+1)+1; end end max1 = 1; max2 = 1; for i=2:256 temp = count(1,i); if temp > count(1,max1) max2 = max1; max1 = i; elseif temp > count(1,max2) max2 = i; end end
mid = round((max1+max2)/2); threshold = mid;
for i = 1:height for j = 1:width if temp_img(i,j) < threshold temp_img(i,j) = 0; else temp_img(i,j) = 255; end end end result = temp_img; end function newPlot(row,col,data,count,plotTitle) subplot(row,col,count); imshow(data); title(plotTitle); end ⛄ 运行结果[1] 王玲. 基于Matlab的图像分割和边缘检测教学的研究[J]. 电脑知识与技术, 2015(3X):3. [2] NASSIR HUSSIEN SALMAN ALMFRGY. 基于图象分割和边缘检测的数字图象分析[D]. 上海交通大学, 2002. [3] 农海啸. 基于MATLAB的数字图像边缘检测算子的实验对比研究[J]. 南宁师范高等专科学校学报, 2008, 25(2):129-131. ⛳️ 代码获取关注我❤️部分理论引用网络文献,若有侵权联系博主删除❤️ 关注我领取海量matlab电子书和数学建模资料 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |