@@ -0,0 +1,2159 @@
+package net.imagej.ops.create.img;%0A%0Aimport net.imglib2.Dimensions;%0Aimport net.imglib2.Interval;%0Aimport net.imglib2.img.Img;%0Aimport net.imglib2.img.ImgFactory;%0Aimport net.imglib2.img.ImgView;%0Aimport net.imglib2.type.Type;%0Aimport net.imglib2.view.Views;%0A%0A/**%0A * Utility methods for working with %7B@link Img%7D objects.%0A * %0A * @author Curtis Rueden%0A */%0Apublic final class Imgs %7B%0A%0A%09private Imgs() %7B%0A%09%09// NB: Prevent instantiation of utility class.%0A%09%7D%0A%0A%09/**%0A%09 * Creates an %7B@link Img%7D.%0A%09 *%0A%09 * @param factory The %7B@link ImgFactory%7D to use to create the image.%0A%09 * @param dims The dimensional bounds of the newly created image. If the given%0A%09 *          bounds are an %7B@link Interval%7D, the resultant %7B@link Img%7D will%0A%09 *          have the same min/max as that %7B@link Interval%7D as well (see%0A%09 *          %7B@link #adjustMinMax%7D for details).%0A%09 * @param type The component type of the newly created image.%0A%09 * @return the newly created %7B@link Img%7D%0A%09 */%0A%09public static %3CT extends Type%3CT%3E%3E Img%3CT%3E create(final ImgFactory%3CT%3E factory,%0A%09%09final Dimensions dims, final T type)%0A%09%7B%0A%09%09return Imgs.adjustMinMax(factory.create(dims, type), dims);%0A%09%7D%0A%0A%09/**%0A%09 * Adjusts the given %7B@link Img%7D to match the bounds of the specified%0A%09 * %7B@link Interval%7D.%0A%09 * %0A%09 * @param img An image whose min/max bounds might need adjustment.%0A%09 * @param minMax An %7B@link Interval%7D whose min/max bounds to use when%0A%09 *          adjusting the image. If the provided %7B@code minMax%7D object is not%0A%09 *          an %7B@link Interval%7D, no adjustment is performed.%0A%09 * @return A wrapped version of the input %7B@link Img%7D with bounds adjusted to%0A%09 *         match the provided %7B@link Interval%7D, if any; or the input image%0A%09 *         itself if no adjustment was needed/possible.%0A%09 */%0A%09public static %3CT extends Type%3CT%3E%3E Img%3CT%3E adjustMinMax(final Img%3CT%3E img,%0A%09%09final Object minMax)%0A%09%7B%0A%09%09if (!(minMax instanceof Interval)) return img;%0A%09%09final Interval interval = (Interval) minMax;%0A%0A%09%09final long%5B%5D min = new long%5Binterval.numDimensions()%5D;%0A%09%09interval.min(min);%0A%09%09for (int d = 0; d %3C min.length; d++) %7B%0A%09%09%09if (min%5Bd%5D != 0) %7B%0A%09%09%09%09return ImgView.wrap(Views.translate(img, min), img.factory());%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return img;%0A%09%7D%0A%0A%7D%0A

Add a utility class for working with Imgs