private static final void incompatibleLoop( final Cursor<FloatType> psiCursor, final ArrayList<RandomAccess<FloatType>> randomAccessWeights, final ArrayList<RandomAccess<FloatType>> randomAccessImgs, final RealSum realSum, final int m) { final FloatType p = psiCursor.next(); double sum = 0; double sumW = 0; for (int j = 0; j < m; ++j) { final RandomAccess<FloatType> randomAccessWeight = randomAccessWeights.get(j); final RandomAccess<FloatType> randomAccessImg = randomAccessImgs.get(j); randomAccessWeight.setPosition(psiCursor); randomAccessImg.setPosition(psiCursor); final double w = randomAccessWeight.get().get(); final double i = randomAccessImg.get().get(); sum += i * w; sumW += w; } if (sumW > 0) { final double i = sum / sumW; realSum.add(i); p.set((float) i); } }
public static void main(final String[] args) { final int numRuns = 20; final boolean printIndividualTimes = false; final long[] dimensions = new long[] {200, 200, 200}; final Img<FloatType> img = ArrayImgs.floats(dimensions); final Random random = new Random(123914924); for (final FloatType t : img) t.set(random.nextFloat()); System.out.println("findLocalMaximaNeighborhood"); System.out.println("(using old LocalNeighborhoodCursor)"); BenchmarkHelper.benchmarkAndPrint( numRuns, printIndividualTimes, new Runnable() { @Override public void run() { findLocalMaximaNeighborhood(img); } }); System.out.println("findLocalMaximaNeighborhood2"); System.out.println("(using LocalNeighborhoodCursor2 by Bene and Tobias)"); BenchmarkHelper.benchmarkAndPrint( numRuns, printIndividualTimes, new Runnable() { @Override public void run() { findLocalMaximaNeighborhood2(img); } }); System.out.println("findLocalMaximaNeighborhood6"); System.out.println("(using RectangleShape)"); BenchmarkHelper.benchmarkAndPrint( numRuns, printIndividualTimes, new Runnable() { @Override public void run() { findLocalMaximaNeighborhood6(img); } }); final int n = findLocalMaximaNeighborhood(img); System.out.println(n); final int n2 = findLocalMaximaNeighborhood2(img); System.out.println(n2); final int n6 = findLocalMaximaNeighborhood6(img); System.out.println(n6); }
private static void adjustForOSEM( final HashMap<ViewId, RandomAccessibleInterval<FloatType>> weights, final WeightType weightType, final double osemspeedup) { if (osemspeedup == 1.0) return; if (weightType == WeightType.PRECOMPUTED_WEIGHTS || weightType == WeightType.WEIGHTS_ONLY || weightType == WeightType.LOAD_WEIGHTS) { for (final RandomAccessibleInterval<FloatType> w : weights.values()) { for (final FloatType f : Views.iterable(w)) f.set( Math.min( 1, f.get() * (float) osemspeedup)); // individual contribution never higher than 1 } } else if (weightType == WeightType.NO_WEIGHTS) { for (final RandomAccessibleInterval<FloatType> w : weights.values()) { final RandomAccess<FloatType> r = w.randomAccess(); final long[] min = new long[w.numDimensions()]; w.min(min); r.setPosition(min); r.get() .set( Math.min( 1, r.get().get() * (float) osemspeedup)); // individual contribution never higher than 1 } } else if (weightType == WeightType.VIRTUAL_WEIGHTS) { for (final RandomAccessibleInterval<FloatType> w : weights.values()) ((NormalizingRandomAccessibleInterval<FloatType>) w).setOSEMspeedup(osemspeedup); } else { throw new RuntimeException( "Weight Type: " + weightType.name() + " not supported in ProcessForDeconvolution.adjustForOSEM()"); } }