KLayout Image Overlay
Load reference images (JPG, PNG, BMP) into KLayout as background overlays for aligning device geometry to real microscope photos.
Prerequisites
- KLayout running with KlayoutClaw plugin (v0.5+)
- A layout must be open (use
create_layoutfirst if needed)
Scripts
add_image.py — Load an image as background overlay
python scripts/add_image.py <filepath> [--pixel-size 0.1] [--scale-bar <um> <pixels>] [--x 0] [--y 0] [--center]
filepath— Path to image file (JPG, PNG, BMP)--pixel-size— Microns per pixel (default: 1.0)--scale-bar— Derive pixel size from a scale bar:<length_um> <length_pixels>. Takes priority over--pixel-size.--x,--y— Position offset in microns (default: 0, 0)--center— Center the image at the given position (default: image corner at position)
Example — set pixel size directly:
python scripts/add_image.py ~/photos/graphene.jpg --pixel-size 0.1
Example — derive pixel size from a 20 um scale bar that spans 153 pixels:
python scripts/add_image.py ~/photos/graphene.jpg --scale-bar 20 153 --center
# Output: Scale bar: 20.0 um / 153.0 px = 0.1307 um/px
Example — load and center at a specific position:
python scripts/add_image.py ~/photos/flake.png --pixel-size 0.05 --x 100 --y 50 --center
list_images.py — List all background images in the view
python scripts/list_images.py
Prints a table of all loaded images with their ID, filename, position, and visibility.
remove_image.py — Remove a background image
python scripts/remove_image.py <image_id | all>
image_id— Numeric ID of the image to remove (fromlist_images.py)all— Remove all background images
Workflow
- Load a microscope image as reference background
- Use geometry scripts to draw device features (contacts, gates, mesa) on top
- Adjust pixel-size to match the image's physical scale (check the scale bar)
- Use
list_images.pyto see loaded images,remove_image.pyto clean up
Estimating pixel-size
If the image has a scale bar of length S microns spanning P pixels:
pixel-size = S / P
For example, a 20 um scale bar that spans 200 pixels gives pixel-size = 0.1.