net.imglib2.Dimensions Java Examples

The following examples show how to use net.imglib2.Dimensions. 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: AbstractIntegralImg.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void initialize() {
	if (in() != null) {
		slicewiseOps = new UnaryComputerOp[in().numDimensions()];

		for (int i = 0; i < in().numDimensions(); ++i) {
			slicewiseOps[i] = Computers.unary(ops(), Slice.class,
				RandomAccessibleInterval.class, RandomAccessibleInterval.class,
				getComputer(i), i);
		}
	}

	createLongRAI = Functions.unary(ops(), Ops.Create.Img.class,
		RandomAccessibleInterval.class, Dimensions.class, new LongType());
	createDoubleRAI = Functions.unary(ops(), Ops.Create.Img.class,
		RandomAccessibleInterval.class, Dimensions.class, new DoubleType());
}
 
Example #2
Source File: FFTMethodsOpF.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void initialize() {
	super.initialize();

	// if no type was passed in the default is ComplexFloatType
	if (fftType == null) {
		fftType = (C)ops().create().nativeType(ComplexFloatType.class);
	}

	padOp = (BinaryFunctionOp) Functions.binary(ops(), PadInputFFTMethods.class,
		RandomAccessibleInterval.class, RandomAccessibleInterval.class,
		Dimensions.class, fast);

	createOp = (UnaryFunctionOp) Functions.unary(ops(),
		CreateOutputFFTMethods.class, RandomAccessibleInterval.class,
		Dimensions.class, fftType, fast);

	fftMethodsOp = (UnaryComputerOp) Computers.nullary(ops(),
		FFTMethodsOpC.class, RandomAccessibleInterval.class,
		RandomAccessibleInterval.class);

}
 
Example #3
Source File: DHM.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates the List of {@link ViewSetup} for the {@link SpimData} object.
 * The {@link ViewSetup} are defined independent of the {@link TimePoint},
 * each {@link TimePoint} should have the same {@link ViewSetup}s. The {@link MissingViews}
 * class defines if some of them are missing for some of the {@link TimePoint}s
 *
 * @return
 */
protected ArrayList< ViewSetup > createViewSetups( final DHMMetaData meta )
{
	final ArrayList< Channel > channels = new ArrayList< Channel >();
	channels.add( new Channel( meta.getAmpChannelId(), meta.getAmplitudeDir() ) );
	channels.add( new Channel( meta.getPhaseChannelId(), meta.getPhaseDir() ) );

	final ArrayList< Illumination > illuminations = new ArrayList< Illumination >();
	illuminations.add( new Illumination( 0, String.valueOf( 0 ) ) );

	final ArrayList< Angle > angles = new ArrayList< Angle >();
	angles.add( new Angle( 0, String.valueOf( 0 ) ) );

	final ArrayList< ViewSetup > viewSetups = new ArrayList< ViewSetup >();
	for ( final Channel c : channels )
		for ( final Illumination i : illuminations )
			for ( final Angle a : angles )
			{
				final VoxelDimensions voxelSize = new FinalVoxelDimensions( meta.calUnit, meta.calX, meta.calY, meta.calZ );
				final Dimensions dim = new FinalDimensions( new long[]{ meta.getWidth(), meta.getHeight(), meta.getDepth() } );
				viewSetups.add( new ViewSetup( viewSetups.size(), null, dim, voxelSize, c, a, i ) );
			}

	return viewSetups;
}
 
Example #4
Source File: PhaseCorrelationPeak2.java    From BigStitcher with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
	
	double o1 = 6;
	double o2 = Double.NEGATIVE_INFINITY;
	int np1 = 30;
	int np2 = 20;

	System.out.println( Double.isInfinite( o2 ));

	int ccCompare = Double.compare(o1, o2);
	if (ccCompare != 0)
		System.out.println( ccCompare );
	else 
		System.out.println( (int)(np1 - np2) );
	
	System.exit( 0 );
	PhaseCorrelationPeak2 peaks = new PhaseCorrelationPeak2(new Point(new int[] {10, 10}), 1.0);
	Dimensions pcmDims = new FinalDimensions(new int[] {50, 50});
	Dimensions imgDims = new FinalDimensions(new int[] {30, 30});
	PhaseCorrelation2Util.expandPeakToPossibleShifts(peaks, pcmDims, imgDims, imgDims);
	
}
 
Example #5
Source File: AbstractImgLoader.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Updates one specific ViewSetup using the imageMetaDataCache
 * 
 * @param setup - {@link ViewSetup}s that can potentially be updated if it is in the cache
 * @param forceUpdate - overwrite the data if it is already present
 * @return true if something was updated, false if it was not in the cache or if could have been updated but was already there
 */
public boolean updateXMLMetaData( final ViewSetup setup, final boolean forceUpdate )
{
	boolean updated = false;
	
	if ( viewIdLookUp.containsKey( setup.getId() ) )
	{
		// look up the metadata using the ViewId linked by the ViewSetupId
		final Pair< Dimensions, VoxelDimensions > metaData = imageMetaDataCache.get( viewIdLookUp.get( setup.getId() ) );

		if ( !setup.hasSize() || forceUpdate )
		{
			setup.setSize( metaData.getA() );
			updated = true;
		}

		if ( !setup.hasVoxelSize() || forceUpdate )
		{
			setup.setVoxelSize( metaData.getB() );
			updated = true;
		}
	}
	
	return updated;
}
 
Example #6
Source File: StitchingUIHelper.java    From BigStitcher with GNU General Public License v2.0 6 votes vote down vote up
public static boolean allViews2D(final List< ? extends BasicViewDescription< ? > > views)
{
	List< BasicViewDescription< ? > > all3DVds = views.stream().filter( vd -> {
		if (!vd.getViewSetup().hasSize())
			return true;
		Dimensions dims = vd.getViewSetup().getSize();
		boolean all3D = true;
		for (int d = 0; d<dims.numDimensions(); d++)
			if (dims.dimension( d ) == 1)
				all3D = false;
		return all3D;
	}).collect( Collectors.toList() );

	boolean is2d = all3DVds.size() == 0;
	return is2d;
}
 
Example #7
Source File: FrangiVesselness.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void run() {
	// parse the spacing, and scales strings.
	spacing = checkDimensions(spacingString, input.numDimensions(), "Spacings");
	scales = Arrays.stream(scaleString.split(regex)).mapToInt(Integer::parseInt)
		.toArray();
	Dimensions resultDims = Views.addDimension(input, 0, scales.length - 1);
	// create output image, potentially-filtered input
	result = opService.create().img(resultDims, new FloatType());

	for (int s = 0; s < scales.length; s++) {
		// Determine whether or not the user would like to apply the gaussian
		// beforehand and do it.
		RandomAccessibleInterval<T> vesselnessInput = doGauss ? opService.filter()
			.gauss(input, scales[s]) : input;
		IntervalView<FloatType> scaleResult = Views.hyperSlice(result, result
			.numDimensions() - 1, s);
		opService.filter().frangiVesselness(scaleResult, vesselnessInput, spacing,
			scales[s]);
	}
}
 
Example #8
Source File: LegacyDHMImgLoader.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
@Override
public RandomAccessibleInterval< UnsignedShortType > getImage( final ViewId view )
{
	final BasicViewDescription< ? > vd = sd.getViewDescriptions().get( view );
	final Dimensions d = vd.getViewSetup().getSize();
	final VoxelDimensions dv = vd.getViewSetup().getVoxelSize();

	final ArrayImg< UnsignedShortType, ? > img = ArrayImgs.unsignedShorts( d.dimension( 0 ), d.dimension( 1 ), d.dimension( 2 ) );

	final String ampOrPhaseDir;

	if ( vd.getViewSetup().getAttribute( Channel.class ).getId() == ampChannelId )
		ampOrPhaseDir = amplitudeDir;
	else if ( vd.getViewSetup().getAttribute( Channel.class ).getId() ==  phaseChannelId )
		ampOrPhaseDir = phaseDir;
	else
		throw new RuntimeException( "viewSetupId=" + view.getViewSetupId() + " is not Amplitude nor phase." );

	populateImage( img, directory, stackDir, ampOrPhaseDir, zPlanes, timepoints.get( view.getTimePointId() ), extension );

	updateMetaDataCache( view, (int)d.dimension( 0 ), (int)d.dimension( 1 ), (int)d.dimension( 2 ), dv.dimension( 0 ), dv.dimension( 1 ), dv.dimension( 2 ) );

	return img;
}
 
Example #9
Source File: FilterNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Executes the "padInputFFT" filter operation on the given arguments.
 */
@OpMethod(ops = { net.imagej.ops.filter.pad.PadInputFFTMethods.class,
	net.imagej.ops.filter.pad.DefaultPadInputFFT.class })
public <T extends ComplexType<T>> RandomAccessibleInterval<T> padFFTInput(
	final RandomAccessibleInterval<T> in1, final Dimensions in2)
{
	@SuppressWarnings("unchecked")
	final RandomAccessibleInterval<T> result =
		(RandomAccessibleInterval<T>) ops().run(Ops.Filter.PadFFTInput.class, in1,
			in2);
	return result;
}
 
Example #10
Source File: FilterNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Executes the "padInputFFT" filter operation on the given arguments.
 */
@OpMethod(ops = { net.imagej.ops.filter.pad.PadInputFFTMethods.class,
	net.imagej.ops.filter.pad.DefaultPadInputFFT.class })
public <T extends ComplexType<T>> RandomAccessibleInterval<T> padFFTInput(
	final RandomAccessibleInterval<T> in1, final Dimensions in2,
	final boolean fast)
{
	@SuppressWarnings("unchecked")
	final RandomAccessibleInterval<T> result =
		(RandomAccessibleInterval<T>) ops().run(Ops.Filter.PadFFTInput.class, in1,
			in2, fast);
	return result;
}
 
Example #11
Source File: PadInputFFTMethods.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void initialize() {
	super.initialize();

	setFFTSizeOp(Functions.unary(ops(), ComputeFFTMethodsSize.class, long[][].class, Dimensions.class, true, fast));

	if (obf != null) {
		setObf(obf);
	}
}
 
Example #12
Source File: FilterNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Executes the "padInput" filter operation on the given arguments. */
@OpMethod(op = net.imagej.ops.filter.pad.PadInput.class)
public <T extends ComplexType<T>> RandomAccessibleInterval<T> padInput(
	final RandomAccessibleInterval<T> in, final Dimensions paddedDimensions,
	final OutOfBoundsFactory<T, RandomAccessibleInterval<T>> obf)
{
	@SuppressWarnings("unchecked")
	final RandomAccessibleInterval<T> result =
		(RandomAccessibleInterval<T>) ops().run(Ops.Filter.PadInput.class, in,
			paddedDimensions, obf);
	return result;
}
 
Example #13
Source File: FilterNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Executes the "padInputFFT" filter operation on the given arguments.
 */
@OpMethod(ops = { net.imagej.ops.filter.pad.PadInputFFTMethods.class,
	net.imagej.ops.filter.pad.DefaultPadInputFFT.class })
public <T extends ComplexType<T>> RandomAccessibleInterval<T> padFFTInput(
	final RandomAccessibleInterval<T> in1, final Dimensions in2,
	final boolean fast,
	final OutOfBoundsFactory<T, RandomAccessibleInterval<T>> obf)
{
	@SuppressWarnings("unchecked")
	final RandomAccessibleInterval<T> result =
		(RandomAccessibleInterval<T>) ops().run(Ops.Filter.PadFFTInput.class, in1,
			in2, fast, obf);
	return result;
}
 
Example #14
Source File: AbstractFFTFilterC.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public UnaryFunctionOp<Dimensions, RandomAccessibleInterval<C>>
	getCreateOp()
{
	if (createOp == null) {
		createOp = (UnaryFunctionOp) Functions.unary(ops(),
			CreateOutputFFTMethods.class, RandomAccessibleInterval.class,
			Dimensions.class, fftType, true);
	}
	return createOp;
}
 
Example #15
Source File: FilterNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Executes the "paddingIntervalCentered" operation on the given arguments.
 */
@OpMethod(op = net.imagej.ops.filter.pad.PaddingIntervalCentered.class)
public <T extends ComplexType<T>> Interval paddingIntervalCentered(
	final RandomAccessibleInterval<T> in, final Dimensions paddedDimensions)
{
	final Interval result = (Interval) ops().run(
		Ops.Filter.PaddingIntervalCentered.class, in, paddedDimensions);
	return result;
}
 
Example #16
Source File: PaddingIntervalCentered.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public O calculate(final I input, final Dimensions paddedDimensions) {

	final long[] paddedSize = new long[paddedDimensions.numDimensions()];
	paddedDimensions.dimensions(paddedSize);

	O inputInterval = (O) FFTMethods.paddingIntervalCentered(input,
		FinalDimensions.wrap(paddedSize));

	return inputInterval;
}
 
Example #17
Source File: FilterNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Executes the "padShiftFFTKernel" filter operation on the given arguments.
 */
@OpMethod(ops = { net.imagej.ops.filter.pad.PadShiftKernelFFTMethods.class,
	net.imagej.ops.filter.pad.PadShiftKernel.class,
	net.imagej.ops.filter.pad.DefaultPadShiftKernelFFT.class })
public <T extends ComplexType<T>> RandomAccessibleInterval<T>
	padShiftFFTKernel(final RandomAccessibleInterval<T> in1,
		final Dimensions in2)
{
	@SuppressWarnings("unchecked")
	final RandomAccessibleInterval<T> result =
		(RandomAccessibleInterval<T>) ops().run(
			Ops.Filter.PadShiftFFTKernel.class, in1, in2);
	return result;
}
 
Example #18
Source File: FilterNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(op = net.imagej.ops.filter.fftSize.ComputeFFTMethodsSize.class)
public long[][] fftSize(final Dimensions in1, final boolean forward,
	final boolean fast)
{
	final long[][] result = (long[][]) ops().run(Ops.Filter.FFTSize.class, in1,
		forward, fast);
	return result;
}
 
Example #19
Source File: CreateOutputFFTMethods.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Img<T> calculate(Dimensions paddedDimensions, T outType) {

	Dimensions paddedFFTMethodsFFTDimensions = FFTMethodsUtility
		.getFFTDimensionsRealToComplex(fast, paddedDimensions);

	return create.calculate(paddedFFTMethodsFFTDimensions, outType);
}
 
Example #20
Source File: FFTMethodsOpF.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public RandomAccessibleInterval<C> calculate(
	final RandomAccessibleInterval<T> input)
{
	// calculate the padded size
	long[] paddedSize = new long[in().numDimensions()];

	for (int d = 0; d < in().numDimensions(); d++) {
		paddedSize[d] = in().dimension(d);

		if (borderSize != null) {
			paddedSize[d] += borderSize[d];
		}
	}

	Dimensions paddedDimensions = new FinalDimensions(paddedSize);

	// create the complex output
	RandomAccessibleInterval<C> output = createOp.calculate(paddedDimensions);

	// pad the input
	RandomAccessibleInterval<T> paddedInput = padOp.calculate(input,
		paddedDimensions);

	// compute and return fft
	fftMethodsOp.compute(paddedInput, output);

	return output;

}
 
Example #21
Source File: FFTMethodsUtility.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Calculates complex FFT size for real to complex FFT
 * 
 * @param fast if true calculate size for fast FFT
 * @param inputDimensions original real dimensions
 * @return complex FFT dimensions
 */
public static Dimensions getFFTDimensionsRealToComplex(final boolean fast,
	final Dimensions inputDimensions)
{
	final long[] paddedSize = new long[inputDimensions.numDimensions()];
	final long[] fftSize = new long[inputDimensions.numDimensions()];

	dimensionsRealToComplex(fast, inputDimensions, paddedSize, fftSize);

	return new FinalDimensions(fftSize);

}
 
Example #22
Source File: AbstractImgLoader.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the cached imageMetaData
 */
protected void updateMetaDataCache( final ViewId viewId,
		final int w, final int h, final int d,
		final double calX, final double calY, final double calZ )
{
	imageMetaDataCache.put( viewId, new ValuePair< Dimensions, VoxelDimensions >(
			new FinalDimensions( new long[] { w, h, d } ),
			new FinalVoxelDimensions( "", calX, calY, calZ ) ) );

	// links the viewSetupId to the last added viewId, overwrites earlier entries
	viewIdLookUp.put( viewId.getViewSetupId(), viewId );
}
 
Example #23
Source File: FFTMethodsUtility.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Calculates padding size and complex FFT size for real to complex FFT
 * 
 * @param fast if true calculate size for fast FFT
 * @param inputDimensions original real dimensions
 * @param paddedDimensions padded real dimensions
 * @param fftDimensions complex FFT dimensions
 */
public static void dimensionsRealToComplex(final boolean fast,
	final Dimensions inputDimensions, final long[] paddedDimensions,
	final long[] fftDimensions)
{
	if (fast) {
		FFTMethods.dimensionsRealToComplexFast(inputDimensions, paddedDimensions,
			fftDimensions);
	}
	else {
		FFTMethods.dimensionsRealToComplexSmall(inputDimensions, paddedDimensions,
			fftDimensions);
	}
}
 
Example #24
Source File: FilterNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Executes the "padShiftFFTKernel" filter operation on the given arguments.
 */
@OpMethod(ops = { net.imagej.ops.filter.pad.PadShiftKernelFFTMethods.class,
	net.imagej.ops.filter.pad.DefaultPadShiftKernelFFT.class })
public <T extends ComplexType<T>> RandomAccessibleInterval<T>
	padShiftFFTKernel(final RandomAccessibleInterval<T> in1,
		final Dimensions in2, final boolean fast)
{
	@SuppressWarnings("unchecked")
	final RandomAccessibleInterval<T> result =
		(RandomAccessibleInterval<T>) ops().run(
			Ops.Filter.PadShiftFFTKernel.class, in1, in2, fast);
	return result;
}
 
Example #25
Source File: CreateNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(
	op = net.imagej.ops.create.imgLabeling.DefaultCreateImgLabeling.class)
public <L, T extends IntegerType<T>> ImgLabeling<L, T> imgLabeling(
	final Dimensions dims, final T outType, final ImgFactory<T> fac,
	final int maxNumLabelSets)
{
	@SuppressWarnings("unchecked")
	final ImgLabeling<L, T> result =
		(ImgLabeling<L, T>) ops().run(
			Ops.Create.ImgLabeling.class, dims,
			outType, fac, maxNumLabelSets);
	return result;
}
 
Example #26
Source File: CreateNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(
	op = net.imagej.ops.create.imgLabeling.DefaultCreateImgLabeling.class)
public <L, T extends IntegerType<T>> ImgLabeling<L, T> imgLabeling(
	final Dimensions dims, final T outType, final ImgFactory<T> fac)
{
	@SuppressWarnings("unchecked")
	final ImgLabeling<L, T> result =
		(ImgLabeling<L, T>) ops().run(
			Ops.Create.ImgLabeling.class, dims,
			outType, fac);
	return result;
}
 
Example #27
Source File: AbstractPadAndFFTFilter.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void initialize() {
	super.initialize();

	/**
	 * Op used to pad the input
	 */
	padOp = (BinaryFunctionOp) Functions.binary(ops(), PadInputFFTMethods.class,
		RandomAccessibleInterval.class, RandomAccessibleInterval.class,
		Dimensions.class, true, obfInput);

	/**
	 * Op used to pad the kernel
	 */
	padKernelOp = (BinaryFunctionOp) Functions.binary(ops(),
		PadShiftKernelFFTMethods.class, RandomAccessibleInterval.class,
		RandomAccessibleInterval.class, Dimensions.class, true);

	if (fftType == null) {
		fftType = (ComplexType<C>) ops().create().nativeType(
			ComplexFloatType.class);
	}

	/**
	 * Op used to create the complex FFTs
	 */
	createOp = (UnaryFunctionOp) Functions.unary(ops(),
		CreateOutputFFTMethods.class, RandomAccessibleInterval.class,
		Dimensions.class, fftType, true);
}
 
Example #28
Source File: CreateNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(
	ops = net.imagej.ops.create.imgFactory.DefaultCreateImgFactory.class)
public <T extends NativeType<T>> ImgFactory<T> imgFactory(
	final Dimensions dims)
{
	// NB: The generic typing of ImgFactory is broken; see:
	// https://github.com/imglib/imglib2/issues/91
	@SuppressWarnings("unchecked")
	final ImgFactory<T> result = (ImgFactory<T>) ops().run(
		Ops.Create.ImgFactory.class, dims);
	return result;
}
 
Example #29
Source File: CreateNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(op = net.imagej.ops.create.img.CreateImgFromDimsAndType.class)
public <T extends NativeType<T>> Img<T> img(final Dimensions in1, final T in2,
	final ImgFactory<T> factory)
{
	@SuppressWarnings("unchecked")
	final Img<T> result = (Img<T>) ops().run(
		Ops.Create.Img.class, in1, in2,
		factory);
	return result;
}
 
Example #30
Source File: CreateNamespace.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@OpMethod(op = net.imagej.ops.create.img.CreateImgFromDimsAndType.class)
public <T extends NativeType<T>> Img<T> img(final Dimensions in1,
	final T in2)
{
	@SuppressWarnings("unchecked")
	final Img<T> result = (Img<T>) ops().run(
		Ops.Create.Img.class, in1, in2);
	return result;
}