IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> 形态学图像处理-膨胀/腐蚀/闭运算/开运算实现(Matlab) -> 正文阅读

[人工智能]形态学图像处理-膨胀/腐蚀/闭运算/开运算实现(Matlab)

文章首发及后续更新:https://mwhls.top/2329.html
新的更新内容请到mwhls.top查看。
无图/无目录/格式错误/更多相关请到上方的文章首发页面查看。

目的

  • 使用33算子实现形态学图像处理中的膨胀、腐蚀、闭运算、开运算。
  • 使用bwmorph函数实现骨架提取、粗化、细化。

原理

  • 选用33模板.:
    • ICOperator = [0 1 0; 1 1 1; 0 1 0];
  • 使用prewitt算子获得图像边缘,并二值化处理。
  • 对处理后的图像进行形态学图像处理:
    • 膨胀:将模板与以每个像素为中心的33矩阵做点乘,并求和结果矩阵,如果结果大于0,则表示矩阵范围内有1值,可膨胀。
    • 腐蚀:将模板与以每个像素为中心的33矩阵做点乘,并求和结果矩阵,如果结果等于5,则表示模板中所有的像素都为1值,不可腐蚀。
    • 闭运算,对膨胀结果进行腐蚀。
    • 开运算,对腐蚀结果进行膨胀。

实验结果

代码

clear all;
ima = imread('lena_color.jpg');
imaGray = rgb2gray(ima);
[height, width] = size(imaGray);
histArray = zeros(1, 256);
%prewitt operator
prewittOperatorX = ([-1 0 1;-1 0 1;-1 0 1;]);
prewittOperatorY = ([-1 -1 -1; 0 0 0; 1 1 1]);
 
imaPrewitt = imaGray;
 
%prewitt edge
for row = 2:height-1
    for col = 2:width-1
        %prewitt
        temp = double(imaGray(row-1:row+1, col-1:col+1));
        tempX = prewittOperatorX .* temp;
        tempX = abs(sum(tempX(:)));
        tempY = prewittOperatorY .* temp;
        tempY = abs(sum(tempY(:)));
        imaPrewitt(row, col) = tempX + tempY;
    end
end
% binary
prewittThresholdValue = 70;
binaryArray = zeros(height, width);
for row = 1:height
    for col = 1:width
        %prewitt
        if(imaPrewitt(row, col) < prewittThresholdValue)
            imaPrewitt(row, col) = 255;
        else
            imaPrewitt(row, col) = 1;
        end
    end
end
 
%Dilate/Erode operator
ICOperator = [0 1 0; 1 1 1; 0 1 0];
 
% after template operation, Dilate will occur in value < 1275, and Erode
% will occur in 5 value.
imaDilate = imaPrewitt .* 255;
imaErode = imaPrewitt .* 255;
 
for row = 2:height-1
    for col = 2:width-1
        %prewitt
        temp = double(imaPrewitt(row-1:row+1, col-1:col+1));
        value = sum(sum(ICOperator .* temp));
        if(value < 1275)
            imaDilate(row, col) = 1;
            binaryArray(row, col) = 1;
        end
        if(value == 5)
            imaErode(row, col) = 1;
        end
    end
end
 
imaClose = imaPrewitt .* 255;
imaOpen = imaPrewitt .* 255;
 
for row = 2:height-1
    for col = 2:width-1
        %prewitt
        tempX = double(imaDilate(row-1:row+1, col-1:col+1));
        tempY = double(imaErode(row-1:row+1, col-1:col+1));
        valueX = sum(sum(ICOperator .* tempX));
        valueY = sum(sum(ICOperator .* tempY));
        if(valueY < 1275)
            imaOpen(row, col) = 1;
        end
        if(valueX == 5)
            imaClose(row, col) = 1;
        end
    end
end
 
%Morphology
times = inf;
imaBinary = im2bw(ima);
imaSkeleton = bwmorph(imaBinary, 'skel', times);
imaThicken = bwmorph(imaBinary, 'thicken', times);
imaThin = bwmorph(imaBinary, 'thin', times);
 
 

subplot(4,3,1);
imshow(imaGray), title('Origin');
subplot(4,3,2);
imshow(imaPrewitt), title('Gray');
subplot(4,3,4);
imshow(imaDilate), title('Dilate');
subplot(4,3,5);
imshow(imaErode), title('Erode');
subplot(4,3,7);
imshow(imaClose), title('Close');
subplot(4,3,8);
imshow(imaOpen), title('Open');
subplot(4,3,3);
imshow(imaBinary), title('Binary');
subplot(4,3,6);
imshow(imaSkeleton), title('Skeleton');
subplot(4,3,9);
imshow(imaThicken), title('Thicken');
subplot(4,3,12);
imshow(imaThin), title('Thin');
  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2021-07-04 19:55:33  更:2021-07-04 19:56:05 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年4日历 -2024/4/25 12:55:21-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码