Practical Electron Microscopy and Database

An Online Book, Second Edition by Dr. Yougui Liao (2006)

Practical Electron Microscopy and Database - An Online Book

Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix

Measure the Length (Dimension) of (Colored) Line Annotations

To facilitate accurate and automated measurement of annotated features in TEM images, a set of custom DigitalMicrograph scripts can be implemented. These scripts streamline the process of extracting calibrated distances from line annotations, thereby minimizing manual error and improving reproducibility. The outputs include individual line lengths as well as statistical metrics such as mean and standard deviation, directly computed from the annotation geometry and image calibration metadata.

Each script in this collection serves a distinct use case, utilizing specific code blocks to implement its functionality:

Script 1 focuses on the measurement of a single selected line annotation. It uses Componentgetcontrolpoint(4, EMx0, EMy0) and Componentgetcontrolpoint(7, EMx, EMy) to extract the endpoints of the annotation, and computes the pixel distance using the Euclidean formula sqrt((EMx-EMx0)^2 + (EMy-EMy0)^2). The result is scaled by the image calibration factor obtained via Imagegetdimensioncalibration(0, EMorigin, EMscale, EMunits, 1).

Script 2 generalizes the measurement to all line annotations on the front image. It iterates through each component using component line = imgdisp.componentgetnthchildoftype(2, i) and extracts lengths similarly to Script 1. It then stores the lengths in a 1D image array using setpixel(arrayimg, i, 0, length), and computes statistics via a custom StandardDeviation() function implemented using image operations such as sum() and sqrt().

Script 3 adds color-based categorization, enabling measurement and separation of line annotations by red, green, blue, and yellow colors. It determines color identity with conditional thresholds (e.g., if(r > 0.9 && g < 0.1 && b < 0.1) for red). The GetColorCategory() helper function handles classification, and PrintStats() is used to output statistics for each color group individually.

Script 4 retains the color-based measurement logic of Script 3 but improves memory allocation by pre-counting lines of each color using componentgetforegroundcolor(r, g, b) and allocating separate images (realimage(...)) of exact dimensions for red, green, blue, and yellow groups. This avoids unnecessary memory usage and simplifies array indexing.

Script 5 shares the same structure and functions as Script 4 but allows the input image to be passed as an argument (GlobalSinoMeasureColoredLines(image myImage)), enabling it to be integrated into broader automated workflows and batch processing systems.

These scripts, when combined, provide a robust, scalable solution for quantitative annotation analysis in TEM images. Their modularity allows researchers to select or extend them based on context, whether performing single-feature verification, bulk measurement, or color-coded feature categorization. The use of script-based measurement also supports auditability, making the approach well-suited for both research and industrial applications.