使用纹理过滤器进行纹理分割
此示例显示了如何根据其纹理识别和细分区域。
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 functionentropyfilt
returns an array where each output pixel contains the entropy value of the 9-by-9 neighborhood around the corresponding pixel in the input image我
。熵是随机性的统计度量。
您也可以使用stdfilt
andrangefilt
获得类似的分割结果。要与本地熵的纹理图像进行比较,请创建纹理图像s
andr
showing the local standard deviation and local range, respectively.
e =熵filt(i);s = stdfilt(i,一个(9));r = Rancefilt(i,Ones(9));
Userescale
重新恢复纹理图像e
ands
因此,如数据类型图像所期望的像素值在[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)标题(“纹理图像显示本地熵,本地标准偏差和本地范围”)
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(“封闭纹理图像”)
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(“纹理之间的边界”)
也可以看看
entropyfilt
|Bwareaopen
|快到了
|inimbinarize
|imfill
|Bwperim
|rangefilt