数字图像分割与边缘检测实验附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电子书和数学建模资料

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值