Example #1
0
 public static final <T extends RealType<T>> void addGaussianNoiseToImage(
     RandomAccessibleInterval<T> img, double sigma_noise) {
   IterableInterval<T> iterImg = Views.iterable(img);
   Cursor<T> lc = iterImg.localizingCursor();
   double val;
   T var = iterImg.firstElement().createVariable();
   while (lc.hasNext()) {
     lc.fwd();
     val = Math.max(0, sigma_noise * ran.nextGaussian());
     var.setReal(val);
     lc.get().add(var);
   }
 }
Example #2
0
  @Override
  public void compute1(final IterableInterval<I> input, final O output) {

    double moment10 = 0;

    final Cursor<I> cur = input.localizingCursor();
    while (cur.hasNext()) {
      cur.fwd();
      double x = cur.getDoublePosition(0);
      double val = cur.get().getRealDouble();
      moment10 += x * val;
    }

    output.setReal(moment10);
  }
  @Override
  public void compute(final RandomAccessibleInterval<T> input, final IterableInterval<V> output) {
    final Cursor<V> cursor = output.localizingCursor();
    final RandomAccess<T> access = input.randomAccess();

    while (cursor.hasNext()) {
      cursor.fwd();
      for (int d = 0; d < input.numDimensions(); d++) {
        if (d != dim) {
          access.setPosition(cursor.getIntPosition(d - d > dim ? -1 : 0), d);
        }
      }

      method.compute(new DimensionIterable(input.dimension(dim), access), cursor.get());
    }
  }
Example #4
0
 public static final <T extends RealType<T>> void addGaussianSpotToImage(
     RandomAccessibleInterval<T> img, double[] params) {
   IterableInterval<T> iterImg = Views.iterable(img);
   Cursor<T> lc = iterImg.localizingCursor();
   int nDims = img.numDimensions();
   double[] position = new double[nDims];
   double val;
   T var = iterImg.firstElement().createVariable();
   while (lc.hasNext()) {
     lc.fwd();
     lc.localize(position);
     val = gaussian.val(position, params);
     var.setReal(val);
     lc.get().add(var);
   }
 }
  @Override
  public RealSum call() throws Exception {
    final Cursor<FloatType> psiCursor = psiIterable.localizingCursor();
    psiCursor.jumpFwd(portion.getStartPosition());

    final int m = iterableImgs.size();

    if (compatibleIteration) {
      final ArrayList<Cursor<FloatType>> cursorWeights = new ArrayList<Cursor<FloatType>>();
      final ArrayList<Cursor<FloatType>> cursorImgs = new ArrayList<Cursor<FloatType>>();

      for (final IterableInterval<FloatType> img : iterableImgs) {
        final Cursor<FloatType> imgCursor = img.cursor();
        imgCursor.jumpFwd(portion.getStartPosition());
        cursorImgs.add(imgCursor);
      }

      for (final IterableInterval<FloatType> weight : iterableWeights) {
        final Cursor<FloatType> weightCursor = weight.cursor();
        weightCursor.jumpFwd(portion.getStartPosition());
        cursorWeights.add(weightCursor);
      }

      for (int j = 0; j < portion.getLoopSize(); ++j)
        compatibleLoop(psiCursor, cursorWeights, cursorImgs, realSum, m);
    } else {
      final ArrayList<RandomAccess<FloatType>> randomAccessWeights =
          new ArrayList<RandomAccess<FloatType>>();
      final ArrayList<RandomAccess<FloatType>> randomAccessImgs =
          new ArrayList<RandomAccess<FloatType>>();

      for (final RandomAccessibleInterval<FloatType> img : imgs)
        randomAccessImgs.add(img.randomAccess());

      for (final RandomAccessibleInterval<FloatType> weight : weights)
        randomAccessWeights.add(weight.randomAccess());

      for (int j = 0; j < portion.getLoopSize(); ++j)
        incompatibleLoop(psiCursor, randomAccessWeights, randomAccessImgs, realSum, m);
    }

    return realSum;
  }
  @Override
  public void compute(final IterableInterval<I> input, final O output) {

    final double moment00 = moment00Func.compute(input).getRealDouble();
    final double moment01 = moment01Func.compute(input).getRealDouble();

    final double centerY = moment01 / moment00;

    double centralmoment02 = 0;

    final Cursor<I> it = input.localizingCursor();
    while (it.hasNext()) {
      it.fwd();
      final double y = it.getDoublePosition(1) - centerY;
      final double val = it.get().getRealDouble();

      centralmoment02 += val * y * y;
    }

    output.setReal(centralmoment02);
  }