public void setKernel( final RandomAccessibleInterval< R > kernel ) { this.kernel = Views.extendValue( kernel, Util.getTypeFromInterval( kernel ).createVariable() ); this.kernelInterval = kernel; this.fftKernel = null; }
@Override public String toString() { if ( originalInvPCMPosition == null) return Util.printCoordinates( position ) + ", phaseCorrelationPeak = " + phaseCorrelationPeak + ", crossCorrelationPeak = " + crossCorrelationPeak; return Util.printCoordinates( position ) + " [" + Util.printCoordinates( originalInvPCMPosition ) + "], phaseCorrelationPeak = " + phaseCorrelationPeak + ", crossCorrelationPeak = " + crossCorrelationPeak; } }
public void fuseGroups() { this.downsampledBB = fuseGroups( spimData, images, unnormalizedWeights, models, groups, bb, downsampling, useWeightsFusion ? Util.getArrayFromValue( blendingRangeFusion, 3 ) : null, useWeightsFusion ? Util.getArrayFromValue( blendingBorderFusion, 3 ) : null, useWeightsDecon ? Util.getArrayFromValue( blendingRangeDeconvolution, 3 ) : null, useWeightsDecon ? Util.getArrayFromValue( blendingBorderDeconvolution, 3 ) : null, intensityAdjustments ); }
protected double computeAlternativeCosts() { if ( percentile == 1 ) { return alternativeCostFactor * Util.max( costs ); } return alternativeCostFactor * Util.percentile( costs, percentile ); }
private <T> ImgFactory<T> imgFactory( final RandomAccessibleInterval<T> rai) { final T type = Util.getTypeFromInterval(rai); return Util.getSuitableImgFactory(rai, type); } }
final private static Img< FloatType > createGaussianKernel( final double[] sigmas ) { final int numDimensions = sigmas.length; final long[] imageSize = new long[ numDimensions ]; final double[][] kernel = new double[ numDimensions ][]; for ( int d = 0; d < numDimensions; ++d ) { kernel[ d ] = Util.createGaussianKernel1DDouble( sigmas[ d ], true ); imageSize[ d ] = kernel[ d ].length; } final Img< FloatType > kernelImg = ArrayImgs.floats( imageSize ); final Cursor< FloatType > cursor = kernelImg.localizingCursor(); final int[] position = new int[ numDimensions ]; while ( cursor.hasNext() ) { cursor.fwd(); cursor.localize( position ); double value = 1; for ( int d = 0; d < numDimensions; ++d ) value *= kernel[ d ][ position[ d ] ]; cursor.get().set( ( float ) value ); } return kernelImg; }
protected void compute( final long startPos, final long loopSize, final T min, final T max ) { final Cursor< T > cursor = image.cursor(); // init min and max cursor.fwd(); min.set( cursor.get() ); max.set( cursor.get() ); cursor.reset(); // move to the starting position of the current thread cursor.jumpFwd( startPos ); // do as many pixels as wanted by this thread for ( long j = 0; j < loopSize; ++j ) { cursor.fwd(); final T value = cursor.get(); if ( Util.min( min, value ) == value ) min.set( value ); if ( Util.max( max, value ) == value ) max.set( value ); } }
/** * performs update step of the Richardson Lucy with Total Variation Algorithm */ @Override public void compute(I correction, I estimate) { if (variation == null) { Type<T> type = Util.getTypeFromInterval(correction); variation = ops().create().img(correction, type.createVariable()); } divUnitGradFastThread(estimate); final Cursor<T> cursorCorrection = Views.iterable(correction).cursor(); final Cursor<T> cursorVariation = Views.iterable(variation).cursor(); final Cursor<T> cursorEstimate = Views.iterable(estimate).cursor(); while (cursorEstimate.hasNext()) { cursorCorrection.fwd(); cursorVariation.fwd(); cursorEstimate.fwd(); cursorEstimate.get().mul(cursorCorrection.get()); cursorEstimate.get().mul(1f / (1f - regularizationFactor * cursorVariation .get().getRealFloat())); } }
@Override public RandomAccessibleInterval<T> calculate(double[] input) { final double[] sigmaPixels = new double[input.length]; final long[] dims = new long[input.length]; final double[][] kernelArrays = new double[input.length][]; for (int d = 0; d < input.length; d++) { sigmaPixels[d] = input[d]; dims[d] = Math.max(3, (2 * (int) (3 * sigmaPixels[d] + 0.5) + 1)); kernelArrays[d] = Util.createGaussianKernel1DDouble(sigmaPixels[d], true); } final RandomAccessibleInterval<T> out = createOp.calculate(new FinalInterval( dims)); final Cursor<T> cursor = Views.iterable(out).cursor(); while (cursor.hasNext()) { cursor.fwd(); double result = 1.0f; for (int d = 0; d < input.length; d++) { result *= kernelArrays[d][cursor.getIntPosition(d)]; } cursor.get().setReal(result); } return out; }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void initialize() { maxVal = Util.getTypeFromInterval(in()).createVariable(); maxVal.setReal(maxVal.getMaxValue()); if (f == null) { f = new OutOfBoundsConstantValueFactory<>(maxVal); } imgCreator = (UnaryFunctionOp) Functions.unary(ops(), Ops.Create.Img.class, Img.class, in(), maxVal.createVariable()); if (out() == null) setOutput(createOutput(in())); }
IntervalView<FloatType> incropped = Views.interval(in, new long[] { size[0] / 2, size[1] / 2 }, new long[] { size[0] - 1, size[1] - 1 }); incropped = Views.zeroMin(incropped); (RandomAccessibleInterval<FloatType>) ops.run(RichardsonLucyF.class, convolved, kernel, null, new OutOfBoundsConstantValueFactory<>(Util .getTypeFromInterval(in).createVariable()), 10); (RandomAccessibleInterval<FloatType>) ops.run(RichardsonLucyF.class, convolved, kernel, null, new OutOfBoundsConstantValueFactory<>(Util .getTypeFromInterval(in).createVariable()), null, null, null, 10, true, true); assertEquals(incropped.dimension(1), deconvolved2.dimension(1)); final Cursor<FloatType> deconvolvedCursor = Views.iterable(deconvolved) .cursor(); assertEquals(deconvolvedValues[i], deconvolvedCursor.next().get(), 0.0f); assertEquals(deconvolvedValues2[i], deconvolvedCursor2.next().get(), 0.0f);
/** Tests the Gaussian. */ @Test public void gaussRegressionTest() { final Img<ByteType> in = generateByteArrayTestImg(true, new long[] { 10, 10 }); final Img<ByteType> out1 = ops.create().img(in, Util.getTypeFromInterval(in)); final double sigma = 5; final Img<ByteType> out2 = ops.create().img(in, Util.getTypeFromInterval(in)); ops.run(GaussRAISingleSigma.class, out1, in, sigma); try { Gauss3.gauss(sigma, Views.extendMirrorSingle(in), out2); } catch (IncompatibleTypeException e) { throw new RuntimeException(e); } // compare outputs final Cursor<ByteType> c1 = out1.cursor(); final Cursor<ByteType> c2 = out2.cursor(); while (c1.hasNext()) { org.junit.Assert.assertEquals(c1.next().getRealDouble(), c2.next() .getRealDouble(), 0); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void initialize() { minVal = Util.getTypeFromInterval(in()).createVariable(); minVal.setReal(minVal.getMinValue()); imgCreator = (UnaryFunctionOp) Functions.unary(ops(), Ops.Create.Img.class, Img.class, in(), minVal.createVariable()); erodeComputer = Hybrids.binaryCF(ops(), Ops.Morphology.Erode.class, out(), in1(), in2(), false); dilateComputer = Hybrids.binaryCF(ops(), Ops.Morphology.Dilate.class, out(), in1(), in2(), false); }
minVal.setReal( minVal.getMinValue() ); final ExtendedRandomAccessibleInterval< T, RandomAccessibleInterval< T >> extended = Views.extendValue( source, minVal ); final ImgFactory< T > factory = Util.getSuitableImgFactory( interval, minVal ); final Img< T > img = factory.create( interval ); final long[] min = new long[ interval.numDimensions() ]; interval.min( min ); final IntervalView< T > translated = Views.translate( img, min );
int counterX = 0; int counterY = 0; while (cursorImg.hasNext()) { if (counterX > 8 && counterX < 12 || counterY > 8 && counterY < 12) { cursorImg.next().setOne(); } else { cursorImg.next().setZero(); FloatType type = Util.getTypeFromInterval(out).createVariable(); type.set(4.0f); assertEquals(type, outRA.get());
@Override @SuppressWarnings("unchecked") public O calculate(final I input) { if (obf == null) { obf = new OutOfBoundsConstantValueFactory<>( Util.getTypeFromInterval(input).createVariable()); } Interval inputInterval = paddingIntervalCentered.calculate(input, paddedDimensions); return (O) Views.interval(Views.extend(input, obf), inputInterval); } }
/** * Randomizes the content of the given image. * @return Reference to the given image */ public < I extends RandomAccessibleInterval< T >, T > I randomize( final I image ) { final T type = Util.getTypeFromInterval( image ); Views.iterable( image ).forEach( randomSetter( type ) ); return image; }
/** * * @param nBins The desired number of bins. * @param numDimensions The dimensions of the image region from which the histogram is computed. * @param min The minimum value, from which the first bin starts; all values under min will be added to the first bin. * @param max The maximum value, at which the last bin ends; all values over max will be added to the last bin. * @param op The type in which operations will be computed. */ public Histogram( final int nBins, final int numDimensions, final T min, final T max) { this.bins = new long[nBins]; this.maxPositions = new long[numDimensions]; this.minPositions = new long[numDimensions]; this.min = min; this.max = max; // this.range = min.createVariable(); this.range.set(max); this.range.sub(min); // final Dimensions dims = new FinalDimensions( nBins ); this.binValues = Util.getSuitableImgFactory( dims, min ).create( dims ); this.accessBinValues = this.binValues.randomAccess(); }
@SuppressWarnings( "unchecked" ) public DogComputationType( final RandomAccessible< ? > input, final Interval interval ) { final Object t = Util.getTypeFromInterval( Views.interval( input, interval ) ); if ( t instanceof DoubleType ) type = ( F ) new DoubleType(); else type = ( F ) new FloatType(); }
@Override public void initialize() { // if no OBF was passed in set default OBF for convolve to be constant value // of zero (zero-pad) if (this.getOBFInput() == null) { setOBFInput(new OutOfBoundsConstantValueFactory<>(Util .getTypeFromInterval(in()).createVariable())); } super.initialize(); }