Java Code Examples for net.imglib2.view.Views#interval()
The following examples show how to use
net.imglib2.view.Views#interval() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultDoG.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void compute(final RandomAccessibleInterval<T> input, final RandomAccessibleInterval<T> output) { // input may potentially be translated final long[] translation = new long[input.numDimensions()]; input.min(translation); final IntervalView<T> tmpInterval = Views.interval(Views.translate( (RandomAccessible<T>) tmpCreator.calculate(input), translation), output); gauss1.compute(input, tmpInterval); gauss2.compute(input, output); // TODO: Match the Subtract Op in initialize() once we have BinaryOp ops().run(Ops.Math.Subtract.class, output, output, tmpInterval); }
Example 2
Source File: CreateImgTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testCreateFromRaiDifferentType() { final IntervalView<ByteType> input = Views.interval(PlanarImgs.bytes(10, 10, 10), new FinalInterval( new long[] { 10, 10, 1 })); final Img<?> res = (Img<?>) ops.run(CreateImgFromDimsAndType.class, input, new ShortType()); assertEquals("Image Type: ", ShortType.class, res.firstElement().getClass()); assertArrayEquals("Image Dimensions: ", Intervals .dimensionsAsLongArray(input), Intervals.dimensionsAsLongArray(res)); assertEquals("Image Factory: ", ArrayImgFactory.class, res.factory() .getClass()); }
Example 3
Source File: BoxCountTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testUnevenBoxes() { // SETUP final int size = 10; final int max = size - 1; final long boxSize = size - 1; final Img<BitType> img = ArrayImgs.bits(size, size, size); final IntervalView<BitType> lastXYSlice = Views.interval(img, new long[] { 0, 0, max}, new long[] { max, max, max}); lastXYSlice.forEach(BitType::setOne); // EXECUTE final List<ValuePair<DoubleType, DoubleType>> points = ops.topology() .boxCount(img, boxSize, boxSize, 3.0); // VERIFY final ValuePair<DoubleType, DoubleType> point = points.get(0); assertEquals(point.b.get(), Math.log(4), 1e-12); }
Example 4
Source File: CommitCanvasN5Test.java From paintera with GNU General Public License v2.0 | 6 votes |
private static <T> void testCanvasPersistance( final N5Writer container, final String group, final String labelsDataset, final CachedCellImg<UnsignedLongType, ?> canvas, final BiFunction<N5Reader, String, RandomAccessibleInterval<T>> openLabels, final BiConsumer<UnsignedLongType, T> asserts) throws IOException, UnableToPersistCanvas, UnableToUpdateLabelBlockLookup { writeAll(container, group, canvas); final RandomAccessibleInterval<T> labels = openLabels.apply(container, labelsDataset); Assert.assertArrayEquals(Intervals.dimensionsAsLongArray(canvas), Intervals.dimensionsAsLongArray(labels)); for (final Pair<UnsignedLongType, T> pair : Views.interval(Views.pair(canvas, labels), labels)) { LOG.trace("Comparing canvas {} and background {}", pair.getA(), pair.getB()); asserts.accept(pair.getA(), pair.getB()); } }
Example 5
Source File: PadInput.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@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); }
Example 6
Source File: ConcatenateViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
private static < T extends ValueEquals< T > > void testEqual( final RandomAccessibleInterval< T > rai1, final RandomAccessibleInterval< T > rai2 ) { Assert.assertArrayEquals( Intervals.minAsLongArray( rai1 ), Intervals.minAsLongArray( rai2 ) ); Assert.assertArrayEquals( Intervals.maxAsLongArray( rai1 ), Intervals.maxAsLongArray( rai2 ) ); for ( final Pair< T, T > p : Views.interval( Views.pair( rai1, rai2 ), rai1 ) ) Assert.assertTrue( p.getA().valueEquals( p.getB() ) ); }
Example 7
Source File: DefaultScaleView.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public RandomAccessibleInterval<T> calculate(RandomAccessibleInterval<T> input) { final long[] newDims = Intervals.dimensionsAsLongArray(in()); for (int i = 0; i < Math.min(scaleFactors.length, in().numDimensions()); i++) { newDims[i] = Math.round(in().dimension(i) * scaleFactors[i]); } IntervalView<T> interval = Views.interval(Views.raster(RealViews.affineReal( Views.interpolate(Views.extendMirrorSingle(input), interpolator), new Scale(scaleFactors))), new FinalInterval(newDims)); return interval; }
Example 8
Source File: PadAndConvolveFFTF.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public RandomAccessibleInterval<O> calculate( final RandomAccessibleInterval<I> img, final RandomAccessibleInterval<K> kernel) { RandomAccessibleInterval<O> out = createOutput(img, kernel); if (obf == null) { obf = new OutOfBoundsConstantValueFactory<>(Util.getTypeFromInterval(in()) .createVariable()); } // extend the input RandomAccessibleInterval<I> extendedIn = Views.interval(Views.extend(img, obf), img); OutOfBoundsFactory<O, RandomAccessibleInterval<O>> obfOutput = new OutOfBoundsConstantValueFactory<>(Util.getTypeFromInterval(out) .createVariable()); // extend the output RandomAccessibleInterval<O> extendedOut = Views.interval(Views.extend(out, obfOutput), out); // ops().filter().convolve(extendedOut, extendedIn, kernel); convolver.compute(extendedIn, extendedOut); return out; }
Example 9
Source File: ShuffledView.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
private static <T> RandomAccessibleInterval<T> cropAt( final RandomAccessibleInterval<T> image, final int[] blockSize, final Localizable offset) { final int numDims = image.numDimensions(); final long[] minsize = new long[numDims * 2]; for (int d = 0; d < numDims; d++) { minsize[d] = offset.getLongPosition(d); final long shaveSize = image.dimension(d) % blockSize[d]; minsize[numDims + d] = image.dimension(d) - shaveSize; } return Views.interval(image, FinalInterval.createMinSize(minsize)); }
Example 10
Source File: ZeroMinViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void defaultZeroMinTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); IntervalView<DoubleType> imgTranslated = Views.interval( Views.translate((RandomAccessible<DoubleType>) img, 2, 5), new long[] { 2, 5 }, new long[] { 12, 15 }); IntervalView<DoubleType> il2 = Views.zeroMin(imgTranslated); IntervalView<DoubleType> opr = ops.transform().zeroMinView(imgTranslated); assertTrue(Views.isZeroMin(il2) == Views.isZeroMin(opr)); }
Example 11
Source File: ConcatenateViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
private < T > List< RandomAccessibleInterval< T > > createIntervals( final RandomAccessibleInterval< T > source, final long divider, final int axis ) { final long[] min = Intervals.minAsLongArray( source ); final long[] max = Intervals.maxAsLongArray( source ); final long[] min1 = min.clone(); final long[] min2 = min.clone(); final long[] max1 = max.clone(); final long[] max2 = max.clone(); max1[ axis ] = divider; min2[ axis ] = divider + 1; final IntervalView< T > interval1 = Views.interval( source, min1, max1 ); final IntervalView< T > interval2 = Views.interval( source, min2, max2 ); return Arrays.asList( interval1, interval2 ); }
Example 12
Source File: MaskedSource.java From paintera with GNU General Public License v2.0 | 5 votes |
public void setMask( final MaskInfo<UnsignedLongType> maskInfo, final RealRandomAccessible<UnsignedLongType> mask, final RealRandomAccessible<VolatileUnsignedLongType> vmask, final Invalidate<?> invalidate, final Invalidate<?> volatileInvalidate, final Runnable shutdown, final Predicate<UnsignedLongType> isPaintedForeground) throws MaskInUse { synchronized (this) { final boolean canSetMask = !isCreatingMask && currentMask == null && !isApplyingMask.get() && !isPersisting; LOG.debug("Can set mask? {}", canSetMask); if (!canSetMask) { LOG.error( "Currently processing, cannot set new mask: persisting? {} mask in use? {}", isPersisting, currentMask ); throw new MaskInUse("Busy, cannot set new mask."); } this.isCreatingMask = true; } setMasks(mask, vmask, maskInfo.level, maskInfo.value, isPaintedForeground); synchronized (this) { final RandomAccessibleInterval<UnsignedLongType> rasteredMask = Views.interval(Views.raster(mask), source.getSource(0, maskInfo.level)); // TODO how to get invalidateVolatile here? this.currentMask = new Mask<>(maskInfo, rasteredMask, invalidate, volatileInvalidate, shutdown); this.isCreatingMask = false; } }
Example 13
Source File: MTKTTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testMTKTimage() { RandomAccessibleInterval<UnsignedByteType> cropCh1 = Views.interval( zeroCorrelationImageCh1, new long[] { 0, 0, 0 }, new long[] { 20, 20, 0 }); RandomAccessibleInterval<UnsignedByteType> cropCh2 = Views.interval( zeroCorrelationImageCh2, new long[] { 0, 0, 0 }, new long[] { 20, 20, 0 }); double result = (Double) ops.run(MTKT.class, cropCh1, cropCh2); assertEquals(2.562373279563565, result, 0.0); }
Example 14
Source File: DefaultPValue.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
private static <V> RandomAccessibleInterval<V> trim( final RandomAccessibleInterval<V> image, final int[] blockSize) { final long[] min = Intervals.minAsLongArray(image); final long[] max = Intervals.maxAsLongArray(image); for (int d = 0; d < blockSize.length; d++) { final long trimSize = image.dimension(d) % blockSize[d]; final long half = trimSize / 2; min[d] += half; max[d] -= trimSize - half; } return Views.interval(image, min, max); }
Example 15
Source File: OrthoSliceFX.java From paintera with GNU General Public License v2.0 | 5 votes |
private void setTextureOpacityAndShading(final Texture texture, final Interval interval) { // NOTE: the opacity property of the MeshView object does not have any effect. // But the transparency can still be controlled by modifying the alpha channel in the texture images. final double alpha = this.opacity.get(); final double shading = this.shading.get(); final BufferExposingWritableImage[] targetImages = {texture.selfIlluminationMapImage, texture.diffuseMapImage}; final double[] brightnessFactors = {1 - shading, shading}; final RandomAccessibleInterval<ARGBType> src = Views.interval(texture.originalImage.asArrayImg(), interval); for (int i = 0; i < 2; ++i) { final BufferExposingWritableImage targetImage = targetImages[i]; final double brightnessFactor = brightnessFactors[i]; final RandomAccessibleInterval<ARGBType> dst = Views.interval(targetImage.asArrayImg(), interval); final Cursor<ARGBType> srcCursor = Views.flatIterable(src).cursor(); final Cursor<ARGBType> dstCursor = Views.flatIterable(dst).cursor(); while (dstCursor.hasNext()) { final int srcArgb = srcCursor.next().get(); final int dstArgb = ARGBType.rgba( ARGBType.red(srcArgb) * brightnessFactor, ARGBType.green(srcArgb) * brightnessFactor, ARGBType.blue(srcArgb) * brightnessFactor, alpha * 255); dstCursor.next().set(PixelUtils.NonPretoPre(dstArgb)); } } Arrays.stream(targetImages).forEach(BufferExposingWritableImage::setPixelsDirty); }
Example 16
Source File: MaskedSource.java From paintera with GNU General Public License v2.0 | 4 votes |
@Override public RandomAccessibleInterval<D> getDataSource(final int t, final int level) { final RealRandomAccessible<D> interpolatedDataSource = getInterpolatedDataSource(t, level, null); return Views.interval(Views.raster(interpolatedDataSource), new FinalInterval(source.getDataSource(t, level))); }
Example 17
Source File: PhaseCorrelationPeak2.java From BigStitcher with GNU General Public License v2.0 | 4 votes |
public <T extends RealType<T>, S extends RealType<S>> void calculateCrossCorr(RandomAccessibleInterval<T> img1, RandomAccessibleInterval<S> img2, long minOverlapPx, boolean interpolateSubpixel) { Pair<Interval, Interval> intervals = PhaseCorrelation2Util.getOverlapIntervals(img1, img2, shift); // no overlap found if (intervals == null) { crossCorr = Double.NEGATIVE_INFINITY; nPixel = 0; return; } nPixel = 1; for (int i = 0; i< intervals.getA().numDimensions(); i++){ nPixel *= intervals.getA().dimension(i); } if (nPixel < minOverlapPx){ crossCorr = Double.NEGATIVE_INFINITY; nPixel = 0; return; } // for subpixel move the underlying Img2 by the subpixel offset if ( subpixelShift != null && interpolateSubpixel ) { RealRandomAccessible< S > rra = Views.interpolate( Views.extendMirrorSingle( img2 ), new NLinearInterpolatorFactory< S >() ); InvertibleRealTransform transform = null; // e.g. subpixel = (-0.4, 0.1, -0.145) final double tx = subpixelShift.getDoublePosition( 0 ) - shift.getDoublePosition( 0 ); final double ty = subpixelShift.getDoublePosition( 1 ) - shift.getDoublePosition( 1 ); if ( rra.numDimensions() == 2 ) transform = new Translation2D( -tx, -ty ); // -relative subpixel shift only else if ( rra.numDimensions() == 3 ) transform = new Translation3D( -tx, -ty, shift.getDoublePosition( 2 ) - subpixelShift.getDoublePosition( 2 ) ); // -relative subpixel shift only img2 = Views.interval( Views.raster( RealViews.transform( rra, transform ) ), img2 ); } // calculate cross correlation. // note that the overlap we calculate assumes zero-min input crossCorr = PhaseCorrelation2Util.getCorrelation( Views.zeroMin( Views.interval(Views.zeroMin(img1), intervals.getA())), Views.zeroMin( Views.interval(Views.zeroMin(img2), intervals.getB())) ); }
Example 18
Source File: N5ChannelDataSource.java From paintera with GNU General Public License v2.0 | 4 votes |
@Override public RandomAccessibleInterval<RealComposite<D>> getDataSource(int t, int level) { return Views.interval(data[level], intervals[level]); }
Example 19
Source File: NonCirculantNormalizationFactor.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
protected void createNormalizationImageSemiNonCirculant(Interval fastFFTInterval) { // k is the window size (valid image region) final int length = k.numDimensions(); final long[] n = new long[length]; final long[] nFFT = new long[length]; // n is the valid image size plus the extended region // also referred to as object space size for (int d = 0; d < length; d++) { n[d] = k.dimension(d) + l.dimension(d) - 1; } // nFFT is the size of n after (potentially) extending further // to a fast FFT size for (int d = 0; d < length; d++) { nFFT[d] = fastFFTInterval.dimension(d); } FinalDimensions fd = new FinalDimensions(nFFT); // create the normalization image normalization = create.calculate(fd); // size of the measurement window final Point size = new Point(length); final long[] sizel = new long[length]; for (int d = 0; d < length; d++) { size.setPosition(k.dimension(d), d); sizel[d] = k.dimension(d); } // starting point of the measurement window when it is centered in fft space final Point start = new Point(length); final long[] startl = new long[length]; final long[] endl = new long[length]; for (int d = 0; d < length; d++) { start.setPosition((nFFT[d] - k.dimension(d)) / 2, d); startl[d] = (nFFT[d] - k.dimension(d)) / 2; endl[d] = startl[d] + sizel[d] - 1; } // size of the object space final Point maskSize = new Point(length); final long[] maskSizel = new long[length]; for (int d = 0; d < length; d++) { maskSize.setPosition(Math.min(n[d], nFFT[d]), d); maskSizel[d] = Math.min(n[d], nFFT[d]); } // starting point of the object space within the fft space final Point maskStart = new Point(length); final long[] maskStartl = new long[length]; for (int d = 0; d < length; d++) { maskStart.setPosition((Math.max(0, nFFT[d] - n[d]) / 2), d); maskStartl[d] = (Math.max(0, nFFT[d] - n[d]) / 2); } final RandomAccessibleInterval<O> temp = Views.interval(normalization, new FinalInterval(startl, endl)); final Cursor<O> normCursor = Views.iterable(temp).cursor(); // draw a cube the size of the measurement space while (normCursor.hasNext()) { normCursor.fwd(); normCursor.get().setReal(1.0); } final Img<O> tempImg = create.calculate(fd); // 3. correlate psf with the output of step 2. correlater.compute(normalization, tempImg); normalization = tempImg; final Cursor<O> cursorN = normalization.cursor(); while (cursorN.hasNext()) { cursorN.fwd(); if (cursorN.get().getRealFloat() <= 1e-3f) { cursorN.get().setReal(1.0f); } } }
Example 20
Source File: PhaseCorrelationTest.java From BigStitcher with GNU General Public License v2.0 | 2 votes |
@Test public void testPCRealShift() { // TODO: very large shifts (nearly no overlap) lead to incorrect shift determination (as expected) // maybe we can optimize behaviour in this situation Img< FloatType > img = ArrayImgs.floats( 200, 200 ); Random rnd = new Random( seed ); for( FloatType t : img ) t.set( rnd.nextFloat()); double shiftX = -20.9; double shiftY = 1.9; // to test < 0.5 px off final double eps = 0.5; FinalInterval interval2 = new FinalInterval(new long[] {50, 50}); AffineRandomAccessible< FloatType, AffineGet > imgTr = RealViews.affine( Views.interpolate( Views.extendZero( img ), new NLinearInterpolatorFactory<>() ), new Translation2D( shiftX, shiftY )); IntervalView< FloatType > img2 = Views.interval( Views.raster( imgTr ), interval2); int [] extension = new int[img.numDimensions()]; Arrays.fill(extension, 10); RandomAccessibleInterval<FloatType> pcm = PhaseCorrelation2.calculatePCM(Views.zeroMin(img2), Views.zeroMin(Views.interval(img, interval2)), extension, new ArrayImgFactory<FloatType>(), new FloatType(), new ArrayImgFactory<ComplexFloatType>(), new ComplexFloatType(), Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); PhaseCorrelationPeak2 shiftPeak = PhaseCorrelation2.getShift(pcm, Views.zeroMin(img2), Views.zeroMin(Views.interval(img, interval2)), 20, 0, true, Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); double[] expected = new double[]{shiftX, shiftY}; double[] found = new double[img.numDimensions()]; shiftPeak.getSubpixelShift().localize(found); System.out.println( Util.printCoordinates( found ) ); for (int d = 0; d < expected.length; d++) assertTrue( Math.abs( expected[d] - found[d] ) < eps ); }