pysilcam.process module

pysilcam.process.clean_bw(imbw, min_area)

cleans up particles which are too small and particles touching the border

Parameters
  • imbw – segmented image

  • min_area – minimum number of accepted pixels for a particle

Returns

cleaned up segmented image

Return type

imbw (DataFrame)

pysilcam.process.concentration_check(imbw, settings)

Check saturation level of the sample volume by comparing area of particles with settings.Process.max_coverage

Parameters
  • imbw – segmented image

  • settings – PySilCam settings

Returns

boolean on if the saturation is acceptable. True if the image is acceptable saturation : percentage of maximum acceptable saturation defined in

settings.Process.max_coverage

Return type

sat_check

pysilcam.process.extract_particles(imc, timestamp, settings, nnmodel, class_labels, region_properties)
extracts the particles to build stats and export particle rois to HDF5 files writted to disc in the location of

settings.ExportParticles.outputpath

Parameters
  • imc – background-corrected image

  • timestamp – timestamp of image collection

  • settings – PySilCam settings

  • nnmodel – loaded tensorflow model from silcam_classify

  • class_labels – lables of particle classes in tensorflow model

  • region_properties – region properties object returned from regionprops (measure.regionprops(iml, cache=False))

Returns

(list of particle statistics for every particle, according to Partstats class)

Return type

stats

@todo clean up all the unnesessary conditional statements in this

pysilcam.process.extract_roi(im, bbox)

given an image (im) and bounding box (bbox), this will return the roi

Parameters
  • im – any image, such as background-corrected image (imc)

  • bbox – bounding box from regionprops [r1, c1, r2, c2]

Returns

image cropped to region of interest

Return type

roi

pysilcam.process.fancy_props(iml, imc, timestamp, settings, nnmodel, class_labels)

Calculates fancy particle properties

Parameters
  • iml – labelled segmented image

  • imc – background-corrected image

  • timestamp – timestamp of image collection

  • settings – PySilCam settings

  • nnmodel – loaded tensorflow model from silcam_classify

  • class_labels – lables of particle classes in tensorflow model

Returns

particle statistics

Return type

stats

pysilcam.process.filter_bad_stats(stats, settings)

remove unacceptable particles from the stats

Note that for oil and gas analysis, this filtering is handled by the functions in the pysilcam.oilgas module.

Parameters
  • stats (DataFrame) – particle statistics from silcam process

  • settings (PySilcamSettings) – settings associated with the data, loaded with PySilcamSettings

Returns

particle statistics from silcam process

Return type

stats (DataFrame)

pysilcam.process.get_spine_length(imbw)

extracts the spine length of particles from a binary particle image (imbw is a binary roi)

Parameters

imbw – segmented particle ROI (assumes only one particle)

Returns

spine length of particle (in pixels)

Return type

spine_length

pysilcam.process.image2blackwhite_accurate(imc, greythresh)

converts corrected image (imc) to a binary image using greythresh as the threshold value (some auto-scaling of greythresh is done inside)

Parameters
  • imc – background-corrected image

  • greythresh – threshold multiplier (greythresh is multiplied by 50th percentile of the image histogram)

Returns

segmented image (binary image)

Return type

imbw

pysilcam.process.image2blackwhite_fast(imc, greythresh)

converts corrected image (imc) to a binary image using greythresh as the threshold value (fixed scaling of greythresh is done inside)

Parameters
  • imc – background-corrected image

  • greythresh – threshold multiplier (greythresh is multiplied by 50th percentile of the image histogram)

Returns

segmented image (binary image)

Return type

imbw

pysilcam.process.measure_particles(imbw, imc, settings, timestamp, nnmodel, class_labels)

Measures properties of particles

Parameters
  • imbw (full-frame binary image) –

  • imc (full-frame corrected raw image) –

  • image_index (some sort of tag for location matching) –

Returns

stats (list of particle statistics for every particle, according to Partstats class)

pysilcam.process.processImage(nnmodel, class_labels, image, settings, logger, gui)

Proceses an image

Parameters
  • nnmodel (tensorflow model object) – loaded using sccl.load_model()

  • class_labels (str) – loaded using sccl.load_model()

  • image (tuple) – tuple contianing (i, timestamp, imc) where i is an int referring to the image number timestamp is the image timestamp obtained from passing the filename imc is the background-corrected image obtained using the backgrounder generator

  • settings (PySilcamSettings) – Settings read from a .ini file

  • logger (logger object) – logger object created using configure_logger()

  • gui=None (Class object) – Queue used to pass information between process thread and GUI initialised in ProcThread within guicals.py

Returns

stats dataframe containing particle statistics

Return type

stats_all (DataFrame)

pysilcam.process.statextract(imc, settings, timestamp, nnmodel, class_labels)

extracts statistics of particles in imc (raw corrected image)

Parameters
  • imc – background-corrected image

  • timestamp – timestamp of image collection

  • settings – PySilCam settings

  • nnmodel – loaded tensorflow model from silcam_classify

  • class_labels – lables of particle classes in tensorflow model

Returns

(list of particle statistics for every particle, according to Partstats class) imbw : segmented image saturation : percentage saturation of image

Return type

stats

pysilcam.process.write_segmented_images(imbw, imc, settings, timestamp)

writes binary images as bmp files to the same place as hdf5 files if loglevel is in DEBUG mode Useful for checking threshold and segmentation

Parameters
  • imbw – segmented image

  • settings – PySilCam settings

  • timestamp – timestamp of image collection

pysilcam.process.write_stats(datafilename, stats_all, append=True, export_name_len=40)

Writes particle stats into the ouput file

Parameters
  • datafilename (str) – filame prefix for -STATS.h5 file that may or may not include a path

  • stats_all (DataFrame) – stats dataframe returned from processImage()

  • append (bool) – if to allow append

  • export_name_len (int) – max number of chars allowed for col ‘export name’