clean matlab 算法_分水岭算法——MATLAB(Watershed algorithm - MATLAB).doc

分水岭算法——MATLAB(Watershed algorithm - MATLAB)

分水岭算法——MATLAB(Watershed algorithm - MATLAB)

% 1. The Compute a segmentation function. This is an image whose dark regions are the objects you are trying to segment.

Calculate the partition function. The darker areas in the image are objects to be divided.

% 2. Compute foreground markers. These are connected blobs of pixels within each of the objects.

2. Calculate the foreground mark. These are the dot pixels of the internal connections of each object.

3 Compute background markers. These are pixels that are not part of any object.

Calculate the background flag. These are pixels that don't belong to any object.

% 4. Modify the segmentation function so that it only has minima at the foreground and background marker locations.

% 4. Modify the partition function to make it only have a minimum value in the foreground and backview mark position.

% 5. Compute the watershed transform of the modified segmentation function.

5. Calculate the watershed transformation for the modified partition function.

% Use by Matlab Image Processing Toolbox

% use MATLAB image processing toolbox

% note: during the period, many functions of image processing toolbox are used, such as fspecial, imfilter, watershed, label2rgb, imopen,

% imclose and imreconstruct, imcomplement, imregionalmax, bwareaopen, graythresh, imimposemin function and so on.

Read in the Color Image and Convert it to Grayscale

% the first step: read the color image and convert it to grayscale image

CLC. Clear all; Close all;

RGB = imread (' pears. PNG ');

If ndims (RGB) = = 3

I = rgb2gray (RGB);

The else

I = RGB.

The end

Figure (' units', 'position', 'position', [0, 0, 1]);

Subplot (1, 2, 1); Imshow (RGB); The title (' artwork ');

Subplot (1, 2, 2); Imshow (I); Title (' grayscale ');

Step 2: % Use the Gradient Magnitude as the Segmentation Function

% 2: the gradient is used as a partition function

% Use the Sobel edge, imfilter, and some simple products to compute the gradient.

The gradient is high at The borders of The object

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值