雅卡德

Jaccard相似性系数用于图像分割

Description

example

similarity= jaccard(BW1,BW2)computes the intersection of binary imagesBW1BW2除以联合BW1BW2, also known as the Jaccard index. The images can be binary images, label images, or categorical images.

example

similarity= jaccard(L1,L2)计算农协ccard index for each label in label imagesL1L2.

similarity= jaccard(C1,C2)计算农协ccard index for each category in categorical imagesC1C2.

Examples

collapse all

Read an image containing an object to segment. Convert the image to grayscale, and display the result.

A = imread('hands.jpg');I = rgb2gray(A); figure imshow(I) title('Original Image')

Use the active contours (snakes) method to segment the hand.

mask = false(size(i));蒙版(25:End-25,25:End-25)= true;bw = activeContour(i,mask,300);

Read in the ground truth against which to compare the segmentation.

bw_groundTruth = imread('hands1 mask.png');

Compute the Jaccard index of this segmentation.

相似性= jaccard(bw,bw_groundTruth);

Display the masks on top of each other. Colors indicate differences in the masks.

figure imshowpair(BW, BW_groundTruth) title(['jaccard index ='num2str(相似性)])

This example shows how to segment an image into multiple regions. The example then computes the Jaccard similarity coefficient for each region.

Read in an image with several regions to segment.

rgb = imread('yellowlily.jpg');

为区分其典型颜色特征的三个区域创建涂鸦。第一个区域将黄花分类。第二区将绿色的茎和叶子分类。最后一个区域将棕色污垢分为图像的两个单独的斑块。区域由4个元素向量指定,其元素表示ROI左上角的X和Y坐标,ROI的宽度和ROI的高度。

region1 = [350 700 425 120];% [x y w h] formatbw1 = false(size(rgb,1),大小(RGB,2));BW1(区域1(2):区域1(2)+区域1(4),区域1(1):区域1(1)+区域1(3))= true;区域2 = [800 1124 120 230];bw2 = false(size(rgb,1),大小(RGB,2));BW2(区域2(2):区域2(2)+区域2(4),区域2(1):region2(1)+reignes2(3))= true;区域3 = [20 1320 480 200;1010 290 180 240];bw3 = false(size(rgb,1),大小(RGB,2));BW3(区域3(1,2):区域3(1,2)+区域3(1,4),区域3(1,1):区域3(1,1)+区域3(1,3))= true;BW3(区域3(2,2):区域3(2,2)+区域3(2,4),区域3(2,1):区域3(2,1)+区域3(2,3))= true;

Display the seed regions on top of the image.

图IMShow(RGB)保持visboundaries(BW1,'颜色','r');visboundaries(BW2,'颜色','g');visboundaries(BW3,'颜色','b');标题('Seed Regions')

使用基于测量距离的颜色分割,将图像分为三个区域。

L = imseggeodesic(RGB,BW1,BW2,BW3,'AdaptiveChannelWeighting',true);

Load a ground truth segmentation of the image.

l_groundTruth = double(imread(imread)('yellowlily-segmented.png'));

Visually compare the segmentation results with the ground truth.

figure imshowpair(label2rgb(L),label2rgb(L_groundTruth),'montage') 标题('Comparison of Segmentation Results (Left) and Ground Truth (Right)')

Compute the Jaccard similarity index (IoU) for each segmented region.

相似性= jaccard(l,l_groundTruth)
similarity =3×10.8861 0.5683 0.8414

对于第二个区域而言,JACCARD相似性指数明显较小。该结果与分割结果的视觉比较一致,该结果将图像右下角的污垢错误地分类为叶子。

Input Arguments

collapse all

第一个二进制图像,指定为任何维度的逻辑数组。

Data Types:logical

第二个二进制图像,指定为与与BW1.

Data Types:logical

第一个标签图像,指定为任何维度的非负整数的数组。

Data Types:double

第二个标签图像,指定为非负整数的数组,大小与L1.

Data Types:double

第一个分类图像,指定为分类大批of any dimension.

Data Types:类别

Second categorical image, specified as a分类大批of the same size asC1.

Data Types:类别

Output Arguments

collapse all

Jaccard similarity coefficient, returned as a numeric scalar or numeric vector with values in the range [0, 1]. Asimilarityof 1 means that the segmentations in the two images are a perfect match. If the input arrays are:

  • 二进制图像,similarityis a scalar.

  • label images,similarityis a vector, where the first coefficient is the Jaccard index for label 1, the second coefficient is the Jaccard index for label 2, and so on.

  • 分类images,similarityis a vector, where the first coefficient is the Jaccard index for the first category, the second coefficient is the Jaccard index for the second category, and so on.

Data Types:double

More About

collapse all

jaccard相似系数

Jaccard相似性系数两组AB(also known as intersection over union or IoU) is expressed as:

雅卡德(A,B) = |intersection(A,B) | / |union(A,B) |

哪里|A|代表集合的基础A. The Jaccard index can also be expressed in terms of true positives (TP), false positives (FP) and false negatives (FN) 作为:

雅卡德(A,B) =TP/ (TP+FP+FN)

Jaccard索引与骰子指数有关:

雅卡德(A,B) =骰子(A,B) / (2 -骰子(A,B))

See Also

|

Introduced in R2017b