segmentCells2D
Description
specifies options using one or more name-value arguments. For example, specify
labels
= segmentCells2D(cp
,im
,Name=Value
)ImageCellDiameter=50
if the cells in im
are
approximately 50 pixels in diameter.
Note
This functionality requires Deep Learning Toolbox™, Computer Vision Toolbox™, and the Medical Imaging Toolbox™ Interface for Cellpose Library. You can install the Medical Imaging Toolbox Interface for Cellpose Library from Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.
Examples
Segment 2-D Image Using Cellpose
Load a 2-D intensity image.
img = imread("AT3_1m4_01.tif");
imshow(img)
Specify the approximate diameter of the cells, in pixels.
averageCellDiameter = 56;
Create a cellpose
object. By default, the object uses the cyto2
model from the Cellpose Library.
cp = cellpose(Model="cyto2");
Segment the image, specifying the average cell diameter.
labels = segmentCells2D(cp,img,ImageCellDiameter=averageCellDiameter);
Display the labels overlaid on the original image.
B = labeloverlay(img,labels); imshow(B)
Input Arguments
cp
— Cellpose model configuration
cellpose
object
Cellpose model configuration, specified as a cellpose
object. The cellpose
object properties specify which model to use, and
define options such as model ensembling and whether to use a GPU.
im
— Intensity image
numeric matrix
Intensity image to segment, specified as a numeric matrix. The Cellpose Library
converts the values in im
to data type single
before segmenting the image.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
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: segmentCells2D(cp,im,ImageCellDiameter=50)
specifies that the
cells in im
are approximately 50 pixels in diameter.
AuxiliaryChannelImage
— Auxiliary channel image
zeros(size(im))
(default) | numeric matrix
Auxiliary channel image, specified as a 2-D numeric matrix the same size and data
type as im
. You can optionally specify this argument if the model
accepts a nuclear channel image. If you do not specify this value, the function passes
a matrix of zeros the same size as im
to the model. The Cellpose
Library converts the auxiliary channel image to data type single
.
This argument corresponds to the chan2
parameter in the Cellpose
Library.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
ImageCellDiameter
— Cell diameter in input image
positive numeric scalar
Cell diameter in the input image im
, specified as a positive
numeric scalar, in pixels. By default, the function assumes that
im
contains cells the same size as in the training data set,
and uses the diameter specified by the TrainingCellDiameter
property of cp
. This argument corresponds to the
diameter
parameter in the Cellpose Library.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
FlowErrorThreshold
— Flow error threshold
0.4
(default) | positive numeric scalar
Flow error threshold, specified as a positive numeric scalar. This argument
specifies the acceptable error between the flow fields output by the network and flow
fields reconstructed from the predicted label. A value between 0.1
and 3
is suitable for most images. This argument corresponds to the
flow_threshold
parameter in the Cellpose Library.
Increasing this value can cause the model to detect more cells, but can generate less accurate boundaries between cells.
Decreasing this value can cause the model to generate cleaner boundaries, but miss some cells.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
CellThreshold
— Cell probability threshold
0
(default) | numeric scalar
Cell probability threshold, specified as a numeric scalar. The model applies this
threshold to the network output, and includes pixels above the threshold in the label
predictions. A value between -6
and 6
is
suitable for most images. This argument corresponds to the
cellprob_threshold
parameter in the Cellpose Library.
Increasing this value can cause the model to generate cleaner boundaries, but miss some cells.
Decreasing this value can cause the model to detect more cells, but can generate less accurate boundaries between cells.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
NormalizeInput
— Normalize input image
true
or 1
(default) | false
or 0
Normalize input image, specified as a numeric or
logical 1
(true
) or 0
(false
). When set to true
, the function rescales the input
image and the auxiliary channel image, if specified, to the range [0, 1]. The function
maps the bottom 1% of intensity values of each image to 0
and the
top 1% of intensity values to 1
. This argument corresponds to the
normalize
parameter in the Cellpose Library.
Data Types: logical
Tile
— Tile input image
false
or 0
(default) | true
or 1
Tile input image, specified as a numeric or
logical 0
(false
) or 1
(true
). When set to true
, the function tiles the input image
into 224-by-224 pixel regions. Segmenting tiled images requires less GPU memory, but
takes longer. Tiling does not affect memory requirements on a CPU. This argument
corresponds to the tile
parameter in the Cellpose Library.
Data Types: logical
TileOverlap
— Overlap between tiles
0.1
(default) | positive numeric scalar
Overlap between tiles, specified as a positive numeric scalar. This argument
specifies the fractional overlap between adjacent tiles. For each pixel in overlapping
regions, the function averages the results across tiles to obtain the final value for
the pixel. A value between 0.05
and 0.5
is
suitable for most images. This argument corresponds to the
tile_overlap
parameter in the Cellpose Library.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
TileAndAugment
— Augment image
false
or 0
(default) | true
or 1
Augment images, specified as a numeric or
logical 0
(false
) or 1
(true
). When set to true
, the function sets
Tile
to true
and
TileOverlap
to 0.5
, generating tiles with
50% overlap. The function flips multiple copies of each tile vertically and
horizontally, and then averages results across orientations. Augmentation generally
increases accuracy, but decreases speed. This argument corresponds to the
augment
parameter in the Cellpose Library.
Data Types: logical
GPUBatchSize
— GPU batch size
8
(default) | positive integer
GPU batch size, specified as a positive integer. This argument has an effect only
when processing images on a GPU with Tile
set to
true
. The batch size specifies the number of tiles per batch.
Using a larger batch size increases speed, but requires more memory. This argument
corresponds to the batchsize
parameter in the Cellpose
Library.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
PostprocessAtOriginalSize
— Postprocess image at original size
true
or 1
(default) | false
or 0
Postprocess image at its original size, specified as a numeric or
logical 1
(true
) or 0
(false
). When set to true
, the function uses bilinear
interpolation to resize the network outputs to the size of the input image before
postprocessing them. Resizing before postprocessing can generate smoother boundaries
when ImageCellDiameter
is larger than the detectable cell
diameter of the model. When set to false
, the function uses nearest
neighbor interpolation to resize label images to the input size after postprocessing.
This argument is inversely related to the no_resample
parameter in
the Cellpose Library.
Data Types: logical
Output Arguments
labels
— Segmentation label image
numeric matrix
Segmentation label image, returned as a numeric matrix of data type
double
. Pixel values map to the labels returned by the model. For
example, if the model detects two cells, labels
has pixel values in
the range [0, 2], where background pixels have a value of 0
, the
first cell has pixel values of 1
, and the second cell has pixel
values of 2
.
References
[1] Stringer, Carsen, Tim Wang, Michalis Michaelos, and Marius Pachitariu. “Cellpose: A Generalist Algorithm for Cellular Segmentation.” Nature Methods 18, no. 1 (January 2021): 100–106. https://doi.org/10.1038/s41592-020-01018-x.
[2] Pachitariu, Marius, and Carsen Stringer. “Cellpose 2.0: How to Train Your Own Model.” Nature Methods 19, no. 12 (December 2022): 1634–41. https://doi.org/10.1038/s41592-022-01663-4.
Version History
Introduced in R2023b
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
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)