Main Content

使用纹理过滤器进行纹理分割

此示例显示了如何根据其纹理识别和细分区域。

read Image

read and display a grayscale image of textured patterns on a bag.

i = imread('bag.png');imshow(I) title(“原始图像”

图包含一个轴对象。带有标题原始图像的轴对象包含类型图像的对象。

Create Texture Image

Useentropyfilt至create a texture image. The functionentropyfiltreturns an array where each output pixel contains the entropy value of the 9-by-9 neighborhood around the corresponding pixel in the input image。熵是随机性的统计度量。

您也可以使用stdfiltandrangefilt获得类似的分割结果。要与本地熵的纹理图像进行比较,请创建纹理图像sandrshowing the local standard deviation and local range, respectively.

e =熵filt(i);s = stdfilt(i,一个(9));r = Rancefilt(i,Ones(9));

Userescale重新恢复纹理图像eands因此,如数据类型图像所期望的像素值在[0,1]范围内双倍的

EIM= rescale(E); Sim = rescale(S);

Display the three texture images in a montage.

montage({Eim,Sim,R},'尺寸',,,,[1 3],'BackgroundColor',,,,'W',,,,“边界”,20)标题(“纹理图像显示本地熵,本地标准偏差和本地范围”

图包含一个轴对象。The axes object with title Texture Images Showing Local Entropy, Local Standard Deviation, and Local Range contains an object of type image.

Create Mask for Bottom Texture

此示例通过处理熵纹理图像继续EIM。You can repeat a similar process for the other two types of texture images with other morphological functions to achieve similar segmentation results.

阈值重新缩放的图像EIM至segment the textures. A threshold value of 0.8 is selected because it is roughly the intensity value of pixels along the boundary between the textures.

BW1= imbinarize(Eim,0.8); imshow(BW1) title('Thresholded Texture Image'

图包含一个轴对象。带有标题阈值纹理图像的轴对象包含类型图像的对象。

二进制图像中的分段对象BW1是白色的。如果您比较BW1,您会注意到顶部纹理过于细分(多个白色对象),并且底部的纹理几乎整体分割。使用使用Bwareaopen

bwao= bwareaopen(BW1,2000); imshow(BWao) title(“区域开放的纹理图像”

图包含一个轴对象。带有标题区域纹理图像的轴对象包含类型图像的对象。

Use快到了平滑边缘并关闭对象中的任何开孔bwao。指定相同的9 x 9社区entropyfilt

nhood = ones(9); closeBWao = imclose(BWao,nhood); imshow(closeBWao) title(“封闭纹理图像”

图包含一个轴对象。The axes object with title Closed Texture Image contains an object of type image.

Useimfill填充物体中的孔Closebwao。底部纹理的面罩并不完美,因为掩码不会延伸到图像的底部。但是,您可以使用掩码来细分纹理。

mask = imfill(Closebwao,“何les');imshow(蒙版);标题(“底部纹理面具”

图包含一个轴对象。带有底部纹理标题蒙版的轴对象包含一个类型图像的对象。

使用面具到细分纹理

将纹理分为两个不同的图像。

texturetop = i;texturetop(蒙版)= 0;textureBottom = i;TextureBottom(〜mask)= 0;蒙太奇({texturetop,texturebottom},'尺寸',,,,[1 2],'BackgroundColor',,,,'W',,,,“边界”,20)标题(“分割顶部纹理(左)和分割的底部纹理(右)”

图包含一个轴对象。带有标题分割的顶部纹理(左)和分段的底部纹理(右)的轴对象包含一个类型图像的对象。

显示分割结果

创建具有标签1的标签矩阵,其中蒙版为错误的和标签2处的面具true。Overlay label matrix on the original image.

l =蒙版+1;imshow(labeloverlay(i,l))标题('Labeled Segmentation Regions'

图包含一个轴对象。带有标题标记的分割区域的轴对象包含类型图像的对象。

概述两种纹理之间的边界。

边界= bwperim(蒙版);imshow(labeloverlay(i,边界,"Colormap",,,,[0 1 1])) title(“纹理之间的边界”

图包含一个轴对象。具有标题边界之间纹理边界的轴对象包含类型图像的对象。

也可以看看

||||||