/**
  * Assigns the data values of a {@link Dataset} from a paired {@link ImagePlus}. Assumes the
  * Dataset and ImagePlus have compatible dimensions and that the data planes are not directly
  * mapped. Gets values via {@link ImageProcessor}::getf(). In cases where there is a narrowing of
  * data into modern ImageJ types the data is range clamped. Does not change the Dataset's
  * metadata.
  */
 @Override
 public void updateDataset(final Dataset ds, final ImagePlus imp) {
   final RealType<?> type = ds.getType();
   final double typeMin = type.getMinValue();
   final double typeMax = type.getMaxValue();
   final boolean signed16BitData = type instanceof ShortType;
   final RandomAccess<? extends RealType<?>> accessor = ds.getImgPlus().randomAccess();
   final long[] dims = ds.getDims();
   final AxisType[] axes = ds.getAxes();
   final int xIndex = ds.getAxisIndex(Axes.X);
   final int yIndex = ds.getAxisIndex(Axes.Y);
   final int zIndex = ds.getAxisIndex(Axes.Z);
   final int tIndex = ds.getAxisIndex(Axes.TIME);
   final int xSize = imp.getWidth();
   final int ySize = imp.getHeight();
   final int zSize = imp.getNSlices();
   final int tSize = imp.getNFrames();
   final int cSize = imp.getNChannels();
   final ImageStack stack = imp.getStack();
   int planeNum = 1;
   final long[] pos = new long[dims.length];
   for (int t = 0; t < tSize; t++) {
     if (tIndex >= 0) pos[tIndex] = t;
     for (int z = 0; z < zSize; z++) {
       if (zIndex >= 0) pos[zIndex] = z;
       for (int c = 0; c < cSize; c++) {
         LegacyUtils.fillChannelIndices(dims, axes, c, pos);
         final ImageProcessor proc = stack.getProcessor(planeNum++);
         for (int x = 0; x < xSize; x++) {
           if (xIndex >= 0) pos[xIndex] = x;
           for (int y = 0; y < ySize; y++) {
             if (yIndex >= 0) pos[yIndex] = y;
             accessor.setPosition(pos);
             double value = proc.getf(x, y);
             if (signed16BitData) value -= 32768.0;
             if (value < typeMin) value = typeMin;
             else if (value > typeMax) value = typeMax;
             accessor.get().setReal(value);
           }
         }
       }
     }
   }
   ds.update();
 }
    @Override
    public void compute1(
        final IterableInterval<RealType<?>> input, final IterableInterval<RealType<?>> output) {

      Cursor<RealType<?>> inputCursor = input.cursor();
      Cursor<RealType<?>> outputCursor = output.cursor();

      double tmp = 0.0d;
      while (outputCursor.hasNext()) {

        RealType<?> inputValue = inputCursor.next();
        RealType<?> outputValue = outputCursor.next();

        // Compute inputValue^order
        tmp += inputValue.getRealDouble();

        outputValue.setReal(tmp);
      }
    }
Exemple #3
0
 @SuppressWarnings({"rawtypes", "unchecked"})
 private static final NumericType<?> withValue(
     final Img<? extends NumericType<?>> img, final NumericType<?> type, final Number val) {
   final NumericType t = img.firstElement().createVariable();
   if (ARGBType.class.isAssignableFrom(t.getClass())) {
     int i = val.intValue();
     t.set(new ARGBType(i));
   } else {
     ((RealType) t).setReal(val.doubleValue());
   }
   return t;
 }
 @Override
 public RealType<?> compute(ComplexType<?> input, RealType<?> output) {
   output.setReal(input.getRealDouble());
   return output;
 }