pre_post_processing

Segment_Analyser

author: Richard Bonye (github Boyne272) Last updated on Wed Aug 28 08:36:46 2019

class TSA.pre_post_processing.Segment_Analyser.Segment_Analyser(img, mask, clusters)

Takes in a segmentation and its clustering. Gets user inputs to label each cluster. Then the appropirate distriubtions of the labelled clusters are calculated.

Segment_Analyser(img, mask, clusters)

Parameters:
  • img (2d or 3d numpy array) – An rgb, rgba, or grey scale array of the image. Used for visulisation only
  • mask (2d numpy array) – Segmentation mask for analysing distibuions
  • clusters (2d numpy array) – Clustering mask for identifying different materials
get_composition(return_arr=False)

Plots a bar graph of fractional composition for each label.

These vaues are also printed in a table.

If return_arr is true then a 1d relative compositions array is returned.

get_grain_count(return_arr=False)

Plots the number of segments in each cluster on a bar graph.

These vaues are also printed in a table.

If return_arr is true then a 1d grain count array is returned.

get_gsd(label, span=True, return_arr=False)

Plots the distribution of segment areas, perimeters and the ratio of the two (i.e. the grain size distribution) of the cluster with the given label.

If span is True this will also plot the span of this clusters segments (can be lengthy calculation).

If return_arr is true then a 2d array array is returned with (size, perimeter, ratio) on the first axis and segment on the second.

plot_cluster(label, ax=None)

Plot the original image and mask all but the cluster with the given label. Plots on ax if given.

plot_clusters()

Plots the indevidual clusters via plot_cluster for every cluster present.

set_labels()

Prompt the user for every cluster to give label for it. If the same label is given twice these clusters are merged.

Image_processor

author: Richard Bonye (github Boyne272) Last updated on Wed Aug 28 08:28:51 2019

class TSA.pre_post_processing.Image_processor.Image_processor(path='', img=array([], dtype=float64))

A class to wrap all image filtering and preprocessing. All functions are wrapped around skimage. Use path to load an image from file or img to load from an array.

Image_processor(path=’‘, img=np.array([])

Images are stored in an internal dictionarry ‘imgs’. The ‘curr’ entry is where all filters are applied and the key passed to every method is where to store the resultant image. This way many filters can be stacked together in ‘curr’ until the final image is stored seperatly under a provided key.

canny(key='curr')

Apply canny edge detection routine on a single channel image

dilation(key='curr', size=3)

Apply dilation on a grey scale image

erosion(key='curr', size=3)

Apply errosion on a grey scale image

gabor_filters(frequency, n_angs, key='curr')

Apply gabor filters of the given frequency and n_angles unfiormly distibuted between [0, 180] deg. All the angles are average to give a single channel output.

gauss(sigma=1, key='curr')

Apply guassian blur with sigma standard deviation on a multi-channel image

gauss_grey(sigma=1, key='curr')

Apply guassian blur with sigma standard deviation on a single-channel image (i.e. grey scale image)

grey_scale(key='curr')

Convert an RGB image to grey scale (single channel)

hog(key='curr')

Apply histogram of gradients to either single or multi-channel images

hsv(key='curr')

Convert an RGB image to hsv scale (both 2 channel)

laplace(size=3, key='curr')

Apply laplace gradient filters of the given size on single or multi-chanel images

lbp(radius=3, method='uniform', key='curr')

Apply local binary pattern over a square region of the given radius to a grey scale image

median(key='curr', **kwargs)

Apply a median filter on a single channel image with addtitonal kwargs passed to skimage.filters.median

normalise(key='curr', std=1.0)

Take single channel image and normalise it to have mean=0, given std

plot(key='curr', ax=None)

Plot an image

prewitt(key='curr')

Apply prewitt edge detection routine on a single channel image

rebase()

mask the working image the new base

reset(key='original')

Reset the working image with the given key

save(path, key='curr')

save the given key on the given path

scharr(key='curr')

Apply scharr edge detection filters on a multi-channel image.

select_channel(channel, key='curr')

Take a single channel of a multi-channel image

sobel(key='curr')

Apply sobel edge detection filters on a multi-channel image.

store(array, key)

add a given array to the imgs

threshold(value, key='curr')

threshold a single channel image to give a binary image