当前位置:网站首页>【第 06 章 MATLAB实现基于分水岭分割进行肺癌诊断】
【第 06 章 MATLAB实现基于分水岭分割进行肺癌诊断】
2022-06-22 01:02:00 【海宝7号】
MATLAB实例应用
源代码下载地址:
https://download.csdn.net/download/dongbao520/85693518
分水岭分割原理:
“分水岭是一种经典算法,用于分段也就是说,用于分离图像中的不同对象。 从用户定义的标记开始,分水岭算法将像素值视为局部地形(高程)。该算法从标记泛洪流域,直到属于不同标记的流域在分水岭上相遇。在许多情况下,标记被选为图像的局部最小值,从中淹没盆地。 在下面的例子中,两个重叠的圆将被分开。要做到这一点,需要计算一幅图像,即到背景的距离。选择该距离的最大值(即,距离的相反的最小值)作为标志,从这些标志中泛滥的盆地沿着分水岭线将两个圆分开。”
本文从分水岭分割进行图像识别展开讨论
效果如图



程序相对比较简单。。
自定义函数即可
Watershed_Fun.m
function Watershed_Fun(fileName)
rgb = imread(fileName);
if ndims(rgb) == 3
I = rgb2gray(rgb);
else
I = rgb;
end
sz = size(I);
if sz(1) ~= 256
I = imresize(I, 256/sz(1));
rgb = imresize(rgb, 256/sz(1));
end
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(I), hy, 'replicate');
Ix = imfilter(double(I), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
se = strel('disk', 3);
Io = imopen(I, se);
Ie = imerode(I, se);
Iobr = imreconstruct(Ie, I);
Ioc = imclose(Io, se);
Iobrd = imdilate(Iobr, se);
Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
fgm = imregionalmax(Iobrcbr);
se2 = strel(ones(3,3));
fgm2 = imclose(fgm, se2);
fgm3 = imerode(fgm2, se2);
fgm4 = bwareaopen(fgm3, 15);
bw = im2bw(Iobrcbr, graythresh(Iobrcbr));
D = bwdist(bw);
DL = watershed(D);
bgm = DL == 0;
gradmag2 = imimposemin(gradmag, bgm | fgm4);
L = watershed(gradmag2);
Lrgb = label2rgb(L, 'jet', 'w', 'shuffle');
[pathstr, name, ext] = fileparts(fileName);
filefolder = fullfile(pwd, '实验结果', [name, '_实验截图']);
if ~exist(filefolder, 'dir')
mkdir(filefolder);
end
h1 = figure(1);
set(h1, 'Name', '图像灰度化', 'NumberTitle', 'off');
subplot(1, 2, 1); imshow(rgb, []); title('原图像');
subplot(1, 2, 2); imshow(I, []); title('灰度图像');
fileurl = fullfile(filefolder, '1');
set(h1,'PaperPositionMode','auto');
print(h1,'-dtiff','-r200',fileurl);
h2 = figure(2);
set(h2, 'Name', '图像形态学操作', 'NumberTitle', 'off');
subplot(1, 2, 1); imshow(Iobrcbr, []); title('图像形态学操作');
subplot(1, 2, 2); imshow(bw, []); title('图像二值化');
fileurl = fullfile(filefolder, '2');
set(h2,'PaperPositionMode','auto');
print(h2,'-dtiff','-r200',fileurl);
h3 = figure(3);
set(h3, 'Name', '图像梯度显示', 'NumberTitle', 'off');
subplot(1, 2, 1); imshow(rgb, []); title('待处理图像');
subplot(1, 2, 2); imshow(gradmag, []); title('梯度图像');
fileurl = fullfile(filefolder, '3');
set(h3,'PaperPositionMode','auto');
print(h3,'-dtiff','-r200',fileurl);
h4 = figure(4); imshow(rgb, []); hold on;
himage = imshow(Lrgb);
set(h4, 'Name', '图像分水岭分割', 'NumberTitle', 'off');
set(himage, 'AlphaData', 0.3);
hold off;
fileurl = fullfile(filefolder, '4');
set(h4,'PaperPositionMode','auto');
print(h4,'-dtiff','-r200',fileurl);

源文件及其数据图像下载–>传送门
边栏推荐
- pyechart 绘制词云图
- 对标Copilot,国内首个:自然语言一键生成方法级代码aiXcoder XL来了
- Principle and Countermeasure of anti Association browser
- Find find files with different extensions
- Amazon evaluation browser, core knowledge points of Amazon evaluation risk control
- 数学知识复习:三重积分
- Classes and objects (Part 2)
- ASEMI快恢复二极管FR107参数,FR107实物,FR107应用
- 同济、阿里获CVPR最佳学生论文,李飞飞获黄煦涛奖,近6000人线下参会
- 【TensorRT】Video Swin-Transformer部署相关
猜你喜欢

类和对象(下)

Five years after graduation, I finally became a software testing engineer with a monthly salary of 13000

记录webscraper的使用过程

第 24 章 基于 Simulink 进行图像和视频处理--matlab深度学习实战整理

Navicat连接不到MySQL

LeetCode 5242. Best English letters with both upper and lower case

Some introduction and transplantation of lvgl
![[solution] Ming Chu Liang Zao video edge computing gateway solution](/img/67/20a9ece2dc7d3a842aff1fc651e4fc.png)
[solution] Ming Chu Liang Zao video edge computing gateway solution

Tongji and Ali won the CVPR best student thesis, lifeifei won the Huang xutao award, and nearly 6000 people attended the offline conference

数学知识复习:三重积分
随机推荐
第八届“互联网+”大赛|百度杰出架构师毕然解读产业赛道命题
ROS 2 driver is now available for ABB manipulator
PM2 learning
Want to join a big factory? Reading this article may help you
Some introduction and transplantation of lvgl
I just learned a cool 3D pyramid stereoscopic effect. Come and have a look
52 classes 110 common components and frameworks
3 minutes, take you to play with chat robot automation [top template]
修改字典的方法
Example and description of lvgl Demo 1
【TensorRT】Video Swin-Transformer部署相关
ROS 2 驱动程序现在可用于 ABB 的机械臂
初识Unity3D(项目结构、ProBuilder第三方插件)
Use of listctl virtual mode under wince
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql. sock' (2)
Panic: permission denied problems encountered when using gomonkey mock functions and methods and Solutions
第 25 章 基于小波变换的数字水印技术
twenty-one
google多用户防止关联工具
ASEMI快恢复二极管FR107参数,FR107实物,FR107应用