MATLAB学习笔记 图像分割(二)
来源:互联网 发布:js弹出本地路径选择框 编辑:程序博客网 时间:2024/06/04 19:34
edge(f, ‘method’, par) 边缘检测函数
sobel边缘检测器(默认为sobel)
edge(f, ‘sobel’, T, dir);
dir 分为 vertical horizontal both(默认) 三种
f = imread('img16.tif');g = edge(f, 'sobel', 'vertical');subplot(1, 2, 1), imshow(f), title('原图');subplot(1, 2, 2), imshow(g), title('sobel');
- 输入:
*输出:
Prewitt边缘检测器
edge(f, ‘prewitt’, T, dir);
f = imread('img16.tif');g = edge(f, 'prewitt', 'vertical');subplot(1, 2, 1), imshow(f), title('原图');subplot(1, 2, 2), imshow(g), title('prewitt');
- 输入:
- 输出:
Roberts边缘检测器
edge(f, ‘roberts’, T, dir);
f = imread('img16.tif');g = edge(f, 'roberts', 'vertical');subplot(1, 2, 1), imshow(f), title('原图');subplot(1, 2, 2), imshow(g), title('roberts');
- 输入:
- 输出:
LoG边缘检测器
edge(f, ‘log’, T, sigma);
f = imread('img16.tif');g = edge(f, 'log', 'vertical');subplot(1, 2, 1), imshow(f), title('原图');subplot(1, 2, 2), imshow(g), title('log');
- 输入:
- 输出:
零交叉检测器
edge(f, ‘zerocross’, T, H);
f = imread('img16.tif');g = edge(f, 'zerocross', 'vertical');subplot(1, 2, 1), imshow(f), title('原图');subplot(1, 2, 2), imshow(g), title('zerocross');
- 输入:
- 输出:
Canny边缘检测器
edge(f, ‘canny’, T, sigma);
f = imread('img16.tif');g = edge(f, 'canny', 'vertical');subplot(1, 2, 1), imshow(f), title('原图');subplot(1, 2, 2), imshow(g), title('canny');
- 输入:
- 输出:
使用Sobel
f = imread('img16.tif');subplot(3, 2, 1), imshow(f), title('原图');[gv, v] = edge(f, 'sobel', 'vertical');subplot(3, 2, 2), imshow(gv), title('自动阈值 Sobel 垂直');[gv, v] = edge(f, 'sobel', 0.15, 'vertical');subplot(3, 2, 3), imshow(gv), title('0.15阈值 Sobel 垂直');[gv, v] = edge(f, 'sobel', 0.15);subplot(3, 2, 4), imshow(gv), title('0.15阈值 Sobel 垂直水平');w45 = [-2 -1 0; -1 0 1; 0 1 2];g = imfilter(double(f), w45, 'replicate');T = 0.3 * max(abs(g(:)));g = g > T;subplot(3, 2, 5), imshow(g), title('45%');w45 = [0 1 2; -1 0 1; -2 -1 0];g = imfilter(double(f), w45, 'replicate');T = 0.3 * max(abs(g(:)));g = g > T;subplot(3, 2, 6), imshow(g), title('-45%');
- 输入:
- 输出:
所有检测器比较
sobel prewitt roberts log zerocross canny
f = imread('img16.tif');[g, v] = edge(f, 'sobel', 'vertical');subplot(3, 4, 1), imshow(g), title('sobel'), xlabel(v);[g, v] = edge(f, 'prewitt', 'vertical');subplot(3, 4, 2), imshow(g), title('prewitt'), xlabel(v);[g, v] = edge(f, 'roberts', 'vertical');subplot(3, 4, 3), imshow(g), title('roberts'), xlabel(v);[g, v] = edge(f, 'log', 'vertical');subplot(3, 4, 4), imshow(g), title('log'), xlabel(v);[g, v] = edge(f, 'zerocross', 'vertical');subplot(3, 4, 5), imshow(g), title('zerocross'), xlabel(v);[g, v] = edge(f, 'canny', 'vertical');subplot(3, 4, 6), imshow(g), title('canny'), xlabel(v);[g, v] = edge(f, 'sobel', 0.05, 'vertical');subplot(3, 4, 7), imshow(g), title('sobel'), xlabel(v);[g, v] = edge(f, 'prewitt', 0.05, 'vertical');subplot(3, 4, 8), imshow(g), title('prewitt'), xlabel(v);[g, v] = edge(f, 'roberts', 0.06, 'vertical');subplot(3, 4, 9), imshow(g), title('roberts'), xlabel(v);[g, v] = edge(f, 'log', 0.003, 2.25, 'vertical');subplot(3, 4, 10), imshow(g), title('log'), xlabel(v);[g, v] = edge(f, 'zerocross', 0.003, 'vertical');subplot(3, 4, 11), imshow(g), title('zerocross'), xlabel(v);[g, v] = edge(f, 'canny', [0.04, 0.10], 1.5 , 'vertical');subplot(3, 4, 12), imshow(g), title('canny'), xlabel(v);
- 输入:
- 输出:
Hough变换的线检测
sparse(r, c, s, m, n)将矩阵变为稀疏矩阵
full(S) 可以将稀疏矩阵还原
hough(f, dtheta, drho) 计算Hough变换
f = zeros(101, 101);f(1, 1) = 1;f(101, 1) = 1;f(1, 101) = 1;f(101, 101) = 1;f(51, 51) = 1;H = hough(f);subplot(1, 2, 1), imshow(f), title('原图');subplot(1, 2, 2), imshow(H), title('计算');
- 输入:
- 输出:
利用Hough变换做峰值处理 houghpeaks
- 找到包含有最大值的hough变换单元并记下它的位置
- 把第一步中找到的最大值点的邻域中的hough变换单元设为零
- 重复该步骤,直到找到需要的峰值数时为止,或者达到一个指定的阈值时为止
利用Hough变换做线检测和链接
houghpixels(f, theta, rho, rbin, cbin)
找到图像中影响到峰值的每一个非零值点的位置。
houghlines(f, theta, rho, rr, cc, fillgap, minlength)
该函数采用以下策略
f = imread('img16.tif');f = edge(f, 'canny', [0.04, 0.10], 1.5 , 'vertical');[H, theta, rho] = hough(f, 0.5);subplot(1, 2, 1), imshow(imadjust(mat2gray(H)), 'XData', theta, 'YData', rho, 'InitialMagnification', 'fit'), axis on, axis normal;[r, c] = houghpeaks(H, 5);hold on;plot(theta(c), rho(r), 'LineStyle', 'none', 'marker', 's', 'color', 'r');lines = houghlines(f, theta, rho, r, c);subplot(1, 2, 2), imshow(f), hold on;for k = 1:length(lines)xy = [lines(k).point1 ; lines(k).point2];plot(xy(:, 2),xy(:,1),'LineWidth', 4, 'Color', 'r');end
- 输入:
- 输出:
阈值处理
* graythresh(f) 获得图像的阈值[0, 1]*
f = imread('coins.png');T = graythresh(f);g = im2bw(f, T);subplot(1, 2, 1), imshow(f), title('原图');subplot(1, 2, 2), imshow(g), title(T);
- 输入:
- 输出:
计算全局阈值
迭代策略
f = imread('img17.tif');T = 0.5 * (double(min(f(:))) + double(max(f(:))));done = false;while ~done g = f >= T; Tnext = 0.5 * (mean(f(g)) + mean(f(~g))); done = abs(T - Tnext) < 0.5; T = Tnext;endsubplot(1, 3, 1), imshow(f), title('原图');subplot(1, 3, 2), imshow(g), title('利用迭代策略');subplot(1, 3, 3), imshow(im2bw(f, graythresh(tofloat(f)))), title('利用graythresh');
- 输入:
- 输出:
局部阈值处理
f = imread('img17.tif');g = imsubtract(imadd(f, imtophat(f, strel('disk', 3))), imtophat(f, strel('disk', 3)));subplot(1, 3, 1), imshow(f), title('原图');subplot(1, 3, 2), imshow(g), title('顶帽后');subplot(1, 3, 3), imshow(im2bw(g, graythresh(tofloat(g)))), title('顶帽后进行阈值处理');
- 输入:
- 输出:
阅读全文
0 0
- MATLAB学习笔记 图像分割(二)
- MATLAB学习笔记 图像分割(一)
- Matlab图像处理学习笔记(二):基于颜色的图像分割
- MATLAB学习笔记 形态学图像处理(二)
- MATLAB学习笔记二(关于图像处理)
- Matlab图像处理学习笔记(九):获取叠加物体的数量并进行分割
- 图像处理学习笔记(二):基于颜色的图像分割
- Matlab图像处理笔记(二)
- Matlab图像处理笔记(二)
- OpenCV学习笔记-图像分割
- OpenCV学习笔记-图像分割
- MatLab学习笔记(二)
- Matlab学习笔记(二)
- MATLAB学习笔记(二)
- MATLAB学习笔记之二 图像的分类和显
- java 学习笔记(二) 字符串分割
- 学习OpenCV范例(二十二)—GrabCut图像分割
- matlab学习笔记(十二)---二值图像及其特征提取
- 编程模拟飞船加速变轨过程-物理基础篇(4) Kepler轨道及其描述(下)
- Linux字符设备驱动程序开发(2)-字符设备驱动模型分析
- Linux基本常用命令
- regexp_extract 正则表达式过滤
- [Leetcode] 249. Group Shifted Strings 解题报告
- MATLAB学习笔记 图像分割(二)
- ios textfield 改变 placeholder 颜色
- 类似于长按文章,有复制,收藏的功能
- 【入驻杂谈】[游戏投屏&串流技巧]论【一台高性能台式机 + 一台智能电视 + 一台iPad】如何结合
- 扩增子图表解读3热图:差异菌、OTU及功能
- java枚举enum的使用
- mysql.sock文件被删除后,如何本地登录mysql的
- maven3.5+hadoop2.7.3统计米骑测试日志KPI指标(三)
- TCP/IP、Http的区别