This gist describes how to automatically features in an images with labels. It is intended in the case where you have a an image, i.e., an SEM map of a sample mount and SEM stage coordinates with features that you wnat to label.
- An image / map with features to map
- A table with labels for the features and stage coordinates
- Inkscape installed on your computer
- Install the Simple Inkscape Scripting plugin for Inkscape
- Import your image into Inkscape and scale it such that 1 mm in Inkscape is equal to 1 µm on your image
- Find three features for which you have stage coordinates on your Inkscape map and note down the Inkscape coordinates. It is recommended that these features are far apart from each other, i.e., top left, top right, and bottom center of the map.
- Use the CoordinateTransformation program to convert your stage
coordinates into Inkscape coordinates using the three features that you identified.
With three features, use the
Admonroutine to transform the coordinates. If your final results are not satisfactory, try adding more feature to the coordinate transformation and use theNittlerroutine. For the latter to work, you will have to multiply all your stage coordinates with a factor of 1000. - Export the transformed coordinates as a
.csvfile - Use the
grain_labeler.pypython script with adjustments to your case (see below) with the simple inkscape scrpiting plugin.
The following variables have to be adjusted to your case:
Note: Python is zero-indexed, which means that the first column will be column 0.
fname: File name for your.csvfile (use absolute path)hdrrows: Number of header lines in the file before the data startnamecol: Number which column contains the feature labelsxcol: Column that contains the Inkscape x-coordinatesycol: Column that contains the Inkscape y-coordinates
Optional variables:
separator: How your data are separated in the file, should stay","for a.csvfilecircle_radius: Radius of the circle in Inkscape mmcircle_color: Color of the circle and labels as RGB code, see, e.g., herecircle_ew: Circle edge width in Inkscape mmlayer_name: Name of the Inkscape layer that will be created and where annotations will be written into