Skip to Content

Scripts Library

2D image rotation

DigitalMicrograph - Gatan

2D plane wave

DigitalMicrograph - Gatan

Create 2D sine wave image with a given angle and periodicity.

3D image rotation

DigitalMicrograph - Gatan

4D STEM maximum spot mapping

Python - Gatan

Produce a colorful map of crystalline regions from a 4D STEM dataset open in DigitalMicrograph using a simple algorithm that finds the location and intensity of the maximum pixel in each pattern. While the result looks like an orientation map, it does not perform proper orientation mapping.

Accessing LinePlot slice data by slice index

DigitalMicrograph - Gatan

Accessing LinePlot slice data by slice label

DigitalMicrograph - Gatan

Accessing LinePlot slice data by slice-ID object

DigitalMicrograph - Gatan

Add a ROI to two images (identical or cloned)

DigitalMicrograph - Gatan

If the identical ROI is added to multiple displays, it is only a single memory object. Changes (such as movements) affect both displays simultaneously. The ROIs appear to be linked. ROIs are automatically cloned when the image is saved.

Add centered rectangle or range ROI to front image

DigitalMicrograph - Gatan

Add ROI to image after checking for ImageDisplay

DigitalMicrograph - Gatan

Add scale-bar and intensity-bar

DigitalMicrograph - Gatan

Command example showing how scale-bar and intensity-bar annotations are created on an image.

Adding annotations to an image display

Python - Gatan

Example of adding annotation components to an ImageDisplay. The script uses the front-most displayed image. If none is found, it creates and displays one.

Affine transformations

DigitalMicrograph - Gatan

Amorphous

DigitalMicrograph - Gatan

Make an image resembling a TEM image of an amorphous specimen.

Annotation scaling

DigitalMicrograph - Gatan

Scale all of the annotations on an image by a requested factor.

Bin 2D image

DigitalMicrograph - Gatan

Bin pixels in 2D images (demonstrate Slice2 command).

Bin 3D image

DigitalMicrograph - Gatan

Perform voxel binning in 3D images (demonstrate Slice3 command).

Calling a Command-Line command from script and showing its output

DigitalMicrograph - Gatan

The script uses the Command-Line command "ipconfig" and outputs its results into a new text window of DigitalMicrograph. The script is a useful blueprint for similar tasks that can be performed from the regular Windows Command-Line.

Camera acquisition

Python - Gatan

Example script showing different types of camera acquisition.

Change calibration units

DigitalMicrograph - Gatan

Switch dimension calibration units in an image (demonstrate simple custom dialog).

Change z-ordering of ROIs on a display

DigitalMicrograph - Gatan

Circular mask image

Python - Gatan

Create circularly masked version of the frontmost image.

Colorband spectrum image

DigitalMicrograph - Gatan

Generates an RGB image from a spectrum image with user-defined central wavelength and bandwidth. Useful for displaying spectrum image data.

Combining images into a stack

DigitalMicrograph - Gatan

Combining spectra into 2D image

DigitalMicrograph - Gatan

Component example

DigitalMicrograph - Gatan

Add and read various text annotations (demonstrate usage of annotations in image documents).

Copy a single string tag to all open images

DigitalMicrograph - Gatan

Copies a single string tag to all the open images.

Copy a specific TagGroup from one image to another

DigitalMicrograph - Gatan

Copy all tags in the TagGroup 'sTG' into the TagGroup 'gTG' gTGsub.TagGroupReplaceTagsWithCopy( sTGsub ).

Copy all tags from one image to another

DigitalMicrograph - Gatan

Copies all tags in the TagGroup 'sTG' into the TagGroup 'gTG,' potentially replacing existing tags.
 

Copy LinePlot display style from front image to all other LinePlots

DigitalMicrograph - Gatan

Automation script to quickly apply specific display styles (e.g., line thickness, color) to all open LinePlots based on the frontmost displayed LinePlot.

Copy single TagList entry into second TagList

DigitalMicrograph - Gatan

Copies a single list entry from the source as an additional entry in the goal list.

Copying LinePlot styles

DigitalMicrograph - Gatan

Copy display properties of the frontmost LinePlot image to all other open LinePlot images.

Count negative pixels

Python - Gatan

Count the number of negative pixels in the front image.

Count pixels with negative value

DigitalMicrograph - Gatan

Create a system response file

DigitalMicrograph - Gatan

Generates a relative system response to correct for non-linearities in a system's sensitivity over a wavelength range. Requires a known reference spectrum, e.g., from a temperature calibrated black body source or calculated transition radiation spectrum.

Create and show RGB image

Python - Gatan

This script creates 3 images in Python and utilizes a DM-script to create and show a color-overlay image. It is an example of how Hybrid scripts can be used to access functionality not (yet) available in the Python language directly. The script shows how image-labels can be used to address images across the two scripts.

Creating DigitalMicrograph images and accessing image data

Python - Gatan

DM images can be created from Numpy arrays. DM image values can be accessed as a Numpy array.

Crop image center

Python - Gatan

Crop an image to a specified size. Only the data is copied.

Crop image to selection

DigitalMicrograph - Gatan

Crop 2D or 3D image based on selection and displayed slices.(demonstrate data extraction).

Cropping a 2D sub-image

DigitalMicrograph - Gatan

Crystal

DigitalMicrograph - Gatan

Produce an image resembling a noisy TEM image of a crystal with x-rays.

DigiScan acquisition

Python - Gatan

Example script staring a simple DigiScan acquisition via a parameter set. For more details on DigiScan access via scripting also refer to the DM-scripting documentation.

DigitalMicrograph drift data - Fit

Python - Gatan

Fit or filter drift-measurement data measured from stacks in Gatan Microscopy Suite.

DigitalMicrograph drift data - Interpolate

Python - Gatan

Interpolate drift-measurement data measured from stacks in Gatan Microscopy Suite.

DigitalMicrograph drift data - Plot

Python - Gatan

Replot drift-measurement data measured from stacks in Gatan Microscopy Suite as a trajectory.

Display application tags (aka_'global_tags') in a tag browser

DigitalMicrograph - Gatan

Displays the application tags (aka_'global_tags') in a tag browser.

Display as HSB

DigitalMicrograph - Gatan

Display complex image as color encoded HSB image (phase = color, modulus = brightness).

Display extended image selection dialog (1 image)

DigitalMicrograph - Gatan

Display extended image selection dialog (3 images)

DigitalMicrograph - Gatan

Display files and sub-folders as tags in a tag browser

DigitalMicrograph - Gatan

Displays files and sub-folders as tags in a tag browser.

Display image tags in a tag browser

DigitalMicrograph - Gatan

This is equivalent to the following 'pipeline' syntax: img.ImageGetTagGroup().TagGroupOpenBrowserWindow( 0 ).

Display listener (show z-stack position)

DigitalMicrograph - Gatan

Creates an annotation for the currently displayed wavelength in a spectrum image. Ideal for embedding current wavelength in images and videos.

Display simple image selection dialog (1 image)

DigitalMicrograph - Gatan

Embedding in larger 2D image

DigitalMicrograph - Gatan

Extract multiple point spectra from 3D spectrum image and store in linescan like container

DigitalMicrograph - Gatan

Extract multiple ROI-selected image cutouts

DigitalMicrograph - Gatan

This example assumes that the frontmost image has one or more rectangular ROIs drawn on it. Use the ROI tool to add them. To add multiple ROIs per mouse, hold down the Shift key when starting
to draw them.

Extract ROI-selection as separate image

DigitalMicrograph - Gatan

The script performs the same action as copying an ROI selection (Ctrl + C) and pasting it as a new image on the workspace (Ctrl + Alt + V). It works for both 2D and 1D images. For 3D images, it copies the integrated intensity seen on the display.

Extract sum-diffraction patterns from all points of 4D STEM diffraction image

DigitalMicrograph - Gatan

The first two numbers specify input (N) and output (M) dimensionality. The next N values give a sampling start point, and the next M triplets define sampling for each output dimension.

Extract values at specific coordinates

DigitalMicrograph - Gatan

Extracting a spectrum

Python - Gatan

Access a single spectrum from a 3D STEM SI in DigitalMicrograph. This script assumes a 3D image is frontmost on the workspace.

Find image by ID

Python - Gatan

Example use of FindImage by ID. This script gets the chronologically last image. It works because image IDs are incremented whenever new memory is allocated.

Find image by label

Python - Gatan

Example use of FindImage by name.

Find image by name

Python - Gatan

Example use of FindImage by name.

Focal series

DigitalMicrograph - Gatan

Simulate a focal series of theoretical diffractograms.

Formatted string

DigitalMicrograph - Gatan

Formats the ellipsis and padding of a string (string input, number width, number eAlign, number eEllipsis, string fillStr).

Get front two images

Python - Gatan

Demonstration of accessing the two frontmost images in GMS.

Having a script wait for a file to appear

DigitalMicrograph - Gatan

Example script which holds its execution until a certain file is found at a given location. Checking is performed on the main thread at given intervals.

Hybrid - DigitalMicrograph script calls Python

DigitalMicrograph - Gatan

This DigitalMicrograph script executes a Python script on a new background thread.

Hybrid - Python calls DigitalMicrograph show alert

Python - Gatan

This Python script builds and runs a DigitalMicrograph script.

Import an image from a text file

DigitalMicrograph - Gatan

Command example script showing how the ImageImportTextData() command is to be used.

In-situ 4D STEM maximum spot mapping

Python - Gatan

Produce a series of colorful maps of crystalline regions from an in-situ 4D STEM dataset open in DigitalMicrograph. This uses a simple algorithm that finds the location and intensity of the maximum pixel in each pattern. The resulting in-situ video of color maps automatically syncs with the original data in DigitalMicrograph. While the results look like orientation maps, the script does not perform proper orientation mapping.

In-situ dataset radial profile Diff or FFT

Python - Gatan

Compute radial-max profiles from an in-situ dataset in DigitalMicrograph. The data can be HRTEM images (from which the FFT will be computed) or diffraction patterns over time. The primary result is a single 2D display of these profiles over time, with time as one dimension and radius as the other. The script also generates an automatically synced in-situ dataset of the 1D radial profiles.

InGaN bandgap to concentration

DigitalMicrograph - Gatan

A basic script that uses an equation and parameters to estimate the concentration of In in an InGaN spectrum image. Requires as input: Map of bandgap estimation (output from NLLS fitting).

Interactive histogram

DigitalMicrograph - Gatan

Compute a histogram of the frontmost image and allow interactive change of histogram bins.

Inverse ROI selection state

DigitalMicrograph - Gatan

IS dataset radial FFT profile

Python - Gatan

Compute radial-max profiles over time from the FFT of in-situ video datasets in Gatan Microscopy Suite.

Iterate layouts

DigitalMicrograph - Gatan

Command example showing how ImageDocument layouts are set.

Launching an external application and regularly checking if it is still running

DigitalMicrograph - Gatan

Example script showing how the external application Notepad.exe can be launched. The script regularly polls whether or not Notepad.exe is still open so that actions can be performed once the external application is closed.

LineROI measurements

DigitalMicrograph - Gatan

Returns the number, length, and angle of the LineROIs on the display.

Listing ROI properties

DigitalMicrograph - Gatan

Listing tag types

DigitalMicrograph - Gatan

Lists all available tag types.

Live difference

Python - Gatan

Code to process the live-view image in DigitalMicrograph, producing a difference image. Two exponentially weighted moving averages are computed, and the absolute value of the difference between them is returned.

Live FFT color map

Python - Gatan

Code to process the live-view image in DigitalMicrograph, producing a series of maps of crystalline regions in real-time. It computes a grid of small FFTs from each image. It then treats this grid similar to a 4D STEM data cube, where it finds the brightest spot in each FFT and displays its orientation and intensity as an updating color map.

Live max FFT

Python - Gatan

Code to process the live-view image in DigitalMicrograph, producing an FFT-like display. A grid of small FFTs is computed from the image, and then rather than averaging the FFTs together, the maximum across all FFTs is taken pixel-by-pixel.

Live noise reduction

Python - Gatan

Code to process the live-view image in DigitalMicrograph, producing a new filtered display. A median and/or Gaussian blur can be applied.

Live radial profile

Python - Gatan

Code to compute radial-max profiles of the FFT of a live-view image in DigitalMicrograph, producing a 2D display of these profiles over time.

Live radial profile Diff or FFT

Python - Gatan

Compute radial-max profiles of either the FFTs of HRTEM images or diffraction patterns over time. You can compute profiles from the 2D live-view image in DigitalMicrograph or in-situ 2D image data played back via the In-Situ Player. The result is a single 2D display of these profiles over time, with time as one dimension and radius as the other. Profiles are computed as often as possible.

Live simple copy

Python - Gatan

Code to process the live-view image in DigitalMicrograph, producing a copy. This script provides a minimal template for processing data in the live view.

Live thresholding with plots

Python - Gatan

Code to process the live-view image in DigitalMicrograph, producing a binary display. The live image is thresholded, and several morphological operations are applied to create a binary display. Then the largest contiguous bright region is found and circled. A plot of the position of the center of mass of that bright region is also updated live.

LiveView linear profile

Python - Gatan

Compute ROI-based profiles over time from the LiveView image in Gatan Microscopy Suite.

LiveView radial FFT profile

Python - Gatan

Compute radial-max profiles over time from the FFT of the LiveView image in Gatan Microscopy Suite.

Lock and unlock all ROIs

DigitalMicrograph - Gatan

Make Gaussians

DigitalMicrograph - Gatan

Generate a 1D and 2D Gaussian distribution (demonstrate function overload).

Manually saving tags as file

DigitalMicrograph - Gatan

Saves the file in *.gtg format.

Mask all pixels with higher value than their right neighbor

DigitalMicrograph - Gatan

Mask all pixels with intensity below image mean value

DigitalMicrograph - Gatan

Mask all pixels within a circular area around a specified point

DigitalMicrograph - Gatan

Mask the lower triangle of an image

DigitalMicrograph - Gatan

Merge images

DigitalMicrograph - Gatan

Combine two images of different intensity levels into one. Useful to merge diffraction patterns of different exposure times.

Microscope access

Python - Gatan

Example script basic microscope access. For further info please also refer to the DM-scripting documentation on microscope access.

Monitor a value over time

DigitalMicrograph - Gatan

This example script monitors a value and plots it in regular intervals, creating a growing LinePlot. The script is a template that can easily be modified to create time-logging of any script-accessible value.

Number format

DigitalMicrograph - Gatan

Defines the number format.

Open tag file

DigitalMicrograph - Gatan

Create an empty TagGroup object and then load it into the TagGroup.

Output DM Python help

Python - Gatan

Output Python commands of DigitalMicrograph. Output command-specific help.

Output version info

Python - Gatan

Output basic information of the used Python environment.

PMT time series for MonoCL3 and MonoCL4 systems

DigitalMicrograph - Gatan

Generates an intensity profile as a function of time using the cps value displayed in the MonoCL Control palette. Useful for measuring beam-induced changes in the specimen emission intensity.

Point-marker tool

DigitalMicrograph - Gatan

Polar transformations

DigitalMicrograph - Gatan

Print all image documents with an optional frame

DigitalMicrograph - Gatan

This automation script will print all currently shown images in page mode using the default printer setting. The script will optionally add a rectangular border to the page.

Print tags to results window

DigitalMicrograph - Gatan

Example of calling the function
image img
if ( !GetFrontImage( img ) )
    Throw( "No image displayed." )

TagGroup tg = ImageGetTagGroup( img )
RecursivePrintTag( tg, 0 )

Process 2D in-situ datasets

Python - Gatan

Process in-situ camera or in-situ STEM imaging datasets in DigitalMicrograph. The script handles several in-situ file formats used by DigitalMicrograph and produces results that are automatically synced with the original data when played back in DigitalMicrograph. The script supports custom processing of each frame by modifying a frame processing function.

Process all DM files in a folder and its subfolders

DigitalMicrograph - Gatan

Automation script for batch processing specific files from a folder structure. The script can be easily modified to perform different tasks.

Process all images on a workspace

DigitalMicrograph - Gatan

This automation script applies a processing method to all currently open images. The script is easily modified to perform different tasks on all currently open images.

Remove all LineROIs from image

DigitalMicrograph - Gatan

Remove all ROIs from image

DigitalMicrograph - Gatan

Replace

DigitalMicrograph - Gatan

Replaces each occurrence and returns the number of replacements.

Resizing with intensity interpolation

DigitalMicrograph - Gatan

RGB color stack

DigitalMicrograph - Gatan

Generates a 3D RGB image with each slice (wavelength image) colored according to its wavelength to match visible light. Each slice is normalized to itself.

Rotational average

DigitalMicrograph - Gatan

Create a rotationally averaged image  (demonstrate warp command).

Run VisualBasic script

DigitalMicrograph - Gatan

Example showing how a VBS script stored as a file on the hard drive can be executed from a DigitalMicrograph script.

Run VisualBasic script directly

DigitalMicrograph - Gatan

Example script showing how a VBS script code can be created as a string variable and directly executed from a DigitalMicrograph script.

Save tag file

DigitalMicrograph - Gatan

Extension *.gtg will be auto-appended to path myTags.TagGroupSaveToFile( path ).

Scale 2D image

DigitalMicrograph - Gatan

Scale a 2D image by a requested factor either using sampling or bi-linear interpolation (demonstrate warp command).

Scale all images to a given value range

DigitalMicrograph - Gatan

This script normalizes the intensity values of all open images to a defined range [0 - max].

Set all scale bars to same style

DigitalMicrograph - Gatan

This automation script will set the style and size of the scale-bar annotations of all currently shown images.

Show system IP configuration

DigitalMicrograph - Gatan

Short script showing how command prompt output can be created and read into a DigitalMicrograph script using the command line 'ipconfig.exe' as an example.

Simple dialogs

Python - Gatan

The input command presents a simple dialog and returns the entered string. Some other simple prompted dialogs are provided by the plugin.

Sine pattern

DigitalMicrograph - Gatan

Demonstrate the usage of icol and irow and setting a different color lookup table.

Sort images onto separate workspaces

DigitalMicrograph - Gatan

This automation script iterates over all currently shown images and selects them one by one. The user is asked to press either ALT or CTRL to move the shown image to one of two newly created workspaces, or SHIFT to end the script.

Spherisize

DigitalMicrograph - Gatan

Take a square image, wrap it around a sphere, and then return the resulting image.

Start an external executable

DigitalMicrograph - Gatan

Mini-example of how the command LaunchExternalProcess() is used. This command can execute any external application. It provides a powerful method to access hardware outside the DigitalMicrograph environment from within DigitalMicrograph.

Text output examples

Python - Gatan

Basic text output examples in DigitalMicrograph. By default, the output stream is sent to the Results window.

Timebar on image

DigitalMicrograph - Gatan

Display a digital clock on the frontmost image (demonstrate periodic tasks).

Tokenize

DigitalMicrograph - Gatan

The Tokenize function finds the next token in the target string. On each call, the function starts at iStart, skips leading delimiters, and returns a string containing the current token. 

Total Dose Rate Listener2

DigitalMicrograph - Gatan

Script to measure and display the total dose rate (in millions of electrons per second) on the camera.
Run this script with the live view frontmost in DigitalMicrograph and press the Spacebar key to stop it.

Transfer function, interactive

DigitalMicrograph - Gatan

Interactively draw and modify the contrast transfer function as a LinePlot.

Transfer ROIs from one image to another

DigitalMicrograph - Gatan

Unicode

DigitalMicrograph - Gatan

Lists the Unicode characters by code.

Use PowerShell to send email

DigitalMicrograph - Gatan

This script uses Microsoft PowerShell to send out an email. Modify the mail server variables before testing.

WARCL polar map to energy-momentum mapping

DigitalMicrograph - Gatan

Remaps a 3D WARCL polar map image stack to an energy-momentum basis.

Waterfall

DigitalMicrograph - Gatan

Adds a defined offset to a collection of spectra when the display type is set to a LinePlot data set; useful for displaying multiple spectra in a single image display, e.g., spectrum image (SI) time series, SI line scan, or (SI) multi-point acquisition modes.