Stack ‘Em Up

In previous posts, we’ve almost taken for granted how Fiji/ImageJ deals with multidimensional data. Whenever you have more than one image, be it a second channel all the way up to massive 5D datasets, you’re dealing with stacks.

This concept is so fundamental, I thought it deserving of it’s own post. Let’s stack ’em up.

A stack is just a linear collection of images. In the example below, let’s assume we have a single-channel, single-slice time course with ‘n’ frames:

2015-10-stacks_01Easy. A single dimension (which can be frames, slices or channels, or none of these if for example, you’re compositing something for a montage) is represented as a linear stack. Thus, if you wanted to delete a time point, you can simply run [ Image > Stacks > Tools > Slice Remover ] and delete, say, the 5th slice.

2015-10-stacks_02Things get (just) a little more complicated when you start to introduce a second dimension.

Hyperstacks

When you have more than one dimension, this is normally displayed as a hyperstack. You can tell if your stack is being displayed as a hyperstack because you will have multiple control bars underneath the image:

2015-10-stacks_06

Note the labels C, Z and ► which denote Channels, Slices and Frames respectively

You might think (as the bars would suggest,) that the images are organised in a matrix. Something like this:

2015-10-stacks_04

But you’d be wrong. The hyperstack is just a convenient way of handling dimensionality. In fact the images are all organised (as with the first example) in a linear fashion:

2015-10-stacks_03The key point here (and indeed for this whole post) is to try and understand the order in which the different dimensions appear.

Travel with me into another dimension…

Not the most original of names, but you can’t fault its accuracy. Every hyperstack and indeed every stack has a property called the “Dimension Order”. This string simply represents in what order the dimensions (slices, frames or channels) are stored. Using our example above, the order would be XYCTZ, denoting that for each time point all of the channels are provided before the next time point begins. Compare this to the same example but in XYTCZ:

2015-10-stacks_09

In XYTCZ, notice how all of the time points for channel 1 (green) come before all of the time points for channel 2 (red)

Of course you can have any permutation of Dimension Order and it won’t (assuming that it’s correct) affect the way your images are displayed.

It’s worth pointing out that one of only a few non-proprietary formats which can store multiple images within one container (video formats aside) is the good old Tagged Image Format (TIF). The Dimension Order (as well as the dimension size) is stored in the file header, so any programs which open TIF stacks know into which dimension the following images should be allocated.

You can usually find out the Dimension Order by running [ Image > Show Info ]. Alternatively, turn the hyperstack back into the stack and manually inspect the order.

You can usually find out the Dimension Order by running [ Image > Show Info ]. Alternatively, turn the hyperstack back into the stack and manually inspect the order.

Why this is good to know

For the most part, this is probably not that important to the end user. It only really becomes relevant when you start manipulating stacks, when it’s crucial. Consider the following stack with 2 channels 3 slices and 5 time points (in XYCZT order):

2015-10-stacks_08

Say for example, you wanted to delete the third slice (z=3) from the stack. In XYCZT order (above) you would need to remove images 5, 6, 11 and 12. If however, the stack is in XYTCZ (below), you would need to remove images 9-12.2015-10-stacks_10

Epilogue: Some Useful Tools for Stack Manipulation

This post has mostly been based on the theory of stacks, but there are some great tools built into Fiji for stack manipulation. This handy graphic from the Fiji website covers some of the basics:

One of the most useful tools that I’ve found for working with stacks is [ Image > Duplicate ]. When dealing with Hyperstacks, extra options appear which let you fully duplicate a stack or substack to a particular range. You can use hyphen-separated ranges as below, or single values (at this point, comma separated lists don’t work).

2015-10-stacks_11

Just remember to check the “Duplicate Hyperstack” box!

Finally, if you have Fiji installed (instead of ImageJ) the Stack Sorter (found at [ Image > Stacks > Tools > Stack Sorter ] ) deserves a mention. It’s a very handy tool for shuffling a few images around, for instance if you want to get several images in order to make a montage.

Advertisements

Comment!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.