Fourier Interpolation Module

Functions

This module performs fourier interpolation on a single image or a image stack (tiff file). Interpolated image (stack) can be saved into a new tiff file or return as a numpy array.

Fourier interpolation was implemented with transformation matrix operation, where the Fourier transformation matrix was constructed with the original matrix size without interpolation grids, and the inverse Fourier transformation matrix encodes the extra interpolation position coordinates.

Adapted from https://github.com/xiyuyi/xy_fInterp_forTIFF.

pysofi.finterp.fourier_interp_array(im, interp_num_lst)

Performs fourier interpolation on an image array with a list of interpolation factors.

pysofi.finterp.fourier_interp_tiff(filepath, filename, interp_num_lst, frames=[], save_option=True, return_option=False)

Performs fourier interpolation on a tiff image (stack) with a list of interpolation factors (the number of pixels to be interpolated between two adjacent pixels).

Parameters
  • filepath (str) – The path to the tiff file.

  • filename (str) – The filename of the tiff file without ‘.tif’.

  • interp_num_lst (list (int)) – A list of interpolation factors.

  • frames (list of int) – The start and end frame number.

  • save_option (bool) – Whether to save the interpolated images into tiff files (each interpolation factor seperately).

  • return_option (bool) – Whether to return the interpolated image series as 3d arrays.

Returns

interp_imstack_lst – A list of interpolated image series corresponding to the interpolation factor list.

Return type

list (ndarray)

pysofi.finterp.ft_matrix2d(xrange, yrange)

Calculate fourier transform matrix for x- and y-dimension.

pysofi.finterp.ift_matrix2d(xrange, yrange, interp_num)

Calculate inverse fourier transform matrix without center shift for a given fold of interpolation for x- and y-dimension. Here we use 2 times the x-dimension of a frame image for xrange and 2 times of y for yrange. interp_num is the number of times the resolution enhanced. For instance, when interp_num = 2, the resolution is two times the original one.

pysofi.finterp.interpolate_image(im, fx, fy, ifx, ify, interp_num)

Performs fourier interpolation to increase the resolution of the image. The interpolated image can be further processed by SOFI for super-resolution imaging.

Parameters
  • im (ndarray) – Input image.

  • fx (ndarray) – Fourier transform matrix in x generated from ft_matrix2d function.

  • fy (ndarray) – Fourier transform matrix in y generated from ft_matrix2d function.

  • ifx (ndarray) – Inverse fourier transform matrix in x from ift_matrix2d function.

  • ify (ndarray) – Inverse fourier transform matrix in y from ift_matrix2d function.

  • interp_num (int) – The number of pixels to be interpolated between two adjacent pixels.

Returns

interp_im – Interpolated image with new dimensions.

Return type

ndarray

Notes

Please note here that interpolation doesn’ extend over the edgeo f the matrix, therefore the total number of pixels in the resulting matrix is not an integer fold of the original size of the matrix. For example, if the original matrix size of each frame is xdim and ydim for x and y dimensions respectively. After interpolation, the size of the resulting matrix will be ((xdim-1)*f + 1) for x dimension, and ((ydim-1)*f + 1) for y dimension.

Example

import numpy as np
import matplotlib.pyplot as plt
xdim, ydim, sigma, mu = 10, 10, 0.5, 0
x, y = np.meshgrid(np.linspace(-1, 1, xdim), np.linspace(-1, 1, xdim))
im = np.exp(-((np.sqrt(x*x + y*y) - mu)**2 / (2*sigma**2)))
xrange, yrange, interp_num = 2 * xdim, 2 * ydim, 3
fx, fy = ft_matrix2d(xrange, yrange)
ifx, ify = ift_matrix2d(xrange, yrange, interp_num)
interp_im = interpolate_image(im, fx, fy, ifx, ify, interp_num)

Examples

To interpolate a single image and generate two images with different interpolation factors (4 and 6):

im_lst = finterp.fourier_interp_array(im, [4,6])

To insert seven new pixels between adjacent physical pixels for the first 1000 frames of the input video and save the interpolated images in a new tiff video.

finterp.fourier_interp_tiff(filepath, filename, interp_num_lst=[8], frames=[0,1000],
                            save_option=True, return_option=False):