package org.bonej.testImages;

import net.imagej.ImgPlus;
import net.imagej.axis.Axes;
import net.imagej.axis.AxisType;
import net.imagej.ops.OpEnvironment;
import net.imglib2.FinalDimensions;
import net.imglib2.img.Img;
import net.imglib2.type.logic.BitType;

/**
 * A utility class to create an ImgPlus that follows the conventions of a hyperstack in ImageJ1.
 * Needed so that the image display correctly (at least in the legacy ui).
 *
 * @author Richard Domander 
 */
public class IJ1ImgPlus {
    public static final int DIMENSIONS = 5;
    public static final int X_DIM = 0;
    public static final int Y_DIM = 1;
    public static final int CHANNEL_DIM = 2;
    public static final int Z_DIM = 3;
    public static final int TIME_DIM = 4;
    public static final AxisType[] IJ1_AXES;

    static {
        IJ1_AXES = new AxisType[DIMENSIONS];
        IJ1_AXES[X_DIM] = Axes.X;
        IJ1_AXES[Y_DIM] = Axes.Y;
        IJ1_AXES[Z_DIM] = Axes.Z;
        IJ1_AXES[CHANNEL_DIM] = Axes.CHANNEL;
        IJ1_AXES[TIME_DIM] = Axes.TIME;
    }

    private IJ1ImgPlus() {}

    public static ImgPlus<BitType> createIJ1ImgPlus(final OpEnvironment ops, String title, final long xSize,
            final long ySize, final long zSize, final long channels, final long frames, final long padding,
            final double scale, final String unit) {
        final long totalPadding = 2 * padding;
        final Img<BitType> img = ops.create().img(
                new FinalDimensions(xSize + totalPadding, ySize + totalPadding,
                                    channels, zSize + totalPadding, frames), new BitType());
        double[] calibration = new double[]{scale, scale, 1.0, scale, 1.0};
        String[] units = new String[]{unit, unit, "", unit, ""};
        return new ImgPlus<>(img, title, IJ1_AXES, calibration, units);
    }
}

@@ -1068,16 +1068,455 @@
 s() %7B%7D%0A%0A
+    /**%0A     * Creates a 5-dimensional ImgPlus%0A     *%0A     * @param title     Name of the image%0A     * @param channels  Number of colour channels%0A     * @param frames    Number of frames%0A     * @param padding   Padding added to width, height & depth (final width = width + 2 * padding)%0A     * @param scale     Scale of calibration in x, y & z%0A     * @param unit      Unit of calibration in x, y & z%0A     * @return An empty ImgPlus%0A     */%0A
     publ
@@ -1609,21 +1609,21 @@
 al long 
-xSize
+width
 ,%0A      
@@ -1639,21 +1639,22 @@
 al long 
-ySize
+height
 , final 
@@ -1658,21 +1658,21 @@
 al long 
-zSize
+depth
 , final 
@@ -1916,13 +1916,13 @@
 ons(
-xSize
+width
  + t
@@ -1938,13 +1938,14 @@
 ng, 
-ySize
+height
  + t
@@ -2007,13 +2007,13 @@
 ls, 
-zSize
+depth
  + t

Add comments