Пример #1
0
  /**
   * 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;
  }
Пример #2
0
 public static Dataset makeDataset(final Context context, final byte[][] data, final String name) {
   final int w = data.length;
   final int h = data[0].length;
   final ArrayImg<ByteType, ByteArray> img =
       new ArrayImgFactory<ByteType>().createByteInstance(new long[] {w, h}, 1);
   final ByteType t = new ByteType(img);
   img.setLinkedType(t);
   final RandomAccess<ByteType> ra = img.randomAccess();
   for (int i = 0; i < w; i++) {
     ra.setPosition(i, 0);
     for (int j = 0; j < h; j++) {
       ra.setPosition(j, 1);
       ra.get().set(data[i][j]);
     }
   }
   final DatasetService datasetService = context.getService(DatasetService.class);
   return datasetService.create(new ImgPlus<ByteType>(img, name, new AxisType[] {Axes.X, Axes.Y}));
 }
Пример #3
0
 @Override
 public Dataset createDataset(final String title, final ColorTable colorTable) {
   final Dataset dataset =
       datasetService.create(
           new UnsignedByteType(),
           new long[] {RAMP_WIDTH, RAMP_HEIGHT},
           title,
           new AxisType[] {Axes.X, Axes.Y});
   rampFill(dataset);
   // TODO - is this papering over a bug in the dataset/imgplus code?
   if (dataset.getColorTableCount() == 0) dataset.initializeColorTables(1);
   dataset.setColorTable(colorTable, 0);
   return dataset;
 }