/** * Makes a color {@link Dataset} from an {@link ImagePlus}. Color Datasets have isRgbMerged() * true, channels == 3, and bitsperPixel == 8. Does not populate the data of the returned Dataset. * That is left to other utility methods. Does not set metadata of Dataset. Throws exceptions if * input ImagePlus is not single channel RGB. */ private Dataset makeColorDataset(final ImagePlus imp, final AxisType[] preferredOrder) { final int x = imp.getWidth(); final int y = imp.getHeight(); final int c = imp.getNChannels(); final int z = imp.getNSlices(); final int t = imp.getNFrames(); if (imp.getType() != ImagePlus.COLOR_RGB) { throw new IllegalArgumentException("can't make a color Dataset from a nonRGB ImagePlus"); } if (c != 1) { throw new IllegalArgumentException( "can't make a color Dataset from a multichannel ColorProcessor stack"); } final int[] inputDims = new int[] {x, y, 3, z, t}; final AxisType[] axes = LegacyUtils.orderedAxes(preferredOrder, inputDims); final long[] dims = LegacyUtils.orderedDims(axes, inputDims); final String name = imp.getTitle(); final int bitsPerPixel = 8; final boolean signed = false; final boolean floating = false; final boolean virtual = imp.getStack().isVirtual(); final Dataset ds = datasetService.create(dims, name, axes, bitsPerPixel, signed, floating, virtual); ds.setRGBMerged(true); DatasetUtils.initColorTables(ds); return ds; }
/** * Shift zero-frequency component to centre of dataset * * @param a * @param axes (if null, then shift all axes) * @return shifted dataset */ public static Dataset ifftshift(final Dataset a, int[] axes) { int alen; if (axes == null) { alen = a.getRank(); axes = new int[alen]; for (int i = 0; i < alen; i++) axes[i] = i; } else { alen = axes.length; for (int i = 0; i < alen; i++) axes[i] = a.checkAxis(axes[i]); } Dataset result = a; int[] indices; for (int i = 0; i < alen; i++) { int axis = axes[i]; int n = a.getShapeRef()[axis]; int p = n - (n + 1) / 2; logger.info("Shift {} by {}", axis, p); indices = new int[n]; for (int j = 0; j < n; j++) { if (j < n - p) indices[j] = p + j; else indices[j] = j - n + p; } result = DatasetUtils.take(result, indices, axis); } return result; }
/** * Create a dataset from an object which could be a PySequence, a Java array (of arrays...) or * Number. Ragged sequences or arrays are padded with zeros. * * @param obj * @return dataset with contents given by input */ public static CompoundIntegerDataset createFromObject(final Object obj) { IntegerDataset result = IntegerDataset.createFromObject(obj); // CLASS_TYPE return (CompoundIntegerDataset) DatasetUtils.createCompoundDatasetFromLastAxis(result, true); }
/** * Discrete FFT sample frequencies * * @param n number of samples * @param d sample spacing * @return frequencies */ public static Dataset sampleFrequencies(int n, double d) { int hn = n / 2; return DatasetUtils.roll( DoubleDataset.createRange(n).isubtract(hn).imultiply(1 / (d * n)), n - hn, null); }