使用线边缘进行Matlab图像分割

SimaGuanxing

我想将图像分为3部分,如图2所示。我所做的第一项工作是使用Canny边缘检测来提取边缘,如图3所示,使用下面的代码。

rgb = imread('Camera_205.png');
I = rgb2gray(rgb);
imshow(I)

figure
BW = edge(I,'canny',0.6);
BW = bwareaopen(BW, 80);
imshow(BW);

我的问题是如何通过使用此边缘将图像分为3个部分?我认为区域增长方法在这里不起作用,因为该行未连接到图像的末端。您可以随意下载第一张图像并进行测试。谢谢您的帮助。原始彩色图像 需要细分为3部分的图片 边缘图像

指甲花玛丹

这些是边缘伪像。Canny在内部使用渐变,目前尚不清楚如何在图像边界处计算渐变(在matlab中也模糊了edge)。只需裁剪BW图像即可。

编辑:

The default value of sigma for gaussian blurring in edge is 1.41 pixels. So If you crop approximately twice that and additional 2 pixels to account for sobel kernel used to calculate gradient (5 pixels in total) from each edge (I mean edge of the image, not the detected edges), you'll get rid of the edge artifacts.

Like this

BW_cropped = BW(5:end-5,5:end-5)

Then add back those 5 pixels to each coordinate if your image processing involves finding positions of something in the image.

EDIT2:

For example to get all pixels in regions of cropped image use bwconncomp on inverted image like this:

CC=bwconncomp(not(BW_cropped),4);

Result:

>> CC

CC = 

    Connectivity: 4
       ImageSize: [471 631]
      NumObjects: 3
    PixelIdxList: {[40405x1 double]  [254682x1 double]  [1430x1 double]}

So you get and output structure , where field PixelIdxList gives you a three element (number of regions) of indeces of all pixels within your regions (indexing into the cropped_BW).

然后,您可以在regionprops功能中使用CC来获取有关您的区域的一些信息(例如区域或质心,请参阅所有选项的帮助)

编辑3:

示例代码:

a = imread('XEDCa.png');

I = rgb2gray(a);
BW = edge(I,'canny',0.6);
BW_cropped = BW(5:end-5,5:end-5);
CC=bwconncomp(not(BW_cropped),4)
imagesc(labelmatrix(CC))

结果:

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章