clean matlab 算法_Matlab的标记分水岭分割算法

1 综述

Separating touching objects in an image is one of the more difficult image processing operations. The watershed transform is often applied to this problem. The watershed transform finds "catchment basins"(集水盆) and "watershed ridge lines"(山脊线) in an image by treating it as a surface where light pixels are high and dark pixels are low.

如果图像中的目标物体是连接在一起的,则分割起来会更困难,分水岭分割算法经常用于处理这类问题,通常会取得比较好的效果。分水岭分割算法把图像看成一幅“地形图”,其中亮度比较强的区域像素值较大,而比较暗的区域像素值较小,通过寻找“汇水盆地”和“分水岭界限”,对图像进行分割。

Segmentation using the watershed transform works better if you can identify, or "mark," foreground objects and background locations. Marker-controlled watershed segmentation follows this basic procedure:

直接应用分水岭分割算法的效果往往并不好,如果在图像中对前景对象和背景对象进行标注区别,再应用分水岭算法会取得较好的分割效果。基于标记控制的分水岭分割方法有以下基本步骤:

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

1.计算分割函数。图像中较暗的区域是要分割的对象。

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

2.计算前景标志。这些是每个对象内部连接的斑点像素。

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

3.计算背景标志。这些是不属于任何对象的像素。

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

4.修改分割函数,使其仅在前景和后景标记位置有极小值。

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

5.对修改后的分割函数做分水岭变换计算。

Use by Matlab Image Processing Toolbox

使用MATLAB图像处理工具箱

注:期间用到了很多图像处理工具箱的函数,例如fspecial、imfilter、watershed、label2rgb、imopen、imclose、imreconstruct、imcomplement、imregionalmax、bwareaopen、graythresh和imimposemin函数等。

2 步骤

Step 1: Read in the Color Image and Convert it to Grayscale

第一步:读入彩色图像,将其转化成灰度图像

clc; clear all; close all;

rgb = imread('pears.png');

if ndims(rgb) == 3

I = rgb2gray(rgb);

else

I = rgb;

end

figure('units', 'normalized', 'position', [0 0 1 1]);

subplot(1, 2, 1); imshow(rgb); title('原图');

subplot(1, 2, 2); imshow(I); title('灰度图');

Step 2: Use the Gradient Magnitude as the Segmentation Function

第2步:将梯度幅值作为分割函数

Use the Sobel edge masks, imfilter, and some simple arithmetic to compute the gradient magnitude. The gradient is high at the borders of the objects and low (mostly) inside the objects.

使用Sobel边缘算子对图像进行水平和垂直方向的滤波,然后求取模值,sobel算子滤波后的图像在边界处会显示比较大的值,在没有边界处的值会很小。

hy = fspecial('sobel');

hx = hy';

Iy = imfilter(double(I), hy, 'replicate');

Ix = imfilter(double(I), hx, 'replicate');

gradmag = sqrt(Ix.^2 + Iy.^2);

figure('units', 'normalized', 'position', [0 0 1 1]);

subplot(1, 2, 1); imshow(I,[]), title('灰度图像')

subplot(1, 2, 2); imshow(gradmag,[]), title('梯度幅值图像')

Can you segment the image by using the watershed transform directly on the gradient magnitude?

可否直接对梯度幅值图像使用分水岭算法?

L = watershed(gradmag);

Lrgb = label2rgb(L);

figure('units', 'normalized', 'position', [0 0 1 1]);

subplot(1, 2, 1); imshow(gradmag,[]), title('梯度幅值图像')

subplot(1, 2, 2); imshow(Lrgb); title('梯度幅值做分水岭变换')

No. Without additional preprocessing such as the marker computations below, using t

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值