Skip to content

ImageStack

ehennestad edited this page Oct 25, 2022 · 2 revisions

Introduction

The ImageStack is a class for representing 2D to 5D image arrays, from individual grayscale images to multichannel volumetric timeseries stacks. The idea of the ImageStack is that it provides properties and methods for interacting with multidimensional stacks from different sources in a unified manner. For example, images from different two-photon microscopes can be saved in a myriad of ways, from each frame saved to individual tiff files (PrairieView), to frames saved in interleaved Tiff stacks (ScanImage), to frames saved in 1D binary files (SciScan).

Also, different systems orders the dimensions of the image stacks differently. For example, the channel (C) dimension (pixel color) might be placed on the first dimension, or on the third dimension. Some 2P scanning system saves the X-axis along the first data dimension, others saves the Y-axis along the first data dimension. Time (T) and depth (Z) might also be saved in different orders.

The ImageStack takes care of all that and will by default provide a stack in the order of YXCZT. If some dimensions are missing, the ImageStack is squeezed along those dimensions, so a 3D timeseries stack would be represented as YXT. It is also possible to choose to represent the stack in any way you want. To rearrange the way the stack is represented, simply manipulate the DimensionOrder property. For example, imageStackObj.DimensionOrder = 'XYCTZ' would permute the X- and Y- axis of the images and also reorder time (T) and depth (Z).

This makes the ImageStack very well suited as a general object to build processing methods on top of. One of the biggest challenges of building new image processing methods is the big variability in how different systems save images, and the need to provide different file readers and writers to reach a wide user base.

ImageStacks can easily be created either using matlab arrays or using data saved in files. When ImageStacks are created from files, the data is represented using virtual stacks, so data is only loaded from the file on request. Data can be accessed either by using a method called getFrameSet or by indexing the Data property directly as any other matlab array. The following section provides a list of supported file types.

Supported file formats

ScanImage

Text coming

SciScan

Text coming

PrairieView

Text coming

Suite2P output

Text coming

NWB files

In development

General multi-part tiff stacks

Text coming

H5 files

Text coming

Video files

Text coming

Viewing ImageStacks in imviewer

ImageStacks can be visualised in the imviewer app. Imviewer lets you scroll through both time (T) and depth (Z) dimensions and also lets you turn on and off individual color channels. It is also possible to show projections along the T (or Z) dimensions and to apply moving frame binning or filters. It is also straight forward to add custom projection calculations or filtering methods. Furthermore, it also comes with some plugins for doing motion correction and managing rois. The imviewer is a good candidate for providing an ImageJ(Fiji)-like experience to MATLAB. A page describing the imviewer in more detail will be added soon.

ImageStackProcessor

The ImageStackProcessor can be used as a general framework for creating new processing methods for ImageStacks. The ImageStackProcessor is a template-based method where the actual implementation of an algorithm is created using subclasses and where the ImageStackProcessor takes care of all the organization, like individual processing of channels and planes or subdividing the ImageStack in multiple parts if the ImageStack is too large for the computer memory. A guide for the ImageStackProcessor will come at some point, but if you are interested in developing methods, you can look at the nansen.processing.MotionCorrection or nansen.processing.AutoSegmentation to get started, and also don't hesitate to get in touch for assistance.

Building custom virtual stack file adapters

It is fairly straight forward to develop custom file adapters for creating virtual stacks. Nansen contains an abstract class called nansen.stack.data.VirtualArray which can be subclassed in order to create custom virtual stacks. See the VirtualArray class or any of the concrete implementations listed above in order to develop custom virtual stacks. It is also possible to create an issue or get in contact for help with this!