✅ 操作成功!

分水岭算法

发布时间:2023-06-08 作者:admin 来源:文学

分水岭算法

分水岭算法

-

2023年2月25日发(作者:新区规划)% 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函数等。% Step 1: Read in the Color Image and Convert it to Grayscale% 第一步:读入彩色图像,将其转化成灰度图像clc; clear all; close all;rgb = imread('');if ndims(rgb) == 3I = rgb2gray(rgb);elseI = rgb;endfigure('units直接使用梯度模值图像进行分水岭算法得到的结果往往会存在过度分割的现象。因此通常需要分别对前景对象和背景对象进行标记,以获得更好的分割效果。% Step 3: Mark the Foreground Objects% 第3步:标记前景对象% A variety of procedures could be applied here to find the foreground markers,% which must be connected blobs of pixels inside each of the foreground objects.% In this example you'll use morphological techniques called "opening-by-reconstruction" and "closing-by-reconstruction" to "clean" up the image. % These operations will create flat maxima inside each object that can be located using imregionalmax.% 有多种方法可以应用在这里来获得前景标记,这些标记必须是前景对象内部的连接斑点像素。这个例子中,将使用形态学技术“基于开的重建”和“基于闭的重建”来清理图像。% 这些操作将会在每个对象内部创建单位极大值,使得可以使用imregionalmax来定位。% 开运算和闭运算:先腐蚀后膨胀称为开;先膨胀后腐蚀称为闭。开和闭这两种运算可以除去比结构元素小的特定图像细节,同时保证不产生全局几何失真。% 开运算可以把比结构元素小的突刺滤掉,切断细长搭接而起到分离作用;闭运算可以把比结构元素小的缺口或孔填充上,搭接短的间隔而起到连接作用。% Opening is an erosion followed by a dilation, while opening-by-reconstruction is an erosion followed by a morphological reconstruction.% Let's compare the two. First, compute the opening using imopen.% 开操作是腐蚀后膨胀,基于开的重建(基于重建的开操作)是腐蚀后进行形态学重建。下面比较这两种方式。首先,用imopen做开操作。se = strel('disk注意到大多闭塞处和阴影对象没有被标记,这就意味着这些对象在结果中将不会得到合理的分割。而且,一些对象的前景标记会一直到对象的边缘。% 这就意味着应该清理标记斑点的边缘,然后收缩它们。可以通过闭操作和腐蚀操作来完成。se2 = strel(ones(5,5));fgm2 = imclose(fgm, se2);fgm3 = imerode(fgm2, se2);figure('units

👁️ 阅读量:0