diff --git a/.travis/settings.xml b/.travis/settings.xml
index 71a56300a7..e9b968031a 100644
--- a/.travis/settings.xml
+++ b/.travis/settings.xml
@@ -1,14 +1,14 @@
-
-
-
- imagej.releases
- travis
- ${env.MAVEN_PASS}
-
-
- imagej.snapshots
- travis
- ${env.MAVEN_PASS}
-
-
-
+
+
+
+ imagej.releases
+ travis
+ ${env.MAVEN_PASS}
+
+
+ imagej.snapshots
+ travis
+ ${env.MAVEN_PASS}
+
+
+
diff --git a/images/readme.txt b/images/readme.txt
index 6665775bff..efae6e5fbc 100644
--- a/images/readme.txt
+++ b/images/readme.txt
@@ -1,3 +1,3 @@
-These images go with the toplevel README.md file.
-
-They are documentation, and not necessary for ImageJ Ops to function.
+These images go with the toplevel README.md file.
+
+They are documentation, and not necessary for ImageJ Ops to function.
diff --git a/src/main/java/net/imagej/ops/create/CreateNamespace.java b/src/main/java/net/imagej/ops/create/CreateNamespace.java
index e0a82af555..c87e1e912a 100644
--- a/src/main/java/net/imagej/ops/create/CreateNamespace.java
+++ b/src/main/java/net/imagej/ops/create/CreateNamespace.java
@@ -52,6 +52,7 @@
import net.imglib2.type.numeric.IntegerType;
import net.imglib2.type.numeric.complex.ComplexDoubleType;
import net.imglib2.type.numeric.complex.ComplexFloatType;
+import net.imglib2.type.numeric.integer.ByteType;
import net.imglib2.type.numeric.real.DoubleType;
import net.imglib2.type.numeric.real.FloatType;
@@ -107,6 +108,350 @@ public Img img(final int[] dims) {
public Img img(final long[] dims) {
return img(new FinalDimensions(dims), new DoubleType());
}
+
+ // -- from array
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Bit.class)
+ public > Img bitArrayImg(final long[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Bit.class)
+ public > Img bitPlanarImg(final long[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Uint2.class)
+ public > Img uint2ArrayImg(final long[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Uint2.class)
+ public > Img uint2PlanarImg(final long[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Uint4.class)
+ public > Img uint4ArrayImg(final long[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Uint4.class)
+ public > Img uint4PlanarImg(final long[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Uint8.class)
+ public > Img uint8ArrayImg(final byte[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Uint8.class)
+ public > Img uint8PlanarImg(final byte[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Int8.class)
+ public > Img int8ArrayImg(final byte[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Int8.class)
+ public > Img int8PlanarImg(final byte[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Uint16.class)
+ public > Img uint16ArrayImg(final short[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Uint16.class)
+ public > Img uint16PlanarImg(final short[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Int16.class)
+ public > Img int16ArrayImg(final short[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Int16.class)
+ public > Img int16PlanarImg(final short[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Uint32.class)
+ public > Img uint32ArrayImg(final int[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Uint32.class)
+ public > Img uint32PlanarImg(final int[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Int32.class)
+ public > Img int32ArrayImg(final int[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Int32.class)
+ public > Img int32PlanarImg(final int[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Uint64.class)
+ public > Img uint64ArrayImg(final long[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Uint64.class)
+ public > Img uint64PlanarImg(final long[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Int64.class)
+ public > Img int64ArrayImg(final long[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Int64.class)
+ public > Img int64PlanarImg(final long[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Uint128.class)
+ public > Img uint128ArrayImg(final long[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Uint128.class)
+ public > Img uint128PlanarImg(final long[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Uint12.class)
+ public > Img uint12ArrayImg(final long[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Uint12.class)
+ public > Img uint12PlanarImg(final long[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.ARGB32.class)
+ public > Img ARGBArrayImg(final int[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.ARGB32.class)
+ public > Img ARGBPlanarImg(final int[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.UintVarLen.class)
+ public > Img uintVarLenArrayImg(final long[] in,
+ final Dimensions dim, final int nBits)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim, nBits);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.UintVarLen.class)
+ public > Img uintVarLenPlanarImg(final long[][] in,
+ final Dimensions dim, final int nBits)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim, nBits);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Float.class)
+ public > Img floatArrayImg(final float[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Float.class)
+ public > Img doublePlanarImg(final float[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreateArrayImgFromArray.Double.class)
+ public > Img doubleArrayImg(final double[] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ @OpMethod(op = net.imagej.ops.create.img.CreatePlanarImgFromArray.Double.class)
+ public > Img doublePlanarImg(final double[][] in,
+ final Dimensions dim)
+ {
+ @SuppressWarnings("unchecked")
+ final Img result = (Img) ops().run(
+ Ops.Create.Img.class, in, dim);
+ return result;
+ }
+
+ // --
@OpMethod(op = net.imagej.ops.create.img.CreateImgFromDimsAndType.class)
public > Img img(final Dimensions in1,
diff --git a/src/main/java/net/imagej/ops/create/img/CreateArrayImgFromArray.java b/src/main/java/net/imagej/ops/create/img/CreateArrayImgFromArray.java
new file mode 100644
index 0000000000..bd631e30f4
--- /dev/null
+++ b/src/main/java/net/imagej/ops/create/img/CreateArrayImgFromArray.java
@@ -0,0 +1,285 @@
+/*
+ * #%L
+ * ImageJ software for multidimensional image processing and analysis.
+ * %%
+ * Copyright (C) 2014 - 2017 ImageJ developers.
+ * %%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * 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 HOLDERS 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.
+ * #L%
+ */
+
+package net.imagej.ops.create.img;
+
+import java.lang.reflect.Array;
+import org.scijava.Priority;
+import org.scijava.plugin.Parameter;
+import org.scijava.plugin.Plugin;
+
+import net.imagej.ops.Contingent;
+import net.imagej.ops.Ops;
+import net.imagej.ops.special.function.AbstractUnaryFunctionOp;
+import net.imglib2.Dimensions;
+import net.imglib2.img.Img;
+import net.imglib2.img.array.ArrayImg;
+import net.imglib2.img.array.ArrayImgs;
+import net.imglib2.img.basictypeaccess.array.LongArray;
+import net.imglib2.type.NativeType;
+import net.imglib2.type.logic.BitType;
+import net.imglib2.type.numeric.ARGBType;
+import net.imglib2.type.numeric.integer.*;
+import net.imglib2.type.numeric.real.DoubleType;
+import net.imglib2.type.numeric.real.FloatType;
+
+/**
+ * Create an {@link ArrayImg} from an array using its type
+ * {@code T}.
+ *
+ * @author Dasong Gao
+ */
+@SuppressWarnings("deprecation")
+public class CreateArrayImgFromArray {
+
+ // hide constructor
+ private CreateArrayImgFromArray() {
+
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Bit extends FromArray {
+
+ @Override
+ protected void updateEPE() { elementsPerPixel = 1 / 64f; }
+
+ @Override
+ public Img asArrayImg(long[] in) {
+ return ArrayImgs.bits(new LongArray(in), this.imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint2 extends FromArray {
+
+ @Override
+ protected void updateEPE() { elementsPerPixel = 2 / 64f; }
+
+ @Override
+ public Img asArrayImg(long[] in) {
+ return ArrayImgs.unsigned2Bits(new LongArray(in), this.imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint4 extends FromArray {
+
+ @Override
+ protected void updateEPE() { elementsPerPixel = 4 / 64f; }
+
+ @Override
+ public Img asArrayImg(long[] in) {
+ return ArrayImgs.unsigned4Bits(new LongArray(in), this.imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Int8 extends FromArray {
+
+ @Override
+ public Img asArrayImg(byte[] in) {
+ return ArrayImgs.bytes(in, this.imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint8 extends FromArray {
+
+ @Override
+ public Img asArrayImg(byte[] in) {
+ return ArrayImgs.unsignedBytes(in, this.imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint12 extends FromArray {
+
+ @Override
+ protected void updateEPE() { elementsPerPixel = 12 / 64f; }
+
+ @Override
+ public Img asArrayImg(long[] in) {
+ return ArrayImgs.unsigned12Bits(new LongArray(in), this.imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Int16 extends FromArray {
+
+ @Override
+ public Img asArrayImg(short[] in) {
+ return ArrayImgs.shorts(in, imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint16 extends FromArray {
+
+ @Override
+ public Img asArrayImg(short[] in) {
+ return ArrayImgs.unsignedShorts(in, imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Int32 extends FromArray {
+
+ @Override
+ public Img asArrayImg(int[] in) {
+ return ArrayImgs.ints(in, imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint32 extends FromArray {
+
+ @Override
+ public Img asArrayImg(int[] in) {
+ return ArrayImgs.unsignedInts(in, imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class ARGB32 extends FromArray {
+
+ @Override
+ public Img asArrayImg(int[] in) {
+ return ArrayImgs.argbs(in, imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Int64 extends FromArray {
+
+ @Override
+ public Img asArrayImg(long[] in) {
+ return ArrayImgs.longs(in, imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint64 extends FromArray {
+
+ @Override
+ public Img asArrayImg(long[] in) {
+ return ArrayImgs.unsignedLongs(in, imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint128 extends FromArray {
+
+ @Override
+ protected void updateEPE() { elementsPerPixel = 128 / 64f; }
+
+ public Img asArrayImg(long[] in) {
+ return ArrayImgs.unsigned128Bits(new LongArray(in), imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class UintVarLen extends FromArray {
+
+ // number of bits of the number
+ @Parameter(required = true)
+ private int nBits;
+
+ @Override
+ protected void updateEPE() { elementsPerPixel = nBits / 64f; }
+
+ @Override
+ public Img asArrayImg(long[] in) {
+ return ArrayImgs.unsignedVariableBitLengths(new LongArray(in), nBits, imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Float extends FromArray {
+
+ @Override
+ public Img asArrayImg(float[] in) {
+ return ArrayImgs.floats(in, this.imgDims);
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Double extends FromArray {
+
+ @Override
+ public Img asArrayImg(double[] in) {
+ return ArrayImgs.doubles(in, this.imgDims);
+ }
+ }
+
+ // helper class for wrapping
+ private static abstract class FromArray>
+ extends AbstractUnaryFunctionOp>
+ implements Ops.Create.Img, Contingent {
+
+ // image dimensions
+ @Parameter(required = true)
+ private Dimensions dims;
+
+ // image dimensions (unpacked from dims)
+ protected long[] imgDims;
+
+ // used to scale for Bit, 12Bit, 128Bit, varBit, etc.
+ protected float elementsPerPixel = 1.0f;
+
+ @Override
+ public Img calculate(final I inArray) {
+ return this.asArrayImg((I)inArray);
+ }
+
+ @Override
+ public boolean conforms() {
+ updateEPE();
+ imgDims = new long[dims.numDimensions()];
+ if (imgDims.length == 0)
+ return false;
+ int numPixel = 1;
+ for (int i = 0; i < imgDims.length; i++)
+ numPixel *= imgDims[i] = dims.dimension(i);
+
+ I in = this.in();
+ return in.getClass().isArray() && numPixel != 0
+ && (int) Math.ceil((numPixel * elementsPerPixel)) == Array.getLength(in);
+ }
+
+ @Override
+ public Img run(Img output) {
+ return null;
+ }
+
+ protected abstract Img asArrayImg(I in);
+
+ // update entitiesPerElement before checking size
+ protected void updateEPE() {};
+ }
+}
diff --git a/src/main/java/net/imagej/ops/create/img/CreatePlanarImgFromArray.java b/src/main/java/net/imagej/ops/create/img/CreatePlanarImgFromArray.java
new file mode 100644
index 0000000000..d6433d19cd
--- /dev/null
+++ b/src/main/java/net/imagej/ops/create/img/CreatePlanarImgFromArray.java
@@ -0,0 +1,377 @@
+/*
+ * #%L
+ * ImageJ software for multidimensional image processing and analysis.
+ * %%
+ * Copyright (C) 2014 - 2017 ImageJ developers.
+ * %%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * 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 HOLDERS 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.
+ * #L%
+ */
+
+package net.imagej.ops.create.img;
+
+import java.lang.reflect.Array;
+import org.scijava.Priority;
+import org.scijava.plugin.Parameter;
+import org.scijava.plugin.Plugin;
+
+import net.imagej.ops.Contingent;
+import net.imagej.ops.Ops;
+import net.imagej.ops.special.function.AbstractUnaryFunctionOp;
+import net.imglib2.Dimensions;
+import net.imglib2.img.Img;
+import net.imglib2.img.basictypeaccess.array.ByteArray;
+import net.imglib2.img.basictypeaccess.array.DoubleArray;
+import net.imglib2.img.basictypeaccess.array.FloatArray;
+import net.imglib2.img.basictypeaccess.array.IntArray;
+import net.imglib2.img.basictypeaccess.array.LongArray;
+import net.imglib2.img.basictypeaccess.array.ShortArray;
+import net.imglib2.img.planar.PlanarImg;
+import net.imglib2.img.planar.PlanarImgFactory;
+import net.imglib2.type.NativeType;
+import net.imglib2.type.logic.BitType;
+import net.imglib2.type.numeric.ARGBType;
+import net.imglib2.type.numeric.integer.*;
+import net.imglib2.type.numeric.real.DoubleType;
+import net.imglib2.type.numeric.real.FloatType;
+
+/**
+ * Create an {@link PlanarImg} from an array using its type
+ * {@code T}. The first two dimensions (first one if it is
+ * the only dimension) in parameter dims are used as sizes
+ * of planes. Any other dimensions are flattened to produce
+ * a list of planar slices.
+ *
+ * @author Dasong Gao
+ */
+@SuppressWarnings("unchecked")
+public class CreatePlanarImgFromArray {
+
+ // hide constructor
+ private CreatePlanarImgFromArray() {
+
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Bit extends FromArray {
+
+ @Override
+ protected void updateEPE() { elementsPerPixel = 1 / 64f; }
+
+ @Override
+ public Img asPlanarImg(long[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new BitType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new LongArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint2 extends FromArray {
+
+ @Override
+ protected void updateEPE() { elementsPerPixel = 2 / 64f; }
+
+ @Override
+ public Img asPlanarImg(long[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new Unsigned2BitType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new LongArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint4 extends FromArray {
+
+ @Override
+ protected void updateEPE() { elementsPerPixel = 4 / 64f; }
+
+ @Override
+ public Img asPlanarImg(long[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new Unsigned4BitType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new LongArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Int8 extends FromArray {
+
+ @Override
+ public Img asPlanarImg(byte[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new ByteType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new ByteArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint8 extends FromArray {
+
+ @Override
+ public Img asPlanarImg(byte[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new UnsignedByteType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new ByteArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint12 extends FromArray {
+
+ @Override
+ protected void updateEPE() { elementsPerPixel = 12 / 64f; }
+
+ @Override
+ public Img asPlanarImg(long[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new Unsigned12BitType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new LongArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Int16 extends FromArray {
+
+ @Override
+ public Img asPlanarImg(short[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new ShortType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new ShortArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint16 extends FromArray {
+
+ @Override
+ public Img asPlanarImg(short[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new UnsignedShortType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new ShortArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Int32 extends FromArray {
+
+ @Override
+ public Img asPlanarImg(int[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new IntType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new IntArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint32 extends FromArray {
+
+ @Override
+ public Img asPlanarImg(int[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new UnsignedIntType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new IntArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class ARGB32 extends FromArray {
+
+ @Override
+ public Img asPlanarImg(int[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new ARGBType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new IntArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Int64 extends FromArray {
+
+ @Override
+ public Img asPlanarImg(long[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new LongType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new LongArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint64 extends FromArray {
+
+ @Override
+ public Img asPlanarImg(long[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new UnsignedLongType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new LongArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Uint128 extends FromArray {
+
+ @Override
+ protected void updateEPE() { elementsPerPixel = 128 / 64f; }
+
+ public Img asPlanarImg(long[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new Unsigned128BitType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new LongArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class UintVarLen extends FromArray {
+
+ // number of bits of the number
+ @Parameter(required = true)
+ private int nBits;
+
+ @Override
+ protected void updateEPE() { elementsPerPixel = nBits / 64f; }
+
+
+ @Override
+ public Img asPlanarImg(long[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims,
+ new UnsignedVariableBitLengthType(nBits));
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new LongArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Float extends FromArray {
+
+ @Override
+ public Img asPlanarImg(float[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new FloatType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new FloatArray(in[i]));
+ return output;
+ }
+ }
+
+ @Plugin(type = Ops.Create.Img.class, priority = Priority.HIGH_PRIORITY)
+ public static class Double extends FromArray {
+
+ @Override
+ public Img asPlanarImg(double[][] in) {
+ PlanarImg output =
+ (PlanarImg) factory.create(imgDims, new DoubleType());
+ for (int i = 0; i < in.length; i++)
+ output.setPlane(i, new DoubleArray(in[i]));
+ return output;
+ }
+ }
+
+ // helper class for wrapping
+ private static abstract class FromArray>
+ extends AbstractUnaryFunctionOp>
+ implements Ops.Create.Img, Contingent {
+
+ // image dimensions
+ @Parameter(required = true)
+ private Dimensions dims;
+
+ // image dimensions (unpacked from dims)
+ protected long[] imgDims;
+
+ // used to scale for Bit, 12Bit, 128Bit, varBit, etc.
+ protected float elementsPerPixel = 1.0f;
+
+ protected PlanarImgFactory factory = new PlanarImgFactory();
+
+ @Override
+ public Img calculate(final I[] inArray) {
+ return this.asPlanarImg(inArray);
+ }
+
+ @Override
+ public boolean conforms() {
+ updateEPE();
+ imgDims = new long[dims.numDimensions()];
+ if (imgDims.length == 0)
+ return false;
+ int numPlane = 1;
+ for (int i = 0; i < imgDims.length; i++) {
+ imgDims[i] = dims.dimension(i);
+ if (i >= 2)
+ numPlane *= imgDims[i];
+ }
+
+ I[] in = this.in();
+
+ int sliceSize = (int) imgDims[0];
+ if (imgDims.length >= 2)
+ sliceSize *= imgDims[1];
+ // number of array elements for a single plane
+ int elementsPerPlane = (int) Math.ceil(sliceSize * elementsPerPixel);
+ for (Object i : in) {
+ if (!i.getClass().isArray() || Array.getLength(i) != elementsPerPlane)
+ return false;
+ }
+ return in.length == numPlane;
+ }
+
+ @Override
+ public Img run(Img