Skip to main content

A stereological analysis tool for porous materials

Project description

GAKTpore: Stereological Characterisation Methods

Installation

To install the package from PyPi:

$ pip install GAKTpore

Quick Use

GAKTpore is distributed with a function utilising the GAKTpore 'AnalysePores' class to output the relevant data files into a save folder and generate a colour map. This outputs the data used for the initial GAKTpore paper. Test-case files are included on Github, with images.

The syntax of the function are as follows:

GAKTpore.analysis.run

Parameters

       IMAGE_NAME: str,

             The directory path for the image to be analysed. The image is expected to be grayscale. The image formats supported can be found on the OpenCV imread reference.

       SAVE_FOLDER: str,

             The directory where the output files will be saved to. There are 3 output files by default:

  • A file containing the standard evaluation parameters (such as mean diameter, number of samples etc.) per radial step.
  • A file containing the standard evaluation parameters (such as pore area, cirularity etc.) for each pore, allowing further analysis.
  • The Area fraction image generated using the 'jet' colourmap via Matplotlib.

The filename will be determined by the name of the image file and input parameters (Threshold, upscale multiplier, contour filtering method (FFT or Savgol) and the data) as <Image name>-<Threshold>-<Upscale Multiplier>-<type of data>_<filtering method>.<file type>, for example 'Test1-127-1x_FFT.csv'.

       THRES: int,

             The binarisation integer, expected to be between 0-255.

       SCALE: float,

             Distance per pixel, presumed to be taken from the 'scale' bar of a microstructure image.

       UPSCALE_MULTIPLIER: int, Optional. Default Value = 1

             The number to upscale the image being processed. Will multiply the image resulution by the value given.

       W_BG: bool, Optional. Default Value = True,

             Whether the background of the image is white (True) or black (False).

       FFT: bool, Optional. Default Value = True,

             Whether to use FFT bandpass to smooth contours. Setting this to False will use the Savgol Filter from Scipy instead (Not validated yet, but much faster).

       parallel: bool, Optional. Default Value = True,

             Whether to use multiple cpu cores to process the image in parallel.

       cpu_count: int, Optional. Default Value = -1,

             The number of parallel computations used when a multiprocessing function is used. -1 to use the number of available cores.

       npy_save: bool, Optional. Default Value = False,

             Whether to save the numpy array of the territory map. This map is a mask containing integers, where the integers refer to the pore number the territory belongs to.

       plt_save: bool, Optional. Default Value = False,

             Whether to use matplotlib.save to save the area fraction image. Matplotlib.save is slow and will crash when using extremely high resolution images (> 25k x 25k), but is otherwise stable. If set to false, will use cv2.imsave to save the area fraction image.

       draw_contours: bool, Optional. Default Value=True,

             Whether to draw the pores onto the map in black.

       vmin: float, Optional. Default Value=0,

             For the area fraction colour map, sets the minimum value to correspond with starting colour of the colour map.

       vmax: float, Optional. Default Value=1,

             For the area fraction colour map, sets the maximum value to correspond with final colour of the colour map.

       radii_n: int, Optional. Default Value=10

             Number of segmented steps to use between the centre of the image and the maximum radius.

Usage

GAKTpore provides a class 'AnalysePores' with multiple analytical tools.

GAKTpore.AnalysePores

The initialisation for the class works as a simple binarisation and pore detection tool utilising the OpenCV implementation of findContours.

Parameters:

       img: np.array,

             2D Grayscale Image

       threshold_value: int, Optional. Default Value: 125

             Threshold value for binarising the image

       scale = float, Optional. Default Value: 1

             Distance per pixel, presumed to be taken from the 'scale' bar of a microstructure image.

       G = bool, Optional. Default Value:False

             Whether to apply a Gaussian filter of sigma=2

       white_background= bool, Optional. Default Value: True

             Whether the background of the image is white (True) or black (False)

       cpu_count= int, Optional. Default Value:-1

             The number of parallel computations used when a multiprocessing function is used. -1 to use the number of available cores.

GAKTpore.AnalysePores.process

The next major function is process (process_parallel for the multiprocessing version). This function computes the properties of the pores (Area, Circularity etc.). Note that this must be run before the territory areas can be calculated.

Parameters:

       FFT: bool, Optional. Default Value: True

             Whether to use FFT bandpass to smooth contours. Setting this to False will use the Savgol Filter from Scipy instead (Not validated yet, but much faster).

GAKTpore.AnalysePores.process_free_area

This function (and its parallel counterpart, process_free_area_parallel) calculates the territory area for each pore by computing the closest pore contour for each pixel of the image provided.

Parameters:

       zoom: int, Optional. Default Value: 1

             Increase the resolution of the map used for computing the territory area. Example: zoom=2 will use double the resolution of the input image to calculate the territory area.

GAKTpore.AnalysePores.process_homogeneity_colour_map

This function (and its parallel counterpart, process_homogeneity_colour_map_parallel) generates a colour map using the area fractions (Pore area divided by Territory area).

Parameters:

       mapper: matplotlib.colors.LinearSegmentedColormap, Optional. Default Value: matplotlib.cm.get_cmap("jet")

             Sets the colourmap to be used when colouring the image. Uses the colour "jet" by default. Provided in this layout to support custom matplotlib maps.

       vmin: float, Optional. Default Value: 0

             Sets the minimum value to correspond with starting colour of the colour map.

       vmax: float, Optional. Default Value: 1

             Sets the maximum value to correspond with final colour of the colour map.

       draw_contours: bool, Optional. Default Value: False

             Whether to draw the pores onto the map.

Returns:

       Colour map of the same resolution as the one in process_free_area.

GAKTpore.AnalysePores.process_radial_contour:

Computes the number of pores and the porosity percentage in segmented steps from the centre of the image.

Parameters:

       radii_n: int, Optional. Default Value: 10

             Number of segmented steps to use between the centre and the maximum radius.

       radius_centre: np.array, Optional. Default Value: None

             The pixel position to use as the centre for the segmented circle. If not supplied, simply takes the centre of the image.

       radius_max: float, Optional. Default Value: None

             The maximum radius to do the calculations for. If not supplied, simply calculates the distance to edge of the image from the centre.

       draw_contours: bool, Optional. Default Value: False

             Whether to draw the pores onto the map.

Citation

When using this package please cite:

  • Sheppard, G. and Tassenberg, K. et al. GAKTpore: Stereological Characterisation Methods for Porous Foams in Biomedical Applications, Materials 2021, MDPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

GAKTpore-1.1.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

GAKTpore-1.1-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file GAKTpore-1.1.tar.gz.

File metadata

  • Download URL: GAKTpore-1.1.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

File hashes

Hashes for GAKTpore-1.1.tar.gz
Algorithm Hash digest
SHA256 0c9d66520e513a47270efa79845537a7d2c5afd6e074fba1c94cf5e697f7210a
MD5 4facfefc9ebdc410298c86ad151284ba
BLAKE2b-256 e67d4607dc8ace367fc50c4d1e94bcb48c09911519ec4c290d6b8fa043114ae9

See more details on using hashes here.

File details

Details for the file GAKTpore-1.1-py3-none-any.whl.

File metadata

  • Download URL: GAKTpore-1.1-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

File hashes

Hashes for GAKTpore-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6a30734bf6eeb9d60d9f9882e16b579236647b29d858ab329caaf7fc2240e526
MD5 cbe37e05134ee0add0b7f1b816e4be16
BLAKE2b-256 eb4b3ac6f1bbb69cc7e9408fe2d751125483913f78dcb2525b68bc73d0596434

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page