The “PysofiData()” class¶
The PysofiData class is the fundamental data container that carries the measurement data and pysofi-related properties and behaviors. User-defined parameters and intermediate results are bundled to the PysofiData object as attributes as well as processing steps as methods. The full SOFI 2.0 analysis pipeline can be achieved based on multiple PysofiData methods. Each processing step is connected to a separate outside module supported by pysofi, and can be utilized not only by pysofi, but also by other computational imaging developers for similar purposes.
Attributes and Methods¶
- class pysofi.pysofi.PysofiData(filepath, filename)¶
Bases:
object
Data object contains the information of a dataset (e.g. dimensions, frame numbers), and provides SOFI methods to perform analysis and visualization on the dataset (moments reconstruction, cumulants reconstruction, shrinking kernel deconvolution, etc…).
When loading a tiff file, a PysofiData() object is created and further SOFI analysis can be preformed. All the standard data-attributes are listed below. New data-attributes can be added or updated using ‘.add()’ function.
- Parameters
filapath (str) – Path to the tiff file.
filename (str) – Name of the tiff file.
- filename¶
- Type
str
- filepath¶
- Type
str
- ave¶
The average image of the image stack / tiff video.
- Type
ndarray
- finterp_factor¶
The interpolation factor for Fourier interpolation.
- Type
int
- morder_lst¶
All orders of moments-reconstructions that have been calculated.
- Type
list
- morder_finterp_lst¶
All orders of moments-reconstructions after Fourier interpolation that have been calculated.
- Type
list
- moments_set¶
moment order (int) -> moment-reconstructed image (ndarray) A dictionary of orders and corrensponding moment reconstructions.
- Type
dict
- moments_set_bc¶
moment order (int) -> moment-reconstructed image (ndarray) A dictionary of orders and corrensponding moment reconstructions with bleaching correction.
- Type
dict
- cumulants_set¶
cumulant order (int) -> cumulant-reconstructed image (ndarray) A dictionary of orders and corrensponding cumulant reconstructions.
- Type
dict
- cumulants_set_bc¶
cumulant order (int) -> cumulant-reconstructed image (ndarray) A dictionary of orders and corrensponding cumulant reconstructions with bleaching correction.
- Type
dict
- morder¶
The highest order of moment reconstruction that has been calculated.
- Type
int
- corder¶
The highest order of cumulant reconstruction that has been calculated.
- Type
int
- fbc¶
Bleaching correction factor.
- Type
float
- n_frames¶
The number of frames of the image stack / tiff video.
- Type
int
- xdim¶
The number of pixels in x dimension.
- Type
int
- ydim¶
The number of pixels in y dimension.
- Type
int
Notes
For SOFI processing, after loading the tiff video into the Data object, a pipeline of 1) fourier interpolation, 2) moments reconstrtuction or cumulants reconstruction, 3) noise filtering 1, 4) shrinking kernel de- convolution, 5) noise filtering 2, and 6) ldrc. The processed video will be saved into a new tiff file with the colormap user selects.
References
- 1
Xiyu Yi, Sungho Son, Ryoko Ando, Atsushi Miyawaki, and Shimon Weiss,
“Moments reconstruction and local dynamic range compression of high order superresolution optical fluctuation imaging,” Biomed. Opt. Express 10, 2430-2445 (2019).
- add(**kwargs)¶
Add or update elements (attributes and/or dict entries).
- add_filtered(image, filter_name='noise filter')¶
Add (noise) filtered image as an attribute of the object.
- average_image(frames=[])¶
Calculate average image of the tiff video.
- average_image_with_finterp(interp_num)¶
- bleach_correct(fbc=0.04, smooth_kernel=251, save_option=True, return_option=False)¶
Performs bleaching correction on a tiff image (stack) with a bleaching correction factor.
- Parameters
fbc (float) – The fraction of signal decrease within each block compared to the total signal decrease. Only used when bleach correction is True.
smooth_kernel (int) – The size of the median filter window.
save_option (bool) – Whether to save the corrected images into tiff files.
return_option (bool) – Whether to return the corrected image series as a 3d array.
- Returns
bc_im – All bleaching-corrected imagee in a 3d array.
- Return type
ndarray
- calc_moments_set(highest_order=4, frames=[], mean_im=None, bleach_correction=False, smooth_kernel=251, fbc=0.04)¶
Calculate moment-reconstructed images to the highest order.
- Parameters
highest_order (int) – The highest order number of moment-reconstructed images.
frames (list of int) – The start and end frame number.
mean_im (ndarray) – Average image of the tiff stack.
bleach_correction (bool) – Whether to use bleaching correction.
smooth_kernel (int, optional) – The size of the median filter window. Only used when bleach correction is True.
fbc (float, optional) – The fraction of signal decrease within each block compared to the total signal decrease. Only used when bleach correction is True.
- Returns
moments_set, moments_set_bc – order number (int) -> image (ndarray) A dictionary of calcualted moment-reconstructed images.
- Return type
dict
- cumulants_images(highest_order=4, frames=[], m_set=None, bleach_correction=False, smooth_kernel=251, fbc=0.04)¶
Calculate cumulant-reconstructed images to the highest order.
- Parameters
highest_order (int) – The highest order number of cumulant-reconstructed images.
frames (list of int) – The start and end frame number.
m_set (dict) – order number (int) -> image (ndarray) A dictionary of calcualted moment-reconstructed images.
bleach_correction (bool) – Whether to use bleaching correction.
smooth_kernel (int, optional) – The size of the median filter window. Only used when bleach correction is True.
fbc (float, optional) – The fraction of signal decrease within each block compared to the total signal decrease. Only used when bleach correction is True.
- Returns
cumulants_set, cumulants_set_bc – order number (int) -> image (ndarray) A dictionary of calcualted cumulant-reconstructed images.
- Return type
dict
- deconvsk(est_psf=array([[0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0], ..., [0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, ..., 0.0, 0.0, 0.0]]), input_im=None, deconv_lambda=1.5, deconv_iter=20)¶
Perform serial Richardson-Lucy deconvolution with a series of PSFs on the input image. For details of shrinking kernel deconvolution, refer to deconvsk.py and [1].
- Parameters
est_psf (ndarray) – Estimated PSF.
input_im (ndarray) – Input image that need deconvolution.
deconv_lambda (float) – Lambda for the exponent between. It is an empirical parameter within the range of (1,2).
deconv_iter (int) – Number of iterations for each deconvolution.
- Returns
deconv – Deconvoluted image.
- Return type
ndarray
- finterp_image(input_im=None, interp_num_lst=[2, 4])¶
Performs fourier interpolation on an image array.
- finterp_tiffstack(interp_num_lst=[2, 4], 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
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
finterps – A list of interpolated image sereis corresponding to the interpolation factor list.
- Return type
list (ndarray)
- get_dims()¶
Get dimensions and frame number of the tiff video.
- get_frame(frame_num=0)¶
Get one frame of the tiff video.
- Parameters
frame_num (int) – The frame number (e.g. 0 for the first frame).
- Returns
frame_im – Frame array.
- Return type
ndarray
- ldrc(order=6, window_size=[25, 25], mask_im=None, input_im=None)¶
Compress the dynamic range of moments-/cumulants reconstruced image with ldrc method. For details of ldrc, refer to ldrc.py and [1].
- Parameters
order (int) – The order of the reconstructed image.
window_size ([int, int]) – The [x, y] dimension of the scanning window.
mask_im (ndarray) – A reference image. Usually a average/sum image or second-order SOFI image is used.
input_im (ndarray) – An input image, usually a high-order moment- or cumulant- reconstructed image.
- Returns
ldrc_image – The compressed image with the same dimensions of input_im.
- Return type
ndarray
- moment_image(order=6, mean_im=None, mvlength=[], finterp=False, interp_num=1)¶
Calculate the moment-reconstructed image of a defined order.
- Parameters
order (int) – The order number of the moment-reconstructed image.
mean_im (ndarray) – Average image of the tiff stack.
mvlength (int) – Length of the video to calculate moments-reconstruction.
finterp (bool) – Whether to first conduct Fourier interpolation then calculate moments-reconstructions.
interp_num (int) – The interpolation factor.
- Returns
moment_im – The calculated moment-reconstructed image.
- Return type
ndarray
Load Data¶
The simulated or experimental measurements can be loaded into the pysofi.PysofiData object using:
d = pysofi.PysofiData(filepath, filename)