当前位置:网站首页>[chapter 06 MATLAB realizes lung cancer diagnosis based on watershed segmentation]

[chapter 06 MATLAB realizes lung cancer diagnosis based on watershed segmentation]

2022-06-22 01:54:00 Haibao 7

MATLAB Application instance

Source code download address :
https://download.csdn.net/download/dongbao520/85693518

The principle of watershed segmentation :

“ Watershed is a classical algorithm , Used for segmentation, that is , Used to separate different objects in an image . Start with a user-defined tag , Watershed algorithm regards pixel value as local terrain ( Altitude ). The algorithm starts from marking the flood basin , Until the watersheds belonging to different markers meet on the watershed . in many instances , The tag is selected as the local minimum of the image , Submerge the basin . In the following example , Two overlapping circles will be separated . Do that , Need to calculate an image , That is, the distance to the background . Select the maximum value of the distance ( namely , The opposite minimum of distance ) As a sign , The basin overflowing from these signs separates the two circles along the watershed line .”
This paper discusses image recognition based on watershed segmentation
The effect is as shown in the picture
 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here
The program is relatively simple ..

Just customize the function
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, ' experimental result ', [name, '_ Experimental screenshot ']);
if ~exist(filefolder, 'dir')
    mkdir(filefolder);
end
h1 = figure(1);
set(h1, 'Name', ' Image graying ', 'NumberTitle', 'off');
subplot(1, 2, 1); imshow(rgb, []); title(' Original image ');
subplot(1, 2, 2); imshow(I, []); title(' Grayscale image ');
fileurl = fullfile(filefolder, '1');
set(h1,'PaperPositionMode','auto');
print(h1,'-dtiff','-r200',fileurl);
h2 = figure(2);
set(h2, 'Name', ' Image morphology operation ', 'NumberTitle', 'off');
subplot(1, 2, 1); imshow(Iobrcbr, []); title(' Image morphology operation ');
subplot(1, 2, 2); imshow(bw, []); title(' Image binarization ');
fileurl = fullfile(filefolder, '2');
set(h2,'PaperPositionMode','auto');
print(h2,'-dtiff','-r200',fileurl);
h3 = figure(3);
set(h3, 'Name', ' Image gradient display ', 'NumberTitle', 'off');
subplot(1, 2, 1); imshow(rgb, []); title(' The image to be processed ');
subplot(1, 2, 2); imshow(gradmag, []); title(' Gradient image ');
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', ' Image watershed segmentation ', 'NumberTitle', 'off');
set(himage, 'AlphaData', 0.3);
hold off;
fileurl = fullfile(filefolder, '4');
set(h4,'PaperPositionMode','auto');
print(h4,'-dtiff','-r200',fileurl);

 Insert picture description here
Download the source file and its data image –> Portal

原网站

版权声明
本文为[Haibao 7]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220101378671.html