Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

labeloverlay

Overlay label matrix regions on 2-D image

Syntax

B = labeloverlay(A,L)
B = labeloverlay(A,BW)
B = labeloverlay(A,C)
B = labeloverlay(___,Name,Value)

Description

example

B = labeloverlay(A,L) fuses the input image, A, with a different color for each label in the label matrix, L.

example

B = labeloverlay(A,BW) fuses the input image with a color where the mask, BW, is true.

B = labeloverlay(A,C) fuses the input image with a different color for each label in the categorical matrix, C.

example

B = labeloverlay(___,Name,Value) computes the fused overlay image, B, using Name,Value pairs to control aspects of the computation.

Examples

collapse all

Read an image, then segment it using superpixels.

A = imread('kobi.png');
[L,N] = superpixels(A,20);

Fuse the segmentation results with the original image. Display the fused image.

B = labeloverlay(A,L);
imshow(B)

Read a grayscale image and display it.

A = imread('coins.png');
imshow(A)

Create a mask using binary thresholding.

t = graythresh(A);
BW = imbinarize(A,t);
imshow(BW)

Fuse the mask with the original image. Display the fused image.

B = labeloverlay(A,BW);
imshow(B)

Read a grayscale image and create a mask using binary thresholding.

A = imread('coins.png');
t = graythresh(A);
BW = imbinarize(A,t);

Create categorical labels based on the image contents.

stringArray = repmat("table",size(BW));
stringArray(BW) = "coin";
categoricalSegmentation = categorical(stringArray);

Fuse the categorical segmentation with the original image. Display the fused image.

B = labeloverlay(A,categoricalSegmentation);
imshow(B)

Fuse the original image with only one label from the categorical segmentation. Change the colormap and make the labels more opaque, and display the result.

C = labeloverlay(A,categoricalSegmentation,'IncludedLabels',"coin",...
    'Colormap','autumn','Transparency',0.25);
imshow(C)

Input Arguments

collapse all

Input image, specified as a 2-D grayscale or color image.

Data Types: single | double | int8 | int16 | uint8 | uint16

Labels, specified as a numeric matrix.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Mask, specified as a logical matrix.

Data Types: logical

Category labels, specified as a categorical matrix.

Data Types: categorical

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: labeloverlay(myImage,myLabels,'Colormap','hot') displays labels in colors from the 'hot' color map.

collapse all

Color map, specified as the comma-separated pair consisting of 'Colormap' and one of these values:

  • An l-by-3 color map. RGB triplets in each row of the color map must be normalized to the range [0, 1]. l is the number of labels in label matrix L, binary mask BW, or categorical matrix C.

  • A string or character vector corresponding to one of the valid inputs to the colormap function. labeloverlay permutes the specified color map so that adjacent labels are more distinct.

Example: [0.2, 0.1, 0.5; 0.1, 0.5, 0.8]

Example: 'hot'

Data Types: single | double | char | string

Labels to display in the fused image, specified as the comma-separated pair consisting of 'IncludedLabels' and one of the following:

  • An integer, or vector of integers, in the range [1, max(L(:))].

  • A string, or vector of strings, corresponding to labels in categorical matrix C.

By default, all labels are displayed.

Example: [1,3,4]

Example: ["flower","stem"]

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | string

Transparency of displayed labels, specified as the comma-separated pair consisting of 'Transparency' and a number in the range [0, 1].

  • A value of 0 makes the colored labels completely opaque.

  • A value of 1 makes the colored labels completely transparent.

Data Types: single | double

Output Arguments

collapse all

Fused image, returned as a numeric matrix with the same size as A.

Data Types: uint8

See Also

| |

Topics

Introduced in R2017b

Was this topic helpful?