K-means clustering based volume segmentation
L = imsegkmeans3(V,k)
[L,centers] = imsegkmeans3(V,k)
L = imsegkmeans3(V,k,Name,Value)
Load a 3-D grayscale MRI volume.
load mristack volshow(mristack);
Segment the volume into three clusters.
L = imsegkmeans3(mristack,3);
Display the segmented volume in a figure window. You can explore slices of the segmented volume by using the Volume Viewer app.
V— Volume to segment
Volume to segment, specified as a 3-D grayscale volume of size m-by-n-by-p or a 3-D multispectral volume of size m-by-n-by-p-by-c, where p is the number of planes and c is number of channels.
imsegkmeans2 treats 2-D color images like 3-D volumes of size
m-by-n-by-3. If you want 2-D behavior, use
k— Number of clusters
Number of clusters to create, specified as a numeric scalar.
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
L = imsegkmeans3(V,5,'NumAttempts',5);
'NormalizeInput'— Normalize input data
Normalize input data to zero mean and unit variance, specified as the
comma-separated pair consisting of
false. If you specify
imsegkmeans3 normalizes each
channel of the input individually.
'NumAttempts'— Number of times to repeat the clustering process
3(default) | positive integer
Number of times to repeat the clustering process using new initial cluster
centroid positions, specified as the comma-separated pair consisting of
'NumAttempts' and a positive integer.
'MaxIterations'— Maximum number of iterations
100(default) | positive integer
Maximum number of iterations, specified as the comma-separated pair consisting of
'MaxIterations' and a positive integer.
'Threshold'— Accuracy threshold
1e-4(default) | positive number
Accuracy threshold, specified as the comma-separated pair consisting of
'Threshold' and a positive number. The algorithm stops when each
of the cluster centers move less than the threshold value in consecutive
L— Label matrix
Label matrix, specified as a matrix of positive integers. Pixels with label 1 belong
to the first cluster, label 2 belong to the second cluster, and so on for each of the
L has the same first three
dimensions as volume
V. The class of
on number of clusters.
|Class of ||Number of Clusters|
centers— Cluster centroid locations
Cluster centroid locations, returned as a numeric matrix of size
k-by-c, where k is the number
of clusters and c is the number of channels.
centers is the same class as the image
The function yields reproducible results. The output will not vary in multiple runs given the same input arguments.