instance_analysis


instance_analysis takes a semantic image stack and generates an instance image stack for one semantic label at a time, as well as statistics on those instances, such as size, shape from a best-fit ellipsoid, as well as neighborhood metrics.


As opposed to semantic segmentation, which groups objects in an image based on defined categories, instance segmentation can be considered a refined version of semantic segmentation wherein individual instances are independently labelled. For example, an image can be semantically segmented to distinguish between different animals (person, sheep, or dog) in an image, while an instance segmentation will label the various individual animals in the image:

Instance analysis provides the user with various metrics for each instance of a semantic label, such as the size, shape, or orientation of each individual instance, enabling a statistical assessment of instance populations from a dataset. This is typically done on individual populations of semantic labels, so an image with multiple sheep and multiple dogs would return separate data for both the sheep and dog populations. Instance analysis on combined semantic labels would require the generation of a new semantic label (e.g. four-legged animals).

semantic_vs_instance.png

With recon3d installed in a virtual environment called .venv, the instance_analysis functionality is provided as a command line interface. Following is an example of the instance_analysis workflow. Providing a semantic image stack with labeled classes, the instances of each class and associated instance properties can be generated.

Contents of instance_analysis.yml:

cli_entry_points: - instance_analysis - image_to_voxel semantic_images_dir: tests/data/cylinder_machined_semantic # (str) path to images, e.g., /Users/chovey/recon3d/examples/fimage/ semantic_images_type: .tif # (str) .tif | .tiff options are supported semantic_imagestack_name: machined_cylinder # (str) name for the image stack class_labels: air: value: 0 instance_analysis: include: False min_feature_size: 0 metal: value: 1 instance_analysis: include: False min_feature_size: 0 pore: value: 2 instance_analysis: include: True min_feature_size: 12 voxel_size: dx: 1.0 # (float), real space units of the voxel size in x dy: 1.0 # (float), real space units of the voxel size in y dz: 1.0 # (float), real space units of the voxel size in z origin: x0: 0.0 # (float), real space units of the origin in x y0: 0.0 # (float), real space units of the origin in y z0: 0.0 # (float), real space units of the origin in z pixel_units: micron # (str), real length dimension of eacah pixel out_dir: recon3d/data/output # output path for the processed files h5_filename: cylinder_machined # output h5 file name, no extension needed

instance_analysis instance_analysis.yml produces:

Processing specification file: instance_analysis.yml Success: database created from file: instance_analysis.yml key, value, type ---, -----, ---- cli_entry_points, ['instance_analysis', 'image_to_voxel'], <class 'list'> semantic_images_dir, tests/data/cylinder_machined_semantic, <class 'str'> semantic_images_type, .tif, <class 'str'> semantic_imagestack_name, machined_cylinder, <class 'str'> class_labels, {'air': {'value': 0, 'instance_analysis': {'include': False, 'min_feature_size': 0}}, 'metal': {'value': 1, 'instance_analysis': {'include': False, 'min_feature_size': 0}}, 'pore': {'value': 2, 'instance_analysis': {'include': True, 'min_feature_size': 12}}}, <class 'dict'> voxel_size, {'dx': 1.0, 'dy': 1.0, 'dz': 1.0}, <class 'dict'> origin, {'x0': 0.0, 'y0': 0.0, 'z0': 0.0}, <class 'dict'> pixel_units, micron, <class 'str'> out_dir, recon3d/data/output, <class 'str'> h5_filename, cylinder_machined, <class 'str'>

This always outputs an hdf file. The current version of hdf file is hdf5, so file extensions will terminate in .h5. The hdf file output can be opened in HDFView.