model bundle streamlines used as a reference to extract similar
streamlines from input tractogram
model_clust_thrfloat
MDF distance threshold for the model bundles
reduction_thrfloat, optional
Reduce search space in the target tractogram by (mm) (default 10)
reduction_distancestring, optional
Reduction distance type can be mdf or mam (default mdf)
slrbool, optional
Use Streamline-based Linear Registration (SLR) locally
(default True)
num_threadsint, optional
Number of threads to be used for OpenMP parallelization. If None
(default) the value of OMP_NUM_THREADS environment variable is used
if it is set, otherwise all available threads are used. If < 0 the
maximal number of threads minus \(|num_threads + 1|\) is used (enter
-1 to use as many threads as possible). 0 raises an error.
slr_metricBundleMinDistanceMetric
slr_x0array or int or str, optional
Transformation allowed. translation, rigid, similarity or scaling
Initial parametrization for the optimization.
If 1D array with:
a) 6 elements then only rigid registration is performed with
the 3 first elements for translation and 3 for rotation.
b) 7 elements also isotropic scaling is performed (similarity).
c) 12 elements then translation, rotation (in degrees),
scaling and shearing are performed (affine).
Here is an example of x0 with 12 elements:
x0=np.array([0,10,0,40,0,0,2.,1.5,1,0.1,-0.5,0])
This has translation (0, 10, 0), rotation (40, 0, 0) in
degrees, scaling (2., 1.5, 1) and shearing (0.1, -0.5, 0).
If int:
6
x0=np.array([0,0,0,0,0,0])
7
x0=np.array([0,0,0,0,0,0,1.])
12
x0=np.array([0,0,0,0,0,0,1.,1.,1,0,0,0])
If str:
“rigid”
x0=np.array([0,0,0,0,0,0])
“similarity”
x0=np.array([0,0,0,0,0,0,1.])
“affine”
x0=np.array([0,0,0,0,0,0,1.,1.,1,0,0,0])
slr_boundsarray, optional
SLR bounds.
slr_selecttuple, optional
Select the number of streamlines from model to neighborhood of
model to perform the local SLR.
slr_methodstring, optional
Optimization method ‘L_BFGS_B’ or ‘Powell’ optimizers can be used.
(default ‘L-BFGS-B’)
pruning_thrfloat, optional
Pruning after reducing the search space.
pruning_distancestring, optional
Pruning distance type can be mdf or mam.
Returns:
recognized_transfStreamlines
Recognized bundle in the space of the model tractogram
recognized_labelsarray
Indices of recognized bundle in the original tractogram
Refine and recognize the model_bundle in self.streamlines
This method expects once pruned streamlines as input. It refines the
first output of RecoBundles by applying second local slr (optional),
and second pruning. This method is useful when we are dealing with
noisy data or when we want to extract small tracks from tractograms.
This time, search space is created using pruned bundle and not model
bundle.
See [1], [2] for
further details about the method.
Parameters:
model_bundleStreamlines
model bundle streamlines used as a reference to extract similar
streamlines from input tractogram
pruned_streamlinesStreamlines
Recognized bundle from target tractogram by RecoBundles.
model_clust_thrfloat
MDF distance threshold for the model bundles
reduction_thrfloat
Reduce search space by (mm) (default 14)
reduction_distancestring
Reduction distance type can be mdf or mam (default mdf)
slrbool
Use Streamline-based Linear Registration (SLR) locally.
slr_metricBundleMinDistanceMetric
Bundle distance metric.
slr_x0array or int or str
Transformation allowed. translation, rigid, similarity or scaling
Initial parametrization for the optimization.
If 1D array with:
6 elements then only rigid registration is performed with
the 3 first elements for translation and 3 for rotation.
7 elements also isotropic scaling is performed (similarity).
12 elements then translation, rotation (in degrees),
scaling and shearing are performed (affine).
Here is an example of x0 with 12 elements:
x0=np.array([0,10,0,40,0,0,2.,1.5,1,0.1,-0.5,0])
This has translation (0, 10, 0), rotation (40, 0, 0) in
degrees, scaling (2., 1.5, 1) and shearing (0.1, -0.5, 0).
If int:
6
x0=np.array([0,0,0,0,0,0])
7
x0=np.array([0,0,0,0,0,0,1.])
12
x0=np.array([0,0,0,0,0,0,1.,1.,1,0,0,0])
If str:
“rigid”
x0=np.array([0,0,0,0,0,0])
“similarity”
x0=np.array([0,0,0,0,0,0,1.])
“affine”
x0=np.array([0,0,0,0,0,0,1.,1.,1,0,0,0])
slr_boundsarray
SLR bounds.
slr_selecttuple
Select the number of streamlines from model to neighborhood of
model to perform the local SLR.
slr_methodstring
Optimization method ‘L_BFGS_B’ or ‘Powell’ optimizers can be used.
pruning_thrfloat
Pruning after reducing the search space.
pruning_distancestring
Pruning distance type can be mdf or mam.
Returns:
recognized_transfStreamlines
Recognized bundle in the space of the model tractogram
recognized_labelsarray
Indices of recognized bundle in the original tractogram
Threshold controls
how much strictness user wants while calculating bundle adjacency
between two bundles. Smaller threshold means bundles should be strictly
adjacent to get higher BA score.
Extracted bundle from the whole brain tractogram (eg: AF_L)
expert_bundleStreamlines
Model bundle used as reference while extracting similar type bundle
from input tractogram
nb_ptsinteger, optional
Discretizing streamlines to have nb_pts number of points
thresholdfloat, optional
Threshold used for in computing bundle adjacency. Threshold controls
how much strictness user wants while calculating bundle adjacency
between two bundles. Smaller threshold means bundles should be strictly
adjacent to get higher BA score.
Calculates bundle shape similarity between two given bundles using
bundle adjacency (BA) metric
See [3], [2] for further
details about the method.
Parameters:
bundle1Streamlines
White matter tract from one subject (eg: AF_L)
bundle2Streamlines
White matter tract from another subject (eg: AF_L)
rngnp.random.Generator
Random number generator.
clust_thrarray-like, optional
list of clustering thresholds used in quickbundlesX
thresholdfloat, optional
Threshold used for in computing bundle adjacency. Threshold controls
how much strictness user wants while calculating shape similarity
between two bundles. Smaller threshold means bundles should be strictly
similar to get higher shape similarity score.
This can replace any class supporting indexing used for referencing
(e.g. list, tuple). Indexing an instance of this class will return the
index provided instead of the element. It does not support slicing.
Provides functionalities for interacting with a cluster.
Useful container to retrieve index of elements grouped together. If
a reference to the data is provided to cluster_map, elements will
be returned instead of their index when possible.
Parameters:
cluster_mapClusterMap object
Reference to the set of clusters this cluster is being part of.
idint, optional
Id of this cluster in its associated cluster_map object.
Provides functionalities for interacting with a cluster.
Useful container to retrieve the indices of elements grouped together and
the cluster’s centroid. If a reference to the data is provided to
cluster_map, elements will be returned instead of their index when
possible.
Parameters:
cluster_mapClusterMapCentroid object
Reference to the set of clusters this cluster is being part of.
idint, optional
Id of this cluster in its associated cluster_map object.
Provides functionalities for interacting with clustering outputs.
Useful container to create, remove, retrieve and filter clusters.
If refdata is given, elements will be returned instead of their
index when using Cluster objects.
Provides functionalities for interacting with clustering outputs
that have centroids.
Allows to retrieve easily the centroid of every cluster. Also, it is
a useful container to create, remove, retrieve and filter clusters.
If refdata is given, elements will be returned instead of their
index when using ClusterCentroid objects.
Parameters:
refdatalist
Actual elements that clustered indices refer to.
Attributes:
centroids
clusters
refdata
Methods
add_cluster(*clusters)
Adds one or multiple clusters to this cluster map.
clear()
Remove all clusters from this cluster map.
clusters_sizes()
Gets the size of every cluster contained in this cluster map.
get_large_clusters(min_size)
Gets clusters which contains at least min_size elements.
get_small_clusters(max_size)
Gets clusters which contains at most max_size elements.
remove_cluster(*clusters)
Remove one or multiple clusters from this cluster map.
size()
Gets number of clusters contained in this cluster map.
Given a list of streamlines, the QuickBundles algorithm
[3] sequentially assigns each streamline to its
closest bundle in \(\mathcal{O}(Nk)\) where \(N\) is the number of streamlines
and \(k\) is the final number of bundles. If for a given streamline its
closest bundle is farther than threshold, a new bundle is created and the
streamline is assigned to it except if the number of bundles has already
exceeded max_nb_clusters.
Parameters:
thresholdfloat
The maximum distance from a bundle for a streamline to be still
considered as part of it.
metricstr or Metric object, optional
The distance metric to use when comparing two streamlines. By default,
the Minimum average Direct-Flip (MDF) distance
[3] is used and streamlines are
automatically resampled so they have 12 points.
>>> fromdipy.segment.clusteringimportQuickBundles>>> fromdipy.dataimportget_fnames>>> fromdipy.io.streamlineimportload_tractogram>>> fromdipy.tracking.streamlineimportStreamlines>>> fname=get_fnames(name='fornix')>>> fornix=load_tractogram(fname,'same',... bbox_valid_check=False).streamlines>>> streamlines=Streamlines(fornix)>>> # Segment fornix with a threshold of 10mm and streamlines resampled>>> # to 12 points.>>> qb=QuickBundles(threshold=10.)>>> clusters=qb.cluster(streamlines)>>> len(clusters)4>>> list(map(len,clusters))[61, 191, 47, 1]>>> # Resampling streamlines differently is done explicitly as follows.>>> # Note this has an impact on the speed and the accuracy (tradeoff).>>> fromdipy.segment.featurespeedimportResampleFeature>>> fromdipy.segment.metricspeedimportAveragePointwiseEuclideanMetric>>> feature=ResampleFeature(nb_points=2)>>> metric=AveragePointwiseEuclideanMetric(feature)>>> qb=QuickBundles(threshold=10.,metric=metric)>>> clusters=qb.cluster(streamlines)>>> len(clusters)4>>> list(map(len,clusters))[58, 142, 72, 28]
Thresholds to use for each clustering layer. A threshold represents the
maximum distance from a cluster for a streamline to be still considered
as part of it.
metricstr or Metric object, optional
The distance metric to use when comparing two streamlines. By default,
the Minimum average Direct-Flip (MDF) distance
[3] is used and streamlines are
automatically resampled so they have 12 points.
Run QuickBundlesX and then run again on the centroids of the last layer.
Running again QuickBundles at a layer has the effect of merging
some of the clusters that may be originally divided because of branching.
This function help obtain a result at a QuickBundles quality but with
QuickBundlesX speed. The merging phase has low cost because it is applied
only on the centroids rather than the entire dataset.
See [3] and [4] for
further details about the method.
Parameters:
streamlinesStreamlines
Streamlines.
thresholdssequence
List of distance thresholds for QuickBundlesX.
nb_ptsint
Number of points for discretizing each streamline
select_randomlyint
Randomly select a specific number of streamlines. If None all the
streamlines are used.
rngnumpy.random.Generator
If None then generator is initialized internally.
verbosebool, optional.
If True, log information. Default False.
Returns:
clustersobj
Contains the clusters of the last layer of QuickBundlesX after merging.
Provides functionalities for interacting with a cluster.
Useful container to retrieve the indices of elements grouped together and
the cluster’s centroid. If a reference to the data is provided to
cluster_map, elements will be returned instead of their index when
possible.
Parameters:
cluster_mapClusterMapCentroid object
Reference to the set of clusters this cluster is being part of.
idint, optional
Id of this cluster in its associated cluster_map object.
Provides functionalities for interacting with clustering outputs
that have centroids.
Allows to retrieve easily the centroid of every cluster. Also, it is
a useful container to create, remove, retrieve and filter clusters.
If refdata is given, elements will be returned instead of their
index when using ClusterCentroid objects.
Parameters:
refdatalist
Actual elements that clustered indices refer to.
Attributes:
centroids
clusters
refdata
Methods
add_cluster(*clusters)
Adds one or multiple clusters to this cluster map.
clear()
Remove all clusters from this cluster map.
clusters_sizes()
Gets the size of every cluster contained in this cluster map.
get_large_clusters(min_size)
Gets clusters which contains at least min_size elements.
get_small_clusters(max_size)
Gets clusters which contains at most max_size elements.
remove_cluster(*clusters)
Remove one or multiple clusters from this cluster map.
size()
Gets number of clusters contained in this cluster map.
Converts a ClustersCentroid object (Cython) to a ClusterMapCentroid
object (Python).
Only basic functionalities are provided with a Clusters object. To have
more flexibility, one should use ClusterMap object, hence this conversion
function.
Parameters:
clusters_listClustersCentroid object
Result of the clustering contained in a Cython’s object.
Returns:
ClusterMapCentroid object
Result of the clustering contained in a Python’s object.
See [3] and [4] for
further details about the method.
Parameters:
streamlineslist of 2D arrays
List of streamlines to cluster.
metricMetric object
Tells how to compute the distance between two streamlines.
thresholdslist of double
Thresholds to use for each clustering layer. A threshold represents the
maximum distance from a cluster for a streamline to be still considered
as part of it.
orderingiterable of indices, optional
Iterate through data using the given ordering.
Returns:
TreeClusterMap object
Result of the clustering. Use get_clusters() to get the clusters at
a specific level of the hierarchy.
Provides functionalities for interacting with a cluster.
Useful container to retrieve the indices of elements grouped together and
the cluster’s centroid. If a reference to the data is provided to
cluster_map, elements will be returned instead of their index when
possible.
Parameters:
cluster_mapClusterMapCentroid object
Reference to the set of clusters this cluster is being part of.
idint, optional
Id of this cluster in its associated cluster_map object.
Provides functionalities for interacting with clustering outputs
that have centroids.
Allows to retrieve easily the centroid of every cluster. Also, it is
a useful container to create, remove, retrieve and filter clusters.
If refdata is given, elements will be returned instead of their
index when using ClusterCentroid objects.
Parameters:
refdatalist
Actual elements that clustered indices refer to.
Attributes:
centroids
clusters
refdata
Methods
add_cluster(*clusters)
Adds one or multiple clusters to this cluster map.
clear()
Remove all clusters from this cluster map.
clusters_sizes()
Gets the size of every cluster contained in this cluster map.
get_large_clusters(min_size)
Gets clusters which contains at least min_size elements.
get_small_clusters(max_size)
Gets clusters which contains at most max_size elements.
remove_cluster(*clusters)
Remove one or multiple clusters from this cluster map.
size()
Gets number of clusters contained in this cluster map.
A sequence of N-dimensional points is represented as a 2D array with
shape (nb_points, nb_dimensions).
The features being extracted are the points of the sequence once resampled.
This is useful for metrics requiring a constant number of points for all
streamlines.
Attributes:
is_order_invariant
Is this feature invariant to the sequence’s ordering
Methods
extract(datum)
Extracts features from a sequential datum.
infer_shape(datum)
Infers the shape of features extracted from a sequential datum.
A sequence of N-dimensional points is represented as a 2D array with
shape (nb_points, nb_dimensions).
The feature being extracted consists of one vector in the N-dimensional
space pointing from one end-point of the sequence to the other
(i.e. S[-1]-S[0]).
Attributes:
is_order_invariant
Is this feature invariant to the sequence’s ordering
Methods
extract(datum)
Extracts features from a sequential datum.
infer_shape(datum)
Infers the shape of features extracted from a sequential datum.
Binary mask. Has \(M\) dimensions where \(M <= V\). When \(M < V\), we
append \(V - M\) dimensions with axis length 1 to mask so that mask
will broadcast against vol. In the typical case vol can be 4D,
mask can be 3D, and we append a 1 to the mask shape which (via numpy
broadcasting) has the effect of applying the 3D mask to each 3D slice in
vol (vol[...,0] to vol[...,-1).
Returns:
masked_volndarray
vol multiplied by mask where mask may have been extended to match
extra dimensions in vol
Simple brain extraction tool method for images from DWI data.
It uses a median filter smoothing of the input_volumes vol_idx and an
automatic histogram Otsu thresholding technique, hence the name
median_otsu.
This function is inspired from Mrtrix’s bet which has default values
median_radius=3, numpass=2. However, from tests on multiple 1.5T
and 3T data from GE, Philips, Siemens, the most robust choice is
median_radius=4, numpass=4.
Parameters:
input_volumendarray
3D or 4D array of the brain volume.
vol_idxNone or array, optional
1D array representing indices of axis=3 of a 4D input_volume.
None is only an acceptable input if input_volume is 3D.
median_radiusint, optional
Radius (in voxels) of the applied median filter.
numpass: int, optional
Number of pass of the median filter.
autocrop: bool, optional
if True, the masked input_volume will also be cropped using the
bounding box defined by the masked data. Should be on if DWI is
upsampled to 1x1x1 resolution.
dilateNone or int, optional
number of iterations for binary dilation
finalize_maskbool, optional
Whether to remove potential holes or islands.
Useful for solving minor errors.
Returns:
maskedvolumendarray
Masked input_volume
mask3D ndarray
The binary brain mask
Notes
Copyright (C) 2011, the scikit-image team
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
Neither the name of skimage nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR “AS IS” AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Segment the cfa inside roi using the values from threshold as bounds.
Parameters:
tensor_fitTensorFit object
TensorFit object
roindarray
A binary mask, which contains the bounding box for the segmentation.
thresholdarray-like
An iterable that defines the min and max values to use for the
thresholding.
The values are specified as (R_min, R_max, G_min, G_max, B_min, B_max)
return_cfabool, optional
If True, the cfa is also returned.
Returns:
maskndarray
Binary mask of the segmentation.
cfandarray, optional
Array with shape = (…, 3), where … is the shape of tensor_fit.
The color fractional anisotropy, ordered as a nd array with the last
dimension of size 3 for the R, G and B channels.
Computes the average of pointwise Euclidean distances between two
sequential data.
A sequence of N-dimensional points is represented as a 2D array with
shape (nb_points, nb_dimensions). A feature object can be specified
in order to calculate the distance between the features, rather than
directly between the sequential data.
Parameters:
featureFeature object, optional
It is used to extract features before computing the distance.
Attributes:
feature
Feature object used to extract features from sequential data
is_order_invariant
Is this metric invariant to the sequence’s ordering
Methods
are_compatible(shape1, shape2)
Checks if features can be used by metric.dist based on their shape.
dist(features1, features2)
Computes a distance between two data points based on their features.
Notes
The distance between two 2D sequential data:
s1s20*a*0
\ |
\ |1*||b*1| \
2* \
c*2
is equal to \((a+b+c)/3\) where \(a\) is the Euclidean distance between s1[0] and
s2[0], \(b\) between s1[1] and s2[1] and \(c\) between s1[2] and s2[2].
A vector (i.e. a N-dimensional point) is represented as a 2D array with
shape (1, nb_dimensions).
Attributes:
feature
Feature object used to extract features from sequential data
is_order_invariant
Is this metric invariant to the sequence’s ordering
Methods
are_compatible(shape1, shape2)
Checks if features can be used by metric.dist based on their shape.
dist(features1, features2)
Computes a distance between two data points based on their features.
Notes
The distance between two vectors \(v_1\) and \(v_2\) is equal to
\(\frac{1}{\pi} \arccos\left(\frac{v_1 \cdot v_2}{\|v_1\| \|v_2\|}\right)\)
and is bounded within \([0,1]\).
A sequence of N-dimensional points is represented as a 2D array with
shape (nb_points, nb_dimensions). A feature object can be specified
in order to calculate the distance between extracted features, rather
than directly between the sequential data.
Parameters:
featureFeature object, optional
It is used to extract features before computing the distance.
Attributes:
feature
Feature object used to extract features from sequential data
is_order_invariant
Is this metric invariant to the sequence’s ordering
A sequence of N-dimensional points is represented as a 2D array with
shape (nb_points, nb_dimensions). A feature object can be specified
in order to calculate the distance between extracted features, rather
than directly between the sequential data.
Parameters:
featureFeature object, optional
It is used to extract features before computing the distance.
Is this metric invariant to the sequence’s ordering
Methods
are_compatible(shape1, shape2)
Checks if features can be used by metric.dist based on their shape.
dist(features1, features2)
Computes a distance between two data points based on their features.
Notes
The distance between two 2D sequential data:
s1s20*a*0
\ |
\ |1*||b*1| \
2* \
c*2
is equal to \(\min((a+b+c)/3, (a'+b'+c')/3)\) where \(a\) is the Euclidean distance
between s1[0] and s2[0], \(b\) between s1[1] and s2[1], \(c\) between s1[2]
and s2[2], \(a'\) between s1[0] and s2[2], \(b'\) between s1[1] and s2[1]
and \(c'\) between s1[2] and s2[0].
Computes the sum of pointwise Euclidean distances between two
sequential data.
A sequence of N-dimensional points is represented as a 2D array with
shape (nb_points, nb_dimensions). A feature object can be specified
in order to calculate the distance between the features, rather than
directly between the sequential data.
Parameters:
featureFeature object, optional
It is used to extract features before computing the distance.
Attributes:
feature
Feature object used to extract features from sequential data
is_order_invariant
Is this metric invariant to the sequence’s ordering
Methods
are_compatible(shape1, shape2)
Checks if features can be used by metric.dist based on their shape.
dist(features1, features2)
Computes a distance between two data points based on their features.
Notes
The distance between two 2D sequential data:
s1s20*a*0
\ |
\ |1*||b*1| \
2* \
c*2
is equal to \(a+b+c\) where \(a\) is the Euclidean distance between s1[0] and
s2[0], \(b\) between s1[1] and s2[1] and \(c\) between s1[2] and s2[2].
Computes the distance matrix between two lists of sequential data.
The distance matrix is obtained by computing the pairwise distance of all
tuples spawn by the Cartesian product of data1 with data2. If data2
is not provided, the Cartesian product of data1 with itself is used
instead. A sequence of N-dimensional points is represented as a 2D array with
shape (nb_points, nb_dimensions).
Parameters:
metricMetric object
Tells how to compute the distance between two sequential data.
Observation model assuming that the intensity of each class is constant.
The model parameters are the means \(\mu_{k}\) and variances \(\sigma_{k}\)
associated with each tissue class. According to this model, the observed
intensity at voxel \(x\) is given by \(I(x) = \mu_{k} + \eta_{k}\) where \(k\)
is the tissue class of voxel \(x\), and \(\eta_{k}\) is a Gaussian random
variable with zero mean and variance \(\sigma_{k}^{2}\). The observation
model is responsible for computing the negative log-likelihood of
observing any given intensity \(z\) at each voxel \(x\) assuming the voxel
belongs to each class \(k\). It also provides a default parameter
initialization.
Computes the gaussian negative log-likelihood of each class at each voxel of image assuming a gaussian distribution with means and variances given by mu and sigmasq, respectively (constant models along the full volume).
Computes the gaussian negative log-likelihood of each class at
each voxel of image assuming a gaussian distribution with means and
variances given by mu and sigmasq, respectively (constant models
along the full volume). The negative log-likelihood will be written
in nloglike.
Updates the means and the variances in each iteration for all
the labels. This is for equations 25 and 26 of Zhang et. al.,
IEEE Trans. Med. Imag, Vol. 20, No. 1, Jan 2001.
Parameters:
imagendarray
3D structural gray-scale image
P_L_Yndarray
4D probability map of the label given the input image
computed by the expectation maximization (EM) algorithm
mundarray
1 x nclasses, current estimate of the mean of each tissue
class.
nclassesint
number of tissue classes
Returns:
mu_updndarray
1 x nclasses, updated mean of each tissue class
var_updndarray
1 x nclasses, updated variance of each tissue class
Executes one iteration of the ICM algorithm for MRF MAP
estimation. The prior distribution of the MRF is a Gibbs
distribution with the Potts/Ising model with parameter beta:
Initializes the segmentation of an image with given
neg-loglikelihood
Initializes the segmentation of an image with neglog-likelihood field
given by nloglike. The class of each voxel is selected as the one
with the minimum neglog-likelihood (i.e. maximum-likelihood
segmentation).
Parameters:
nloglikendarray
4D shape, nloglike[x, y, z, k] is the likelihhood of class k
for voxel (x, y, z)
Conditional probability of the label given the neighborhood
Equation 2.18 of the Stan Z. Li book (Stan Z. Li, Markov Random Field
Modeling in Image Analysis, 3rd ed., Advances in Pattern Recognition
Series, Springer Verlag 2009.)
Parameters:
segndarray
3D tissue segmentation derived from the ICM model
betafloat
scalar that determines the importance of the neighborhood and
the spatial smoothness of the segmentation.
Usually between 0 to 0.5
nclassesint
number of tissue classes
Returns:
PLNndarray
4D probability map of the label given the neighborhood of the
voxel.
It calculates the image intensity histogram, and based on the rate value it
decide what is the upperbound value for intensity normalization, usually
lower bound is 0. The rate is the ratio between the amount of pixels in
every bins and the bins with highest pixel amount
Parameters:
datafloat
Input intensity value data
ratefloat
representing the threshold whether a specific histogram bin that should
be count in the normalization range
This method uses the Maximum a posteriori - Markov Random Field approach for segmentation by using the Iterative Conditional Modes and Expectation Maximization to estimate the parameters.
This method uses the Maximum a posteriori - Markov Random Field
approach for segmentation by using the Iterative Conditional Modes
and Expectation Maximization to estimate the parameters.
Parameters:
imagendarray,
3D structural image.
nclassesint,
Number of desired classes.
betafloat,
Smoothing parameter, the higher this number the smoother the
output will be.
tolerance: float, optional
Value that defines the percentage of change tolerated to
prevent the ICM loop to stop. Default is 1e-05.
If you want tolerance check to be disabled put ‘tolerance = 0’.
max_iterint, optional
Fixed number of desired iterations. Default is 100.
This parameter defines the maximum number of iterations the
algorithm will perform. The loop may terminate early if the
change in energy sum between iterations falls below the
threshold defined by tolerance. However, if tolerance is
explicitly set to 0, this early stopping mechanism is disabled,
and the algorithm will run for the specified number of
iterations unless another stopping criterion is met.
Returns:
initial_segmentationndarray,
3D segmented image with all tissue types specified in nclasses.
final_segmentationndarray,
3D final refined segmentation containing all tissue types.