This repository contains a set of Jupyter notebooks that implement the full pipeline for preparing graphene microscopy images and their segmentation masks, starting from raw images, through ilastik probability maps, to UNet-ready multi-label masks.
-
Image normalization
Notebook:tem_normalization_clahe_minmax.ipynb- Prepares raw microscopy images for downstream analysis.
- Includes intensity normalization (clahe, minmax)
- Ensures reproducibility and standardization of input data.
-
Probability maps post-processing
Notebook:ilastik_h5_to_mask.ipynb- Converts ilastik probability map outputs (
.h5) into binary masks. - Supports user-defined thresholds and class selection.
- Automatically scans directories for
.h5files and matching raw images. - Exports masks in PNG and NumPy (
.npy) formats. - Generates overlays and probability heatmaps for quality control.
- Converts ilastik probability map outputs (
-
Label masks post-processing (UNet dataset preparation)
Notebook:mask_postprocessing_for_unet.ipynb- Processes manually refined ilastik label exports (
*_Labels.h5). - Fills unlabeled pixels (class 0) using nearest-neighbor interpolation.
- Applies morphological smoothing to reduce edge artifacts (dilution, erosion)
- Aligns raw images with masks, builds one-hot multi-label stacks (e.g., GFM, carbonhole, undefined).
- Saves paired datasets as images (
.png) and compressed masks (.npz), ready for supervised training. - Performs sanity checks to ensure non-overlapping classes and consistent pixel counts.
- Processes manually refined ilastik label exports (
Each notebook defines its own input and output paths, but the workflow is organized around:
notebooks/— Jupyter notebooks for each stage of the pipeline.data/— raw images and intermediate outputs.masks_output/,net_input_images/,net_input_masks/— generated binary and multi-label masks.
- Python 3.8+
- Dependencies:
numpy,matplotlib,h5py,scikit-image,scipy,opencv-python,Pillow
Open each notebook in sequence to reproduce the workflow:
- Run image normalization.
- Run probability maps post-processing for ilastik
.h5outputs. - Run label masks post-processing for refined labels and dataset preparation.
This pipeline ensures reproducibility, cleanliness, and quality control in preparing microscopy image datasets for deep learning applications.