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
| =================================================== Calibrate and put a scale bar, and draw a fixed line segment on an image: code: =================================================== Detect a scale bar / scalebar calibration by clicking the start and end of the scale bar on desktop: code: A custom Python script (code for white scale bar and codefor red scale bar) was developed to automatically detect and quantify the scale bar in transmission electron microscopy (TEM) images, facilitating the conversion of pixel-based measurements into real-world units (e.g., nanometers). The script employs OpenCV to preprocess the image, applying thresholding and morphological operations to isolate the bright horizontal scale bar typically located near the bottom of the image. Contour analysis is used to identify the scale bar based on its high aspect ratio and area characteristics. Additionally, the script integrates Tesseract OCR to extract the numerical value of the scale bar label (e.g., “100 nm”) from the adjacent text region. This allows the automated calculation of the physical scale (nanometers per pixel) for the image. The entire process, including visual verification of the detected scale bar and OCR output, is automated and repeatable, providing an efficient tool for high-throughput image analysis in TEM studies.
|