This subfolder contains the Python port of the original MATLAB image analysis pipeline for measuring local Nd-rich spacing and orientations from micrographs. The main entrypoint is the ANALYSE_IMAGES.py script that:
- reads images,
- performs contrast enhancement & background-corrected binarisation,
- computes spacing (local mean distances) and orientations,
- computes distributions/histograms and exports results per image.
-
Image & parameters:
- Main script: ANALYSE_IMAGES.py
- Global settings: PARAMETRES.py
-
Binarisation:
- CLAHE + background correction + thresholding (Otsu or adaptive).
- Implementation:
binarisation
-
Spacing & statistics:
- Local distance map:
distance - Normalized histogram / distribution:
distribution
- Local distance map:
-
Orientation:
- Orientation/angle calculation:
calculangle
- Orientation/angle calculation:
-
Post-processing / export:
- Visualization and XLS export:
dessinexport - Grain prolongation/cleanup helpers:
prolong_nd
- Visualization and XLS export:
- ANALYSE_IMAGES.py — main orchestration script, loops samples/types/photos and calls the pipeline steps.
- PARAMETRES.py — dataset/sample parameters (ECHTS, TYPES, NBPHOTOS, etc.).
- Nd_spacing/Binarisation_methods/binarisation clahe+BGcorr+adaptive thresholding.py — detailed binarisation routine.
- distance.py — compute local mean spacing map.
- distribution.py — convert DM map into histogram classes and normalized distribution.
- calculangle.py — compute local crystal/grain orientations and class histograms.
- dessinexport.py — saves figures and XLSX results.
- prolong_nd.py — morphological helpers used for grain prolongation and cleaning.
- Install dependencies:
pip install -r requirements.txt
- Configure PARAMETRES.py for your dataset (sample names, photo counts, paths).
- Run the analyzer from the Nd_spacing folder:
(Script prints progress and writes per-image XLSX in the "Résultats" folder.)
python ANAYLSE_IMAGES.py
- Binarisation parameters (CLAHE clip_limit, tile_grid_size, blur kernel, threshold method, adaptive block_size/C) are configurable in the binarisation call made by ANALYSE_IMAGES.py.
- Distribution parameters such as
dmaxandpasdistriare imported from PARAMETRES.py and used bydistribution.
- The pipeline mirrors the original MATLAB flow (see Code_matlab_OT_original for the MATLAB reference).
- The binarisation routine applies CLAHE then optional Gaussian background estimation before thresholding.
distributioncomputes histogram class boundaries consistent with the MATLAB original.- If you want to inspect intermediate outputs, ANALYSE_IMAGES.py writes masks and labeled images (TIFF) for debugging.
This is the implementation of conditional denoising diffusion probabilistic model to generate SEM microstructure images of seen and unseen cast-forged AZ80 magnesium alloy components. The model is conditioned based on the cast geometry, casting cooling rate, soaking process, pre-forging heat treatment, forging temperature, location of extracted metallography sample, and magnification.
Please cite our paper as follows: E. Azqadan, H. Jahed, A. Arami, Predictive microstructure image generation using denoising diffusion probabilistic models, Acta Mater. 261 (2023), 119406, https://doi.org/10.1016/j.actamat.2023.119406.
The following repositories were used as inspiration for this implementation: https://github.com/dome272/Diffusion-Models-pytorch/tree/main https://github.com/lucidrains/denoising-diffusion-pytorch https://github.com/CompVis/latent-diffusion