Main Content


Display label overlay on bigimageshow object

Since R2021b



    showlabels(b,labels) displays the labels in the 2-D blocked image labels as an overlay on the blocked image displayed in the bigimageshow object, b.


    showlabels(b,labels,Name=Value) uses name-value arguments to modify the appearance of the overlay.

    Example: showlabels(b,labels,Colormap="jet") displays the label overlay using the "jet" colormap.


    collapse all

    Create a blocked image from the sample image tumor_091R.tif. This sample image is a training image of a lymph node containing tumor tissue from the CAMELYON16 data set. The image has been modified to have three coarse resolution levels, and has been adjusted to enforce a consistent aspect ratio and to register features at each level.

    bim = blockedImage("tumor_091R.tif");

    Create a label image at a coarse resolution level.

    First get a single-resolution image. By default, gather gets data from the coarsest resolution level.

    cim = gather(bim);

    Convert the image to grayscale. Use multithresh to calculate three threshold values to convert the image into a four-level image.

    cgim = im2gray(cim);
    numClasses = 4;
    thresh = multithresh(cgim,numClasses-1);

    Segment the image into four regions using imquantize, specifying the threshold levels returned by multithresh.

    labels = imquantize(cgim,thresh);
    axis square
    title("Coarse Label Image")

    Convert the labels image back to a blockedImage object, using the same spatial referencing as the original image at the coarsest resolution level.

    blabels = blockedImage(labels,WorldStart=bim.WorldStart(3,1:2),...

    Display the original blocked image.

    hB = bigimageshow(bim);

    Overlay the labels image on the original blocked image.


    Create a blocked image using a modified version of image tumor_091R.tif from the CAMELYON16 data set. The original image is a training image of a lymph node containing tumor tissue. The original image has eight resolution levels, and the finest level has resolution 53760-by-61440. The modified image has only three coarse resolution levels. The spatial referencing of the modified image has been adjusted to enforce a consistent aspect ratio and to register features at each level.

    bim = blockedImage("tumor_091R.tif");

    Create a mask at the coarsest resolution level and display it.

    blabels = apply(bim,@(bs)rgb2lightness(bs.Data)<80,Level=3);
    hbim = bigimageshow(blabels);

    Display the original blocked image with the mask as a label overlay. Use the Alphadata and Alphamap name-value arguments to display the mask background overlay as translucent and the mask foreground overlay as fully transparent.

    hbim = bigimageshow(bim);
    showlabels(hbim,blabels,AlphaData=blabels,Alphamap=[0.8 0])

    Load a file containing an image, img, and its corresponding pixel label data, label. Convert the image to a blockedImage object.

    bim = blockedImage(img);

    Create a blocked image of the categorical pixel label data. Display the order of the four label categories.

    blabel = blockedImage(label);
    labels = categories(blabel.InitialValue)
    labels = 4×1 cell
        {'sky'     }
        {'grass'   }

    Define a custom colormap specifying RGB triplets for each category. The first row of cmap corresponds to undefined pixel labels, and the remaining four rows correspond to each categorical label. Assign the sky overlay to display blue and the grass overlay to display green.

    cmap = [0 0 0; 0 0 1; 0 1 0; 0 0 0; 0 0 0];

    Define the transparency map.

    amap = [.5 .5 0 0];

    Display the original unlabeled blocked image and the label overlay on the same axes. The AlphaData and Alphamap name-value arguments map each defined category in blabel to the corresponding element in amap, making the sky and grass overlays translucent and the building and sidewalk overlays fully transparent. Undefined pixel labels map to the first element in amap.

    hbim = bigimageshow(bim);

    Figure contains an axes object. The axes object contains an object of type bigimageshow.

    Input Arguments

    collapse all

    bigimageshow object displaying 2-D blocked image data, specified as a bigimageshow object.

    Labels, specified as a 2-D blockedImage object, numeric matrix, or logical matrix. If labels is a blockedImage object with multiple resolution levels, showlabels selects the level closest to the current ResolutionLevel of b for display. If labels is specified as a numeric or logical matrix, showlabels converts the matrix to a blockedImage object.

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: showlabels(b,labels,AlphaData=labels,Alphamap=[0 0.1 0.1 0.5 1]) specifies five varying transparency values in the overlay by mapping each element in AlphaData to an index in Alphamap.

    Transparency data, specified in one of these forms:

    • Numeric scalar — Applies consistent transparency across the entire image.

    • 2-D blockedImage object — Applies varying transparency values based on the underlying pixel values. Transparency data must be the same size as the blockedImage object displayed in b.

    The function interprets the numeric scalar or underlying pixel values as indices of the transparency map specified by Alphamap. Values with a decimal portion are fixed to the nearest lower integer:

    • If the values are of type double or single, values of 1 or less map to the first element of Alphamap. Values equal to or greater than the length of Alphamap map to the last element of Alphamap.

    • If the values are of an integer data type, then values of 0 or less map to the first element of Alphamap. Values equal to or greater than the length of Alphmap map to the last element of Alphamap (or up to the range limits of the data type). The integer data types are uint8, uint16, uint32, uint64, int8, int16, int32, and int64.

    • If the values are of type logical, values of 0 map to the first element of Alphamap and values of 1 map to the second element of Alphamap.

    • If AlphaData is a categorical blockedImage object, the defined categories map to corresponding elements of Alphamap. You can verify the order in which categories map to Alphamap by using the categories function.

    Transparency map, specified as a numeric scalar or m-element vector. All values must be in the range [0, 1], where 0 is transparent and 1 is opaque. You can specify Alphamap as a 1-by-m or m-by-1 vector, where m is the number of transparency values.

    Colormap, specified as one of these values:

    • A c-by-3 colormap, where c is the number of colors in the colormap. RGB triplets in each row of the colormap must be normalized to the range [0, 1]. When c is greater than the number of labels l in the blocked image labels, showlabels uses only the first l colors of the colormap.

    • A string scalar or character vector corresponding to one of the valid inputs to the colormap function. showlabels permutes the specified colormap 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

    Version History

    Introduced in R2021b