2D Granulometry & Grain segmentation module
The 2D Granulometry [1] module is designed to detect, separate, and analyze grains in 2D. It is accessible via one dedicated button, inside the menu bar of IPSDK Explorer.
Input selection
The module window contains a dropdown menu at the top left corner to select an input image to process. Both grayscale and RGB formats are supported, for individual 2D images or sequences of 2D images.
- Note
- Input images must be loaded inside IPSDK Explorer to be selected inside the dropdown list.
Configuration management
The second dropdown menu appearing on the right corner allows to choose and reload previously saved configurations. The special entry "..." refers to the last auto-saved configuration made during the last preview.
The button
applies the settings to the different processing sections, while the
delete the current setting selected in the list.
The button
at the top right corner, resets all the settings to default values.
The checkbox Keep images for next process is an optional setting that allows to save processed images for the next process, and therefore gain some time during computations. When this option is checked, images will be saved everytime a preview is done, reducing redundant computations.
To save the current configuration :
- Enter a name for the parameter set, on the entry field at the bottom left corner,
Click the
button to save the current configuration.
Processing sections
The core of the plugin window includes seven distinct and collapsible sections :
- Pre process,
- Binarization,
- Morphological operations,
- Separation,
- Post process,
- Measures,
- Output images.
Module Section Structure
Each processing section is made up of individual functions.
Each line is described as follows :
- The method name or operation type appears on the left,
- The parameters are displayed in the middle,
- A checkbox on the right allows to enable or disable the function,
An
button at the far right displays a preview of the function’s effect inside IPSDK Explorer's viewer.
Here is an example with the pre process section :
Pre Process
This section is intended to enhance image quality before grain detection.
It includes:
- Color Mode : Selects a specific color channel (for grayscale or color-based processing).
- Filters : Used to denoise or smooth the image.
- Smart Shading Correction : Corrects and normalizes grayscale intensity variations.
- Remove Points : Removes bright or/and dark artifacts caused by acquisition noise (e.g., dust or uneven lighting).
Here's an example of pre processing :
Pre process of a color image by extracting the Red channel, applying a median of size 1, and removing dark and light points.
Binarization
This step converts the pre-processed image into a binary mask highlighting the grains.
This section includes 5 thresholding methods, with 3 classical algorithms :
And also two advanced options :
- Smart segmentation model,
- Macro-based binarization.
Parameters vary depending on the chosen method. The documentation of each function is accessible through Explorer function sections, using the
button.
Here is an example of a binarization using the Otsu method :
Binarization of grains using the Otsu light type method.
When using the smart segmentation method, a pre-trained model is needed. The documentation shows how to build a smart segmentation model here.
The smart segmentation option allows to select a pre-trained model and to choose the model classes to use for the binarization.
- Note
- The trained model relies on the pre-processed image as input; therefore, any changes to the pre-processing steps afterward may cause the model to malfunction or deliver inaccurate results.
The
button can be used to refresh the models list, in case the model doesn't appear in the list.
Here is an example of binarization using the smart segmentation method :
Besides the smart segmentation algorithm, the macro-based binarization can be usefull for very complex images binarization.
The previous example shows that the binarization isn't perfect with a multitude of holes inside the objects. To improve the binary image we can use morphological operations.
Morphological Operations
Morphological operations refine the binary image by cleaning up artifacts and enhancing the separation of grains.
Available operations are :
- Fill Holes, with 2 functions to removes holes with a given size.
- Closing, a function that connects nearby objects or small discontinuities, and fills small holes or gaps within objects.
- Opening, a function that smooths object contours by eliminating small protrusions or spikes, removing small objects or details in the process, but usefull to preserve the general shape of larger objects.
Each operation is optional and configurable.
Here's an example of holes removal using the morphological operations inside the module :
Separation
Grain segmentation is performed here to label individual grains for further analysis.
Three different segmentation methods are available :
- Classic watershed : based on distance map computation and watershed algorithms [2], allows to separate objects with similar sizes and with rather circular shapes,
- Adaptive watershed : allows to separate more complex objects with various sizes and shapes,
- Connected components : detects connected regions in binary images, depending on the neighboring and assigns each as a label.
Only one method can be selected at a time.
Grain separation using the classic watershed algorithm
Post Process
Additional cleaning of the labeled result can be performed here using a set of post-processing tools.
This section implements 4 different methods :
- The Border kill method, that removes objects touching the borders of the image.
- The Fill holes method, that fills holes inside a label.
- The remove small shapes method, that removes shapes depending on a unit and a given size (depends on the image calibration).
- The remove big shapes method, that removes the largest shapes in the image.
Here is an example of post process :
Post process of a label image using the fill holes method, the border kill method and the remove small shapes method
Measures
This section provides quantitative analysis of the segmented grains.
It is divided in two different parts :
- A list of measures on the right pane,
- A list of selected measures on the left pane.
Measures selection
The right pane lists all available measurements.
Measures are separated in 2 different categories and again in multiple sub-categories
- Click the arrow to collapses a category,
Click the
button to add a measurement to the left pane,
Click the
button to remove it.
The preview button gives a peak of the results inside IPSDK Explorer.
Selected measures
Once a measure is added, it appear on the left side with the possibility to compute two different histograms by clicking the checkboxes.
- For each measurement added, it is possible to compute :
- an histogram,
- a cumulative histogram.
- You can also select a sieve (via dropdown) to define histogram bins.
Or remove a measure using the
button.
Sieves can be customized under Settings → Sieves → Preferences.
Sieves can be created and edited inside the sieves edition window
Output Images
This section defines the type of output results (label images, binary masks, overlays, etc.) to compute and save.
- Label image result returns a label image of the segmented grains,
- Color image result returns the label image as a RGB image,
- Merge input and color image result returns the input image blended with the label image in overlay,
- The blending ratio can be changed. Its value is defined between 0 and 1.
- Input image with contours result returns the input image blended with the contours of the labels in overlay.
- The contour size can be changed.
Saving and Launching Analyses
At the bottom right, three buttons control the execution of the analyses :
: launches the analysis and displays the result in Explorer (no saving).
: executes the analysis and saves the results.
: applies the analysis to a batch of images.
The
button shows the python code for the current analysis pipeline.
References
[1] https://en.wikipedia.org/wiki/Granulometry
[2] https://en.wikipedia.org/wiki/Watershed_(image_processing)