Skip to main content

sem2surface

sem2surface reconstructs a three-dimensional surface from three to five multi-detector SEM/BSE images. It extracts two normalized principal images, identifies their orientation with a Radon transform, and integrates the resulting gradients using the Frankot-Chellappa FFT method.

3D surface reconstruction from multi-detector SEM images

The reconstruction can be used qualitatively with an arbitrary vertical scale. Quantitative measurements require a calibrated Z scaling factor for the imaging configuration. The included Vickers-indentation example demonstrates that calibration procedure.

Installation

Python 3.10 or newer is required. An isolated virtual environment is strongly recommended so the application does not conflict with system Python packages.

Linux and macOS

Create an environment and install a released version:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install sem2surface
sem2surface-gui

Until a release is uploaded to PyPI, run the final installation command from this source checkout instead:

python -m pip install .

On Linux, Tkinter may be packaged separately. For example, Ubuntu and Debian users can install it with their system package manager as python3-tk before creating the environment.

Windows

Install Python 3.10 or newer from python.org. Keep the standard pip, Tcl/Tk, and Python Launcher components enabled. Then open PowerShell in the folder where you want the environment and run:

py -3 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install sem2surface
sem2surface-gui

If PowerShell blocks the activation script, allow it only for the current PowerShell process and retry activation:

Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
.\.venv\Scripts\Activate.ps1

In Command Prompt, activate the same environment with:

.venv\Scripts\activate.bat

Activation is optional. The GUI can always be launched directly:

.\.venv\Scripts\sem2surface-gui.exe

Before the PyPI release, install either from a source checkout with python -m pip install . or from the provided wheel:

python -m pip install "C:\path\to\sem2surface-0.2.0-py3-none-any.whl"

Use deactivate to leave the environment on any platform. Do not copy a virtual environment between computers or move it after creation; create a new one and reinstall the package instead.

VTK export is optional because VTK is a large dependency:

python -m pip install "sem2surface[vtk]"
# From this source checkout instead: python -m pip install ".[vtk]"

The application does not require ImageMagick or a LaTeX installation. Tkinter is included with the standard Python installers on Windows and macOS.

Desktop application

After installation, launch the graphical interface from a terminal:

sem2surface-gui

Select three to five detector images, confirm the pixel size and scaling factor, choose an output directory, and start the reconstruction. TIFF, PNG, JPEG, and BMP images are supported. The work runs in the background so the window remains responsive.

The GUI intentionally provides only the FFT reconstruction. Atomic-number correction and direct profile integration have been removed.

Command line

Installation also provides a sem2surface executable:

sem2surface detector_A.tif detector_B.tif detector_C.tif \
  --z-scale 217.27243 \
  --save npz \
  --output-dir results

Pixel size is read from the first TIFF by default. For images without compatible SEM metadata, provide it in micrometres:

sem2surface detector_A.png detector_B.png detector_C.png \
  --pixel-size-um 0.325521 \
  --curvature none

Run sem2surface --help for the complete list of options. VTK output requires the optional vtk installation described above.

Python API

from pathlib import Path

from sem2surface import construct_surface

images = [Path("detector_A.tif"), Path("detector_B.tif"), Path("detector_C.tif")]
preview, X, Y, Z, warning = construct_surface(
    images,
    z_scaling_factor_per_pixel=217.27243,
    remove_curvature=True,
    save_file_type="NPZ",
    output_dir="results",
)

Pixel size and manual curvature radii use metres in the Python API. Returned coordinate and height arrays use micrometres. The old constructSurface function remains as a compatibility wrapper for version 0.1 scripts, but only FFT reconstruction is accepted and the old atomic-number arguments are ignored.

Outputs

Every reconstruction creates:

  • a colour PNG of the reconstructed surface;
  • a grayscale PNG suitable for further image analysis;
  • a UTF-8 log containing parameters, input names, angles, and surface RMS.

Surface arrays can additionally be saved as CSV, compressed NumPy NPZ, or VTK structured-grid data. Optional diagnostic output includes the detector/PCA decomposition, Radon search, and oriented gradients.

When timestamps are disabled, an existing output with the same name is replaced. Choose a dedicated output folder or enable timestamps when results must be kept.

Reference examples and scaling

The examples directory contains the reference analyses:

  • Surface_1 and Surface_2: representative reconstructed surfaces;
  • Vickers_imprint: reconstruction of a Vickers indentation;
  • Vickers_imprint_scaling: identification of the Z scaling factor from the known Vickers geometry.

After installing the package with the VTK extra, an example can be run from any working directory:

python examples/Surface_1/test_without_gui.py

Reconstruction of the indented surface

Development

Create an isolated environment and install the editable project with its test tools:

python -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[test]"
python -m pytest
python -m build
python -m twine check dist/*

Continuous integration tests Python 3.10 and 3.13 on Linux, Windows, and macOS, and verifies both the source distribution and universal wheel.

Maintainer release checklist

Use a clean virtual environment and update the version in both pyproject.toml and src/sem2surface.py. PyPI does not allow an uploaded file or release version to be replaced.

python -m pytest -q
python -m build
python -m twine check dist/*

For a first trial, create a separate account and API token on TestPyPI, then upload only the files for the new version:

python -m twine upload --repository testpypi dist/sem2surface-0.2.0*

When prompted, use __token__ as the username and the complete TestPyPI token, including its pypi- prefix, as the password. Test the uploaded wheel in a new environment without resolving dependencies from TestPyPI:

python -m pip install --index-url https://test.pypi.org/simple/ --no-deps sem2surface==0.2.0
sem2surface --version

For the real release, create a PyPI account and API token at pypi.org, then run:

python -m twine upload dist/sem2surface-0.2.0*

PyPI and TestPyPI use separate accounts and tokens. Never commit a token or put one directly in a command. For later automated releases, prefer PyPI Trusted Publishing.

Method references

  1. Neggers, J. et al. (2021). Principal image decomposition for multi-detector backscatter electron topography reconstruction. Ultramicroscopy, 227, 113200. DOI
  2. Frankot, R. T. and Chellappa, R. (1988). A method for enforcing integrability in shape from shading algorithms. IEEE Transactions on Pattern Analysis and Machine Intelligence, 10(4), 439-451. DOI

Author and license

Developed by Vladislav A. Yastrebov, CNRS, Mines Paris – PSL, Centre des matériaux. Distributed under the BSD 3-Clause License.

Metadata

Release files for sem2surface 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sem2surface 0.2.0
File Size Uploaded
sem2surface-0.2.0.tar.gz 22.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sem2surface 0.2.0
File Interpreter ABI Platform
sem2surface-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 43.6 kB

Release files / sem2surface-0.2.0.tar.gz

Download URL sem2surface-0.2.0.tar.gz
Size 22.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0292b4bfa0c705bf4d4a719aba27b98c9f42fb9bf1b6177cdc67487bbc6b05fb
BLAKE2b-256 checksum
How to use checksums
ea1b4b4d1209471d99ed5c89887bd85da7af56e901e2388312b137b2271ec38a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / sem2surface-0.2.0-py3-none-any.whl

Download URL sem2surface-0.2.0-py3-none-any.whl
Size 21.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8f91079126f893c74965b1d70fdf01facca5b6a1f98a4b5ef12a96e1f986124
BLAKE2b-256 checksum
How to use checksums
a769bf2e64773b871ca5f74d98bdb32ca23df67ca9ebf5f7b64e781b3a7052fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release history Release notifications | RSS feed

0.2.2

2 release files

0.2.1

2 release files

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page