Stack Sorter
 
Author: Bob Dougherty (rpd@optinav.com
Installation: Download Stack_Sorter.jar into the plugins folder and restart ImageJ.  Stack Sorter installs itself into the Plugins>Stacks menu.

ImageJ version 1.32c or later is required.

Source file: The source can be extracted with the command: jar xvf Stack_Sorter.jar
Description: ImageJ plugin to sort the slices of a stack.
Menu: The buttons operate on the front window, which should usually be a stack.   The first four (arrow) buttons reposition a slice within the stack, changing the order of the slices.   "Delete" deletes the current slice, "Duplicate" duplicates the current slice, and "Duplicate n" and "Delete n" duplicate and delete multiple slices.  "Insert" adds a new slice (or stack) from another window and increases the size of the stack.  "Insert File" and "Insert URL" obtain new slice(s) from a disk file or a URL.  Paste (system) takes an image from the system clipboard.  Duplicate, Duplicate n, and the Insert and Paste commands do not require a stack begin with; when used with a single image they will create stacks.  The Insert and Paste buttons will create a new window if necessary.

Insert: Pressing "Insert" produces a dialog box that lets you choose the source image from the available windows. If there are only two windows open, then the dialog is not displayed, since Insert assumes that you want to insert the image from the "other" window.  If the source image has an ROI, then the new slice in the stack will contain only the ROI in the center of the image, with the outside filled with the background color.   It is not necessary for the source image and the destination stack to match in dimensions or type.   If the types do not match, then the values of the inserted pixels may not be the same as the source values.

If the source and destination images match in dimensions, then the ROI is not moved to the center.

If the source ROI to be inserted is larger than the destination image in one or both dimensions, then several options will be presented for adjusting the the source or the destination before the insert operation:

  • Insert a cropped image
  • Insert a reduced size image
  • Resize the destination stack by adding border pixels
  • Resize the destination stack by scaling up the image
The second and fourth options change the size of the pixels in the inserted image and the destination stack, respectively.

If a stack is chosen as the source to insert, then a dialog will ask how many slices to take from the stack, starting with the currently selected slice.

Insert File, Insert URL, and Paste (system) insert images as above.

Whole Stack: "Label Slices" applies sequential labels to all of the slices, replacing any existing labels.  "Sort by Label" sorts the stack by label.  "Sort by Mean" sorts the stack by mean value.  If there is an ROI, then the mean value is measured within the ROI.   Image/Stacks/Plot Z-Axis Profile should give a non-decreasing curve if used after "Sort by Mean."  "Reverse" reverses the stack.  This can be used after "Sort by Label" or "Sort by Mean" to put the slices in decreasing order instead of increasing.

An interesting editing session might be:

  1. Open a stack from some type of sequential measurement.
  2. "Label Slices"
  3. Create an ROI.
  4. "Sort by Mean"
  5. In Analyze/Set Measuements..., check "Display Label."
  6. Analyze/Measure
The Results should effectively list the measurement times (indicated by the applied slice labels) sorted by the magnitude of the result (determined by the mean in the ROI).
Limitations: "Undo" is not supported.
8-bit color images can give strange results due to LUT issues.
"Scaling" is not carefully controlled on "Insert," so the values may not match.
History: Version 0: 3/14/2004
Version 1: 3/15/2004 Added "Insert."
Version 2: 3/16/2004 Updated (by Wayne Rasband) for Mask type in ImageJ v. 1.32c.
Version 3: 3/17/2004 Added Duplicate commands and improved the UI.
Version 4: 3/20/2004 Added type conversions before insert.
Version 5: 3/22/2004 Added size adjustments before insert and stack insertion.
Version 6: 4/2/2004 Added Insert File.
Version 7: 4/2/2004 Added Insert URL and Paste (system).
Version 8: 4/5/2004 Fixed a bug in duplicate and revised delete.
Version 9: 11/18/2005 Added Sort and Reverse
Version 10: 11/18/2005 Added Sort by Mean and Label Slices
Version 11 1/21/2010 Preserve slice label, if any, on insert. Added Edit Label.
Version 12 1/23/2010 Fixed crash in Edit Label if label is null.
Acknowledgements: Some of the code was borrowed from Wayne Rasband's ROI Manager, Filler, and StackEditor.
Thanks to Simon Roussel and Gabriel Landini for testing and feedback.
See also System Clipboard and Stack Plugins.
License:

Copyright (c) 2002, 2005, OptiNav, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of OptiNav, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

ImageJ: ImageJ can be freely downloaded from the ImageJ web site.