showlabels
Description
showlabels(
uses name-value arguments to modify the appearance of the overlay.b
,labels
,Name=Value
)
Example: showlabels(b,labels,Colormap="jet")
displays the label
overlay using the "jet"
colormap.
Examples
Display Blocked Image with Label Overlay
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); imagesc(labels) 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),...
WorldEnd=bim.WorldEnd(3,1:2));
Display the original blocked image.
figure hB = bigimageshow(bim);
Overlay the labels
image on the original blocked image.
showlabels(hB,blabels)
Modify Transparency of Blocked Image Label Overlay
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])
Display Categorical Labels as Blocked Image Overlay
Load a file containing an image, img
, and its corresponding pixel label data, label
. Convert the image to a blockedImage
object.
load("buildingPixelLabeled.mat")
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' }
{'building'}
{'sidewalk'}
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); showlabels(hbim,blabel,AlphaData=blabel,Alphamap=amap,Colormap=cmap)
Input Arguments
b
— bigimageshow
object displaying 2-D blocked image data
bigimageshow
object
bigimageshow
object displaying 2-D blocked image data, specified as
a bigimageshow
object.
labels
— Labels
2-D blockedImage
object | numeric matrix | logical matrix
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(
specifies five varying transparency values in the
overlay by mapping each element in b
,labels
,AlphaData=labels
,Alphamap=[0
0.1 0.1 0.5 1]
)AlphaData
to an index in
Alphamap
.
AlphaData
— Transparency data
1
(default) | numeric scalar | 2-D blockedImage
object
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 theblockedImage
object displayed inb
.
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
orsingle
, values of1
or less map to the first element ofAlphamap
. Values equal to or greater than the length ofAlphamap
map to the last element ofAlphamap
.If the values are of an integer data type, then values of
0
or less map to the first element ofAlphamap
. Values equal to or greater than the length ofAlphmap
map to the last element ofAlphamap
(or up to the range limits of the data type). The integer data types areuint8
,uint16
,uint32
,uint64
,int8
,int16
,int32
, andint64
.If the values are of type
logical
, values of0
map to the first element ofAlphamap
and values of1
map to the second element ofAlphamap
.If
AlphaData
is a categoricalblockedImage
object, the defined categories map to corresponding elements ofAlphamap
. You can verify the order in which categories map toAlphamap
by using thecategories
function.
Alphamap
— Transparency map
0.5
(default) | numeric scalar or m-element vector
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
— Colormap
"jet"
(default) | c-by-3 colormap | string scalar | character vector
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
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)