playnano.io.image_sequence_export module¶
Export AFM image stacks as a folder of annotated PNG or JPEG images, one per frame.
Frames are coloured and annotated by playnano.io.render_utils, which the
GIF and video exports share, and written with Pillow.
- playnano.io.image_sequence_export.create_image_sequence(image_stack: ndarray, pixel_sizes_nm: list, timestamps=None, scale_bar_length_nm: int = 100, output_folder: str | Path = 'output_frames', base_name: str = 'frame', fmt: str = 'png', cmap_name: str = 'afm_brown', zmin: float | str | None = None, zmax: float | str | None = None, draw_ts: bool = True, draw_scale: bool = True, font_scale: float = 2.0) Path[source]¶
Write each frame of an image stack as an image file, with optional annotations.
Files are named
<base_name>_<n>.<ext>, wherenis the frame index from 0, padded with zeros to at least 4 digits so they sort in order. Useexport_image_sequence()to export anAFMImageStack.- Parameters:
image_stack (numpy.ndarray) – 3D image stack of shape (n_frames, height, width).
pixel_sizes_nm (list of float) – Pixel size of each frame, in nm. If it is not a list with one value per frame, no scale bar is drawn.
timestamps (list or tuple of float, optional) – Time of each frame, in seconds. If it is not a list or tuple with one value per frame, frame numbers are drawn instead.
scale_bar_length_nm (int, optional) – Length of the scale bar, in nm; 0 hides it. Default is 100.
output_folder (str or pathlib.Path, optional) – Folder for the images; created if missing. Default is
"output_frames".base_name (str, optional) – Start of each file name. Default is
"frame".fmt ({"png", "jpg", "jpeg"}, optional) – Image format. PNG is lossless; JPEG files are saved at quality 90 with the extension
.jpg. Default is"png".cmap_name (str, optional) – Name of a registered matplotlib colormap. Default is
"afm_brown".zmin (float or str or None, optional) – Colour scale limits, as for the
export_*functions: both None scales each frame separately; otherwise the limits apply to every frame, with"auto"for the 1st or 99th percentile and None for the stack’s minimum or maximum. Default is None.zmax (float or str or None, optional) – Colour scale limits, as for the
export_*functions: both None scales each frame separately; otherwise the limits apply to every frame, with"auto"for the 1st or 99th percentile and None for the stack’s minimum or maximum. Default is None.draw_ts (bool, optional) – Draw each frame’s time on the frame. Default is True.
draw_scale (bool, optional) – Draw a scale bar. Default is True.
font_scale (float, optional) – Size of the annotation text for a frame 512 pixels high. Default is 2.0.
- Returns:
The folder the images were written to.
- Return type:
- Raises:
ValueError – If
fmtis not supported,zminis greater thanzmax, or a limit is not a number,"auto"or None.
- playnano.io.image_sequence_export.export_image_sequence(afm_stack, make_sequence: bool, output_folder: str | None, output_name: str | None, scale_bar_nm: int | None, fmt: str = 'png', raw: bool = False, zmin: float | None = None, zmax: float | None = None, draw_ts: bool = True, draw_scale: bool = True, cmap_name: str = 'afm_brown', font_scale: float = 2.0) None[source]¶
Export a stack as a folder of annotated PNG or JPEG images, one per frame.
The images are written to
<output_folder>/<output_name>/as<output_name>_0000.png,<output_name>_0001.pngand so on._filteredis added to the name when processed data is exported, that is whenrawis False and the stack has processed layers other than"raw".- Parameters:
afm_stack (AFMImageStack) – The stack to export.
make_sequence (bool) – If False, do nothing.
output_folder (str or None) – Folder for the output; created if missing. If None,
./output.output_name (str or None) – Name for the output, without extension. Any folder part and known extension are removed. If None or empty, the name of the file the stack was loaded from is used.
scale_bar_nm (int or None) – Length of the scale bar, in nm. 0 hides it; None uses 100.
fmt ({"png", "jpg", "jpeg"}, optional) – Image format. Default is
"png".raw (bool, optional) – If True, export the unprocessed snapshot
stack.processed["raw"], with the frame times from before any frames were removed. Otherwise exportstack.data. Default is False.zmin (float or str or None, optional) – Height mapped to the bottom of the colormap, in the units of the data (usually nm), or
"auto"for the 1st percentile of the stack. Default is None.zmax (float or str or None, optional) –
Height mapped to the top of the colormap, or
"auto"for the 99th percentile of the stack. Default is None.If
zminandzmaxare both None, each frame is scaled separately from its own minimum to its maximum. If either is set, both apply to every frame, and a None limit becomes the minimum or maximum of the whole stack. Values outside the range are clipped.draw_ts (bool, optional) – Draw each frame’s time, in seconds, on the frame. Default is True.
draw_scale (bool, optional) – Draw a scale bar. Default is True.
cmap_name (str, optional) – Name of a registered matplotlib colormap. Default is
"afm_brown".font_scale (float, optional) – Size of the annotation text for a frame 512 pixels high; scaled with the rendered frame height. Default is 2.0.
- Raises:
ValueError – If
fmtis not supported, orzminis greater thanzmax.