Image processing module¶

class
app.imgprocessing.segmentation.
Segmentation
[source]¶ This class provides the methods to reduce and segment the images of the toy model. It assumes that the set of Dicom files that represents the toy model have been tranformed in an array of numpy.

reduction
(img, factor=0.2222222222222222)[source]¶ This method reduces the set of images of the toymodel by a given scale factor or zoom factor, using the CSpline algorithm which is provided by the ndimage module of scipy
CSpline algorithm consists in funding a function which is the linear combination of piecewise definened functions known as Basis Splines (BSplines), which are smooth functions whose first, second and third derivative pass through one point of the given discrete set:
The linear combination of the BSpline functions can be expressed by the next equation:
Parameters:  img (3d numpy array) – representation of the toy model
 factor (float) – zoom factor in which the image is reduced
Returns: the image rescaled
Return type: 3d numpy array

view
(original, segmented, reduced)[source]¶ This method is implemented for test purposes, it takes as arguments an untreated slice, a segmented slice and a reduced and segmented slice showing its differences on screen using a matplotlib figure
view(original, segmented, reduced)

histogram
(img_red)[source]¶ Plots an histogram of the materials distibution over the toy model using matplotlib. It is neccesary to reduce the toy model before plotting the histogram. For test porpuses
histogram(reduced_toymodel)

clasify
(img, normalize=True, n_clusters=3)[source]¶ This method segments or clasify the values of the given image in three different groups of values, thus the different Hounsfield unit values found in the image are replaced by only three different values. If the parameter normalize is true, these values are:
 0 for the airvoid
 1 for the mastic
 2 for the aggregates
For this porpuse, a implementation of the Kmeans algorithm, provided by the cluster module of the Scikitlearn library, is used. Kmeans algorithm takes a dataset X of N values, and a parameter K specifies how many cluster to create. Kmeans finds evenlyspaced sets of points in subsets of Euclidean spaces called Voronoi diagrams. Each found partitions will be a uniformly shaped region called Voronoi cell, one for each material. This process is executed in two steps:
The assign step consists in calculating a Voronoi diagram having a set of centroids . The clusters are updated to contain the closest points in distance to each centroid as it is described by the equation:
The upadate step, given a set of clusters, recalculates the centroids as the means of all points belonging to a cluster:
The kmeans algorithm loops through the two previous steps until the assignments of clusters and centroids no longer change. The convergence is guaranteed but the solution might be a local minimum as shown in the next equation:
Parameters:  img (2d numpy array) – a slice of the toy model
 = 3 # number of clusters (n_clusters) – void, aggregate and mastic
:type int :param boolean normalize: If it is true, the segmentation mark the three
group of values as 0, 1 and 2. If it is false, the marks are the default values generated by kmeans.Returns: the image segmented, with only three different possible values Return type: 3d numpy array

segment_all_samples
(samples)[source]¶ Take the given samples, uses KMeans algorithm with each sample slice and returns all the segmented samples. it also cuts irrelevant data corresponding to voids outside of the lenth of the radius of the toymodel
Parameters: samples (list of 2d numpy arrays) – the set of slices of the toy model Returns: the toy model with its materials classified in airvoids, mastic and aggregates. Return type: list of 2d numpy arrays


app.imgprocessing.slice_mask.
sector_mask
(shape, centre=(50, 50), radius=50, angle_range=(0, 360))[source]¶ This method provides a circular mask over a numpy array (image), its purpose is to differentiate the air void pixels within the cylindrical toymodel from the air void space outward.
Parameters:  shape (twodimensional tuple of integers) – shape of the image
 centre (twodimensional tuple of integers) – point from where the circular mask is applied
 radius (float) – length of the radius for the circular mask
 angle_range (twodimensional tuple of integers) – circular sector where the mask is applied, the whole circle by default
Returns: mask for a circular sector
Return type: 2d boolean numpy array