sem_io

Python code to help extract metadata parameters from SEM images

https://github.com/mammos-project/sem_io

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.7%) to scientific vocabulary

Keywords

electron-microscopy images metadata-extraction research
Last synced: 6 months ago · JSON representation ·

Repository

Python code to help extract metadata parameters from SEM images

Basic Info
  • Host: GitHub
  • Owner: MaMMoS-project
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 67.4 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 1
  • Releases: 5
Topics
electron-microscopy images metadata-extraction research
Created over 3 years ago · Last pushed 8 months ago
Metadata Files
Readme License Citation

README.md

sem_io

Helper functions to extract, view and store metadata from the header of SEM images (.tif) recorded using either Zeiss SmartSEM or Thermo Fisher Scientific xT software.


Installation

Please clone/download the repository and install with pip

bash cd sem_io pip install .


Usage

Command line

To print an overview of parameters from the image header in the console, at the command line, you can do:

bash sem_io path/to/my/image.tif


To print an overview from several images one after the other, you can use:

bash sem_io path/to/my/image.tif path/to/my/image2.tif path/to/my/image3.tif


To print an overview from all images in a folder, you can use:

bash sem_io path/to/my/folder_of_tif_images


You can process any number of individual images and folders at the same time:

bash sem_io path/to/my/image.tif path/to/my/folder_of_tif_images path/to/my/image2.tif


The flag -d can be used to additionally dump selected metadata to json:

bash sem_io path/to/my/image.tif -d

The json file will be located in the same folder as the image and will have the name myimagemetadata.json. As before, you can process any number of images and/or folders of images with the flag -d.


To dump metadata from a folder containing many images, without printing the output to the screen, you can additionally use the flag -s:

bash sem_io path/to/my/folder_of_tif_images -d -s

or, more simply:

bash sem_io path/to/my/folder_of_tif_images -ds

Either of the above two commands will save a json file for each .tif image in the specified folder.


If you prefer a simple text file instead of a json, you can pipe the output of sem_io to file like this:

bash sem_io path/to/my/folder_of_tif_images > other/path/my_text_output.txt

The above command will put the output of sem_io for all the .tif images in the folder given into a single text file. You can equally do this for a single .tif image by specifying the path to an image instead of to a folder.


Python

You can also import the module and use the functions directly in Python.

To print an overview of parameters from the image header in the console:

```python

import semio myparams = sem_io.SEMparams(r"path/to/my/image.tif") ```


If you just want to collect and store the parameters and not print them, you can do:

```python

myparams = semio.SEMparams(r"path/to/my/image.tif", verbose=False) ```


You can print ALL the header parameters to the console like this:

```python

myparams.printparamdict(myparams.params) ```


You can print A SELECTION OF the header parameters (given in the class definition) to the console like this:

```python

myparams.printparamdict(myparams.params_grouped) ```


Both myparams.params and myparams.params_groups are dictionaries and any parameter can be accessed, e.g.

```python

date = myparams.paramsgrouped["General"]["Date"] ```


Alternatively you can dump all the header parameters to a json file (optionally including a key giving the original image path) like this:

```python

myparams.dumpparamstojson(myparams.params, r"myjsonpath.json", imagepath=myparams.imgpath) ```


Calling the command line functionality from Python

You can call the functions from the command line within Python using the subprocess module. For example, to dump metadata from a directory of images to json and print the output to the Python terminal:

```python

import subprocess subprocess.run(["semio", r"path/to/my/folderoftifimages", "-d"]) ```

To pipe the output of sem_io to a text file instead:

```python

with open(r"my/output/path/myfile.txt", "w") as outputfile: ... process = subprocess.Popen(["semio", r"path/to/my/image.tif"], stdout=output_file) ... process.communicate() ... ```


Getting the Image Pixel Size and Adding a Scalebar

All the functions are staticmethods, so you don't need to instantiate the SEMparams class at all. For example, there is a bespoke function for getting the image pixel size and its unit in one line of code:

```python

pixelsize, unit = semio.SEMparams.getimagepixel_size(r"path/to/my/image.tif") ```

This is useful if you want to plot the SEM image using matplotlib and add a scalebar with the correct dimensions using matplotlib-scalebar. Here's the whole process as an example:

```python

import matplotlib.pyplot as plt from matplotlibscalebar.scalebar import ScaleBar import semio myimage = plt.imread(r"pathtomyimage.tif") fig, ax = plt.subplots() ax.imshow(myimage, cmap='gray') pixelsize, unit = semio.SEMparams.getimagepixelsize(r"pathtomyimage.tif") myscalebar = ScaleBar(pixelsize, units=unit, location='lower right', scaleloc='top') ax.addartist(myscalebar) ```

Even Electron Channeling Patterns acquired in rocking beam mode are correctly handled by semio.SEMparams.getimagepixelsize()


Dependencies

General

  • The selected parameters defined in the class definition of SEMparams form a subset of those available in the header of the .tif image. If you are interested in other parameters, the program can be easily customised - all the header parameters are extracted and are available as the "params" instance attribute.
  • If there are any issues, please feel free to get in touch using the issues mechanism

Code Archive

This repository is archived on Zenodo: DOI

Owner

  • Name: MAgnetic Multiscale MOdelling Suite (MaMMoS) - placeholder
  • Login: MaMMoS-project
  • Kind: organization

Citation (CITATION.cff)

abstract: "Python functions to extract, view and store metadata from the header of SEM images."
authors:
  - family-names: Woodcock
    given-names: Thomas George
    orcid: "https://orcid.org/0000-0003-2351-973X"
    affiliation: "Leibniz Institute for Solid State and Materials Research (ROR: https://ror.org/04zb59n70)"
  - name: The sem_io Developers
    website: "https://github.com/MaMMoS-project/sem_io/graphs/contributors"
cff-version: 1.2.0
date-released: "2025-04-10"
doi: 10.5281/zenodo.15180575
keywords:
  - "electron microscopy"
  - metadata
  - SEM
  - image
  - research
  - data
  - management
license: MIT
message: "If you would like to cite this code, please do so using these metadata."
repository-code: "https://github.com/MaMMoS-project/sem_io"
title: "sem_io"
version: 0.2.2

GitHub Events

Total
  • Release event: 2
  • Push event: 7
  • Pull request event: 1
  • Create event: 3
Last Year
  • Release event: 2
  • Push event: 7
  • Pull request event: 1
  • Create event: 3