Skip to content

Latest commit

 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HR(S)TEM filter

Introduction

hrtem_filter provides a set of python functions to denoise HR(S)TEM images. A Wiener filter and an average background subtraction filter were designed based on R. Kilaas J. Microscopy, 1998, 190, 45-51. Some steps are adopted from D. R. G. Mitchell's script for GMS. A nonlinear filter was adopted by the "non-linear filter plugin from GMS", originally developed by Dr. Hongchu Du. Refer to the original paper: Hongchu Du, A nonlinear filtering algorithm for denoising HR(S)TEM micrographs, Ultramicroscopy 2015, 151, 62-67

Installation

Clone the repository and install using pip

pip install git+https://matao1984/hrtem_filter

Usage

Use wraper function: apply_filter(img, filter_type, **kwargs)

Or call filter functions explicitly:

The package contains three main filter functions:

wiener_filter(img, delta=5, lowpass=True, lowpass_cutoff=0.3, lowpass_order=2)

abs_filter(img, delta=5, lowpass=True, lowpass_cutoff=0.3, lowpass_order=2)

These are for Wiener filter or average background subtraction filter. It takes img, an image array as an input, and returns the filtered image array and a difference image array. Parameters are the following:

delta: a threashold for background averaging. Smaller number results in more iterations in refining the averaged background and hense longer time.

lowpass: also apply a lowpass filter after filtering to remove the residual high frequency noise.

lowpass_cutoff: a cutoff ratio in frequency domain for the lowpass. 1 means no filtering and vice versa.

lowpass_order: order for the Butterworth filter; smaller int retults more tapered cutoff

nlfilter(img, N=50, delta=10, lowpass_cutoff=0.3, lowpass = True, lowpass_order=2)

This function carries out the nonlinear filter, a combination of Gaussian lowpass and Wiener filters. It takes img, an image array as an input, and returns the filtered image array and a difference image array. Parameters are the following:

N: number of iterations for the lowpass + wiener filtering. More iterations give better noise reduction and takes more time.

lowpass: if True, also applys a Butterworth lowpass filter after the Wiener filtering in every iteration. This prevents from adding back high frequency noise.

All other parameters are the same as in the wiener_filter.

In addition, hrtem_filter also provides two lowpass filters: Butterworth filter and Gaussian filter.

bw_lowpass(img, order, cutoff_ratio)

gaussian_lowpass(img, cutoff_ratio, hp_cutoff_ratio)

Citation

If you use hrtem_filter in your publications, I kindly ask that you cite the following paper:

T. Ma, Python implementation of various denoising filters for HR(S)TEM images, Microscopy and Microanalysis 30 (Suppl 1) (2024) ozae044.213. doi:10.1093/mam/ozae044.213.

Contact

Send your questions and suggestions to Dr. Tao Ma at matao1984@gmail.com

Update History

2025/11/11

  • Updated all filters to accept non-square images
  • Updated all filters to accept image stacks
  • Rewrote the background subtraction algorithm
  • Removed the dependent on Pandas
  • Used numba to speed up the process
  • Wrote a wraper function to apply selected filter on image or stack
  • Modified the gaussian_lowpass function to also take a hp_cutoff_ratio to work as high-pass or band-pass filter

About

A set of python functions to carry out noise filters for high resolution (S)TEM images

Resources

Stars

21 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages