autoemx.runners.annotate_particle_images module
Annotate the particle and frame images of a sample with the X-ray spectrum spots and the particles found.
During acquisition, particle and frame images are saved without annotations (unless
annotate_particle_images=True), while the pixel position of every spectrum spot, and
of every particle found in a frame, is stored in the sample ledger. This runner draws each
spot as a dot with its spectrum ID, and each particle found in a frame (particle size
statistics, or frames searched for EDS particles) as a circle with its particle number, as
done during acquisition, plus a scale bar when the pixel size is known.
Annotated copies are written to SEM images/annotated; the original images are not
modified.
Import this module in your own code and call annotate_particle_images(), or use the
script Annotate_Particle_Images.py.
Workflow
Loads the sample ledger and the images
SEM images/<sample>_par<N>_fr<F>_xyspots.<ext>(or<sample>_fr<F>_xyspots.<ext>for grid/linescan acquisitions).Finds the spectra acquired on each image: same particle (or same frame, for images without particle).
Draws a dot + spectrum ID at the pixel position of each spectrum, and a scale bar.
Annotates the frame images recorded in the ledger (
particle_stats,particle_stats_progress,eds_size_scans) with their particles (particle_marks_px).
Notes
The un-annotated image is used: the
<name>_raw.<ext>copy if present, or the raw page of a two-page TIFF. Images saved with annotations and without raw copy are annotated again.The pixel size used for the scale bar is read from the ledger (
image_pixel_size_umof the particle) or, for older samples and images without particle, from the image metadata. Without it, no scale bar is drawn.
Created on Mon Oct 5 2026
@author: Andrea
- autoemx.runners.annotate_particle_images.annotate_particle_images(sample_path: str | None = None, sample_ID: str | None = None, results_path: str | None = None, output_dir: str | None = None, scalebar: bool = True, overwrite: bool = True, verbose: bool = True) List[str][source]
Write copies of the particle images of a sample annotated with the X-ray spectrum spots, and of its frame images annotated with the particles found in them.
- Parameters:
sample_path (str, optional) – Full path to the sample folder (containing ledger.json).
sample_ID (str, optional) – Sample identifier, used with
results_pathwhensample_pathis not given.results_path (str, optional) – Directory under which the
sample_IDfolder is searched. Default: ./Resultsoutput_dir (str, optional) – Folder for the annotated images. Default:
SEM images/annotatedin the sample folder.scalebar (bool, optional) – Whether to draw a scale bar (when the pixel size is known). Default: True.
overwrite (bool, optional) – Whether to overwrite existing annotated images. Default: True.
verbose (bool, optional) – Whether to log progress. Default: True.
- Returns:
written – Paths of the annotated images.
- Return type:
list of str