Skip to main content

Image segmentation of building material surfaces using deep learning (CrackPy)

This package is dedicated to segment cracks, matrix and pores in testing specimens of different building materials. The project was developed under the ressearch project of Grant Agency of Czech Republic No. 22-02098S with title: "Experimental analysis of the shrinkage, creep and cracking mechanism of the materials based on the alkali-activated slag".

DOI

Please cite our research paper when using CrackenPy in your research project: R. Dvořák, V. Bílek, D. Lisztwan, P. Nápravník, R. Krč, B. Kucharczyková, Quantitative multi-class crack analysis in cementitious materials using convolutional neural networks, Measurement 295 (2027) 123831, doi:10.1016/j.measurement.2026.123831. The sidebar button "Cite this repository" gives the same reference.

The videos documenting the source training images are represented via videos on youtube playlist Cracks in alkali activated binders.

Features

Image segmentation of given surface of the test specimen. The photo of the specimen must have minimum resolution of 416 $\times$ 416 pixels. The specimens should be placed on close-to-black background. The surface plane of the specimen should be parallel to the objective, to have minimal lens distortion. It is possible to give the main axis dimensions of the speicmens to calculate pixels to mm ratio. The CrackPy package is able do generate mask with classes "background", "matrix", "cracks" and "pores". On these classes the CrackPy package introduce couple of metrics, which are the intersection of practises in image processing regarding the evaluation of building materials in the current state of the art. The most basic metrics are:

  • edge_per_node
  • crack_tot_length
  • average_angle
  • spec_area
  • mat_area
  • crack_ratio
  • crack_length
  • crack_thickness
  • pore_area
  • avg_pore_distance
  • avg_pore_size

Tese metrics can be observed all at once, or just some of the metrics can be picked. If the time evolution of one speicmen is adressed the acquring of the metrics can be optimilized, to focus only for the metrics important for the given experiment.

The instalation of the package (private package)

The package works optimal with NVIDIA GPU together with installed CUDA 11.8 or newer. It was also tested on mac OS using MPS backend. The package was tested in Google Colab.

pip install crackenpy

The basic usage of the package

from crackest.cracks import CrackPy
 
#%Model 1 optimized also for pores
#Model 0 is optimized for fine cracks
cp=CrackPy(model=1) #

#Read a file from examples
imfile=r'Examples\Img\ID14_940_Image.png' 
cp.get_mask(imfile)

#Plot the example
cp.overlay()

After instance initilaization, a pre-trained model is downloaded from HuggingFace repository, the model is stored in package folder for models. If the the NVIDIA GPU and CUDA toolkit is installed it will use cuda for segmentation. It can also use MPS backend on Apple Sillicon M1-M3 chips. The CrackenPy has basically two ways of use. Either on single image, where a specimen on dark background is placed, or on set of images.

Width-bias correction

A validation of the width measurement against 853 manual crack-width measurements (Dvořák et al., Measurement 295, 2027, 123831) showed that the predicted crack masks are systematically wider than the annotated reference by ≈ +1 px of full width (a one-pixel boundary rim). Since the bias is systematic, it can be subtracted from the mean crack thickness; this removes the 10–12 % relative overestimation of fine cracks near the ≈ 2.5 px quantification limit while leaving wide cracks essentially unchanged. The correction is off by default (backward compatible) and is enabled with:

cp.set_width_bias(1.0)        # full-width bias in px (1.0 = characterized value for the bundled model)
metrics = cp.get_metrics()    # crack_thickness is now bias-corrected

# or per call:
metrics = cp.get_metrics(width_bias_px=1.0)

The applied value is recorded in the returned metrics as width_bias_px. Note the correction is characterized for the bundled model and the annotation convention of its training data; for custom models, characterize the bias with your own reference measurements before enabling it.

Single image

The basic usage is t osegment the whole image, and all metrics and masks will represent the whole image. This can be done, if the whole image is either filled with specimen, or if on the image is only the 1 specimen. In both cases all metrics connected to the matrix of binder, cracks and pores are assessed as 1 body / specimen.

If there is multiple speicmens on 1 image, then the Cracken should be used.

Multiple images

In this scenario on the image multiple specimens are present. In this case it is nessessary which specimen should be assessed. For this a Cracken class is designed. At first it masks the whole image, and then using skimage library segment it into regions. The specimen mask is created out of inverse background mask, therefore it allows to have cracks which are going straight thgough the specimens, and the speicmen is still recognized. Otherwise, the segmentation would returned two different specimens, even tho they would be one body. It will create a set of operations neded to crop and rotate each specimen by its longer axis. The current state of the library takes into account the fact that the photos are taken perpendicular to the base on which the bodies under consideration are placed. Each specimen is given an ID, and allows to retrive the mask and image in stabilized state.

The library is build to assess change in time of specimens, which are placed on fixed position in scene and are not moved throught the whole image acquistion period. The original aim is to monitorthe long term changes on multiple specimens. After the first registr of specimens, the segmentation is then always done on croped and stabilized version of image filled with the sample with adjustable frame around it. This saves time and allows to osberve also volumetric changes (expansion, shrinkage).

from crackest.crack_analyzer import CrackAn

ca=CrackAn()
ca.input(file=r"Examples\Img\256_Image_29-01-2022 02-36-02.png")
ca.registr()
ca.preview()

Both CrackPy and SubSpecies class inherit plotting methods from class CrackPlot, so it is possible to use same plotting functions for both cases.

spec=ca.get_spec(specid=0,frame=50)
spec.overlay()

The same apply for the CrackAnalyzer, which is generating metrics out of image and its segmented mask. By this a development of metrics can be generated if the folder is given to CrackAn instead of single file. The segmentation in registr method is currently using the same model for recognizing how many specimens is on the image, as well for the segmnetation itself, so for the experiments it is recomended to keep the speicmens still on same spot. Otherwise it would need to segment whole image every time.

Future plans

The current library is designed for laboratory enviroment, where every possible of binder can be placed (cement, geopolymers, alkali activated systems) and it should be able to segment cracks, matrix, pores and background. This is intented use, however the crack variety and vast brightness and texture allow to design in general accurate and reliable deep learning aplication for crack segmentation in different type of mediums.

  • Segmentation using photogrammetry (basicly running CrackenPy on UV textures of generated 3D models)
  • Segmentation on videos (using less power demanding models to process bigger volumes of data)
  • Connecting the image with BIM metadata for structure surveing (for infrastructre isnepctions)

Acknowledgment

This package was written under the Czech Science Foundation, grant number 22-02098S, project title „Experimental analysis of the shrinkage, creep and cracking mechanism of the materials based on the alkali-activated slag“.

Please cite our work

The research paper describing the toolkit, the dataset and the validation of the measurement (preferred citation):

@article{Dvorak_2027_CrackenPy,
	author       = {Dvo{\v{r}}{\'a}k, Richard and B{\'i}lek, Vlastimil and Lisztwan, Dominik and N{\'a}pravn{\'i}k, Petr and Kr{\v{c}}, Rostislav and Kucharczykov{\'a}, Barbara},
	title        = {Quantitative multi-class crack analysis in cementitious materials using convolutional neural networks},
	journal      = {Measurement},
	volume       = {295},
	pages        = {123831},
	year         = {2027},
	issn         = {0263-2241},
	doi          = {10.1016/j.measurement.2026.123831},
	url          = {https://doi.org/10.1016/j.measurement.2026.123831}
}

The model, the library and the dataset:

@misc {richard_dvorak_2024_model,
	author       = { {Richard Dvorak} },
	title        = { crackenpy (Revision 04ed02c) },
	year         = 2024,
	url          = { https://huggingface.co/rievil/crackenpy },
	doi          = { 10.57967/hf/3295 },
	publisher    = { Hugging Face }
}

@software {Dvorak_CrackenPy_Image_segmentation_2024,
	author       = {Dvorak, Richard and Bilek, Vlastimil and Krc, Rostislav and Kucharczykova, Barbara},
	doi          = {10.5281/zenodo.13969747},
	month        = oct,
	title        = {{CrackenPy: Image segmentation tool for semantic segmentation of building material surfaces using deep learning}},
	url          = {https://github.com/Rievil/CrackenPy},
	year         = {2024}
}

@misc {richard_dvorak_2024_dataset,
	author       = { {Richard Dvorak} },
	title        = { crackenpy_dataset (Revision ce5c857) },
	year         = 2024,
	url          = { https://huggingface.co/datasets/rievil/crackenpy_dataset },
	doi          = { 10.57967/hf/3496 },
	publisher    = { Hugging Face }
}

Metadata

Release files for crackenpy 0.1.87

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crackenpy 0.1.87
File Size Uploaded Provenance Actions
crackenpy-0.1.87.tar.gz 20.8 kB With provenance Details for crackenpy-0.1.87.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for crackenpy 0.1.87
File Interpreter ABI Platform Actions
crackenpy-0.1.87-py3-none-any.whl Python 3 none any Details for crackenpy-0.1.87-py3-none-any.whl

Total release size: 43.8 kB

Release files / crackenpy-0.1.87.tar.gz

Download URL crackenpy-0.1.87.tar.gz
Size 20.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0cd24422ceeaedf3bde37907f1c2191bcb07696730896d87daf5170534cbfadc
BLAKE2b-256 checksum
How to use checksums
8f403ed107265a727d47ea8a29025de18e4124ab9f4a87dba7ec9d7f7c153773
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / crackenpy-0.1.87-py3-none-any.whl

Download URL crackenpy-0.1.87-py3-none-any.whl
Size 23.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e17e54db1f55eb5077844b461ce68228d6dcd4187e99e648d95515fe5eba0cf
BLAKE2b-256 checksum
How to use checksums
9a930f0407956f029093d6570a85d5580234c937ea80ea622abcf692c20ce895
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for crackenpy 0.1.87

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for crackenpy-0.1.87.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page