HyperStackReg
An ImageJ/FIJI plugin for the multi-channel Hyperstack alignment (registration)
(released: December 31, 2015)

Movie: A 16-bit multi-channel (blue, green and red) hyperstack before and after HyperStackReg registration. The intravital multiphoton movie shows green and red labeled cells moving in vivo in living mice. Extracellular matrix collagen fibers are shown in blue.

Check out version 5, with new features! (at the end of this page)

Installation
Put HyperStackReg_v04.class in the plugins folder and restart ImageJ. "HyperStackReg_v04" command should be visible under Plugins menu.

Requires
Just like StackReg, HyperStackReg requires that another plugin called TurboReg should be installed. Please follow directions described on the StackReg page.

Source code
HyperStackReg_v04.java

Description
A single channel time-lapse, Z-stack (C=1, Z>=1, T>1) can be aligned using StackReg plugin. HyperStackReg plugin, on the other hand, aligns images in a multi-channel hyperstack (C>1, Z>=1, T>1). The main idea of the HyperStackReg plugin is to apply the same transformation matrix to each channel of a hyperstack, so that all the channels of a hyperstack are registered with respect to each other. Briefly, the plugin works like this:

Step 1: User opens a multi-channel hyperstack
(C>1, Z>=1, T>1) and runs the HyperStackReg_v04 plugin. In a pop-up dialog window, user then selects the transformation type (Translation, Rigid body, Scaled rotation, Affine) and whether the processing details show be shown in the Log window.

Step 2: The plugin duplicates the hyperstack and merges all the
channels into an RGB hyperstack (C=1, Z>=1, T>1).

Step 3: This RGB hyperstack is aligned for each Z and T; and transformation matrices are stored in a text file. RGB hyperstack is closed.

Step 4: Transformation matrices are read from the text file and applied to the first channel (C=1) of the original hyperstack. This process is repeated for all the channels (2nd, 3rd, 4th...so on) of the original hyperstack.

Step 5: All the registered channels are combined into a hyperstack.

Batch processing a folder full of Hyperstacks
Following Macro (also available here) can be used to process all the files ending in a particular extension (e.g. .tif)

// Macro starts here
dirS = getDirectory("Choose source Directory");
dirD = getDirectory("Choose destination Directory");

filenames = getFileList(dirS);
for (i = 0; i < filenames.length; i++) {
    currFile = dirS+filenames[i];
    if(endsWith(currFile, ".tif")) { // process only files ending with .tif
        open(currFile);
        run("HyperStackReg v04", "transformation=Affine show");
//        run("HyperStackReg v05", "transformation=Affine show");
//        run("HyperStackReg v05", "transformation=Affine channel3 channel4 show");
        saveAs("Tiff", dirD+getTitle());
        close(); // close registered file
        close(); // close original file
    }
}
// Macro ends here

Special cases
The supplied image need not be a multi-channel hyperstack. This plugin can also handle the alignment of a single channel, stack/hyperstack:
1. a time-lapse stack (C=1, Z=1, T>1)
2. a Z-stack (C=1, Z>1, T=1)
3. a single channel, multi-slice time-lapse hyperstack (C=1, Z>1, T>1)

Acknowledgements
StackReg and MultiStackReg plugins.

Contact
If you have any questions, please email at:
ved.sharma (at) einstein (dot) yu (dot) edu


HyperStackReg (version 5) (released: June 2, 2016)

What's new

1. User can now choose specific channel(s) for transformation matrix computation. This option is very useful in registering hyperstacks where the intensity of a particular channel changes erratically and therefore that channel needs to be excluded for the correct transformation matrix computation.
2. If user does not select any channel for transformation matrix computation, then plugin gives a warning and proceeds by selecting all the channels
3. Updated messages with more details are now displayed in the Log file during plugin execution.
4. Improved user-interface (UI) layout


Installation
Put HyperStackReg_v05.class in the plugins folder and restart ImageJ. "HyperStackReg_v05" command should be visible under Plugins menu.

Source code
HyperStackReg_v05.java

Description
Step 1: User opens a multi-channel hyperstack (C>1, Z>=1, T>1) and runs the HyperStackReg_v05 plugin. In a pop-up dialog window, user then selects the transformation type and the channels to be used for transformation matrix computation. All the channels are selected, by default.

Step 2: The plugin duplicates the user-selected channels (and the corresponding Z and T frames) into a hyperstack and merges those
channels into an RGB hyperstack (C=1, Z>=1, T>1). No RGB flattening is done, if user selects a single channel for transformation matrix computation (Step 1).

Step 3: The resulting hyperstack is then aligned for each Z and T; and transformation matrices are stored in a text file. The duplicated hyperstack is closed.

Steps 4 and 5: Same as in version 4 (see above)


Batch processing a folder full of Hyperstacks
Same as in version 4, except user can now select the channels to be used for transformation matrix computation. For example,
    run("HyperStackReg v05", "transformation=Affine channel3 channel4 show");
    ... will select channels 3 and 4 of a hyperstack for transformation matrix computation.

To select all the channels of a hyperstack for
transformation matrix computation, user can either enter all the channel names, or drop all of them, i.e. the following two will give the same result:
    run("HyperStackReg v05", "transformation=Affine channel1 channel2 channel3 channel4 show");
    run("HyperStackReg v05", "transformation=Affine show");

Tips for pre-processing Hyperstacks
In a time-lapse hyperstack, if the signal in any of the frames changes dramatically (e.g. signal loss leading to blank frames), then registration might fail for all the subsequent time points. In this case, a successful registration can be achieved by either replacing the problem frame with the previous frame, or deleting it. This can be achieved with the Make Substack... command as described in the example below.

Example
We have a hyperstack with 4 channels, 11 slices and 22 frames. Frame number 14 is the problem frame, which needs to be replaced with frame number 13.
  run("Make Substack...", "channels=1-4 slices=1-11 frames=1-13,13,15-22");

Instead, to remove frame number 14.
  run("Make Substack...", "channels=1-4 slices=1-11 frames=1-13,15-22");