net.imglib2.util.ValuePair Java Examples

The following examples show how to use net.imglib2.util.ValuePair. 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: TransformTools.java    From BigStitcher with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 
 * @param vr the ViewRegistration to decompose
 * @param is2d true or false
 * @param dsCorrectionT downsampling correction 
 * @return (1) the ViewRegistration without Translation part and the translation, with the inverse of (1) and dsCorrection applied
 */
public static Pair<AffineGet, TranslationGet> getInitialTransforms( final ViewRegistration vr, final boolean is2d, final AffineTransform3D dsCorrectionT )
{
	AffineTransform3D model = vr.getModel().copy();
	
	// get model without translation (last column set to 0)
	AffineTransform3D modelWithoutTranslation = model.copy();
	modelWithoutTranslation.set( 0, 0, 3 );
	modelWithoutTranslation.set( 0, 1, 3 );
	modelWithoutTranslation.set( 0, 2, 3 );
	
	// the translation with inverse of other part of model applied
	final double[] target = model.getTranslation();
	modelWithoutTranslation.applyInverse( target, target );
	
	// we go from big to downsampled, thats why the inverse
	dsCorrectionT.applyInverse( target, target );
	
	
	if ( is2d )
		return new ValuePair<>(modelWithoutTranslation, new Translation2D( target[ 0 ], target[ 1 ] ));
	else
		return new ValuePair<>(modelWithoutTranslation, new Translation3D( target[ 0 ], target[ 1 ], target[ 2 ] ));
}
 
Example #2
Source File: DemoLinkOverlay.java    From BigStitcher with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void selectedViewDescriptions(
		List< List< BasicViewDescription< ? extends BasicViewSetup > > > viewDescriptions)
{
	List<Pair<Group<ViewId>, Group<ViewId>>> res = new ArrayList<>();
	for (int i = 0; i<viewDescriptions.size(); i++)
		for (int j = i+1; j<viewDescriptions.size(); j++)
		{
			Group<ViewId> groupA = new Group<>();
			groupA.getViews().addAll( viewDescriptions.get( i ) );
			Group<ViewId> groupB = new Group<>();
			groupB.getViews().addAll( viewDescriptions.get( j ) );
			res.add( new ValuePair< Group<ViewId>, Group<ViewId> >( groupA, groupB ) );
		}
	setActiveLinks( res );
}
 
Example #3
Source File: DefaultMinMax.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Pair<I, I> calculate(final Iterable<I> input) {
	double tmpMin = Double.POSITIVE_INFINITY;
	double tmpMax = Double.NEGATIVE_INFINITY;

	for (final I in : input) {
		final double n = in.getRealDouble();

		if (tmpMin > n) {
			tmpMin = n;
		}

		if (tmpMax < n) {
			tmpMax = n;
		}
	}

	final I min = input.iterator().next().createVariable();
	min.setReal(tmpMin);

	final I max = input.iterator().next().createVariable();
	max.setReal(tmpMax);

	return new ValuePair<>(min, max);
}
 
Example #4
Source File: BoxCountTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testAllBackground() throws Exception {
	// SETUP
	final double expectedCount = Math.log(0.0);
	final Img<BitType> img = ArrayImgs.bits(TEST_DIMS);

	// EXECUTE
	final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
		.boxCount(img, MAX_SIZE, MIN_SIZE, SCALING);

	// VERIFY
	assertNotNull(points);
	assertEquals(ITERATIONS, points.size());
	for (int i = 0; i < ITERATIONS; i++) {
		assertEquals(EXPECTED_SIZES[i], points.get(i).a.get(), 1e-12);
		assertEquals(expectedCount, points.get(i).b.get(), 1e-12);
	}
}
 
Example #5
Source File: BoxCountTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testAllForeground() {
	// SETUP
	final double scalingPow = DoubleStream.generate(() -> SCALING).limit(
		DIMENSIONS).reduce((i, j) -> i * j).orElse(0);
	final double[] expectedCounts = DoubleStream.iterate(1.0, i -> i *
		scalingPow).map(Math::log).limit(ITERATIONS).toArray();
	final Img<BitType> img = ArrayImgs.bits(TEST_DIMS);
	img.forEach(BitType::setOne);

	// EXECUTE
	final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
		.boxCount(img, MAX_SIZE, MIN_SIZE, SCALING);

	// VERIFY
	for (int i = 0; i < ITERATIONS; i++) {
		assertEquals(EXPECTED_SIZES[i], points.get(i).a.get(), 1e-12);
		assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12);
	}
}
 
Example #6
Source File: BoxCountTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testHyperCube() {
	// SETUP
	final double[] expectedSizes = DoubleStream.of(4, 2, 1).map(i -> -Math.log(
		i)).toArray();
	final double[] expectedCounts = DoubleStream.of(1, 16, 16).map(Math::log)
		.toArray();
	final Img<BitType> img = ArrayImgs.bits(4, 4, 4, 4);
	final IntervalView<BitType> hyperView = Views.offsetInterval(img,
		new long[] { 1, 1, 1, 1 }, new long[] { 2, 2, 2, 2 });
	hyperView.forEach(BitType::setOne);

	// EXECUTE
	final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
		.boxCount(img, 4L, 1L, 2.0);

	// VERIFY
	for (int i = 0; i < expectedSizes.length; i++) {
		assertEquals(expectedSizes[i], points.get(i).a.get(), 1e-12);
		assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12);
	}
}
 
Example #7
Source File: BoxCountTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Test box counting with a hyper cube and one grid translation (should find a
 * better fit than in @see {@link #testHyperCube()})
 */
@Test
public void testHyperCubeTranslations() {
	final double[] expectedSizes = DoubleStream.of(4, 2, 1).map(i -> -Math.log(
		i)).toArray();
	final double[] expectedCounts = DoubleStream.of(1, 1, 16).map(Math::log)
		.toArray();
	final Img<BitType> img = ArrayImgs.bits(4, 4, 4, 4);
	final IntervalView<BitType> hyperView = Views.offsetInterval(img,
		new long[] { 1, 1, 1, 1 }, new long[] { 2, 2, 2, 2 });
	hyperView.forEach(BitType::setOne);

	// EXECUTE
	final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
		.boxCount(img, 4L, 1L, 2.0, 1L);

	// VERIFY
	for (int i = 0; i < expectedSizes.length; i++) {
		assertEquals(expectedSizes[i], points.get(i).a.get(), 1e-12);
		assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12);
	}
}
 
Example #8
Source File: BoxCountTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testOneVoxel() {
	// SETUP
	final PrimitiveIterator.OfDouble sizes = DoubleStream.of(9, 3, 1).map(
		i -> -Math.log(i)).iterator();
	final PrimitiveIterator.OfDouble counts = DoubleStream.of(1, 1, 1).map(
		Math::log).iterator();
	final Img<BitType> img = ArrayImgs.bits(9, 9, 9);
	final RandomAccess<BitType> access = img.randomAccess();
	access.setPosition(new long[] { 4, 4, 4 });
	access.get().setOne();

	// EXECUTE
	final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
		.boxCount(img, 9L, 3L, 3.0);

	// VERIFY
	points.forEach(p -> {
		assertEquals(p.a.get(), sizes.next(), 1e-12);
		assertEquals(p.b.get(), counts.next(), 1e-12);
	});
}
 
Example #9
Source File: BoxCountTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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 #10
Source File: Histogram.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public static List< ValuePair< Double, Integer > > binData( final List< Double > data, final double min, final double max, final int numBins )
{
	// avoid the one value that is exactly 100%
	final double size = max - min + 0.000001;

	// bin and count the entries
	final int[] bins = new int[ numBins ];

	for ( final double v : data )
		++bins[ (int)Math.floor( ( ( v - min ) / size ) * numBins ) ];

	// make the list of bins
	final ArrayList< ValuePair< Double, Integer > > hist = new ArrayList< >();

	final double binSize = size / numBins;
	for ( int bin = 0; bin < numBins; ++bin )
		hist.add( new ValuePair< >( min + binSize/2 + binSize * bin, bins[ bin ] ) );

	return hist;
}
 
Example #11
Source File: Histogram.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
protected IntervalXYDataset createDataset( final List< Double > values, final int numBins, final String title )
{
	final XYSeries series = new XYSeries( title );

	final ValuePair< Double, Double > minmax = getMinMax( values );
	this.min = minmax.getA();
	this.max = minmax.getB();

	final List< ValuePair< Double, Integer > > hist = binData( values, min, max, numBins );

	for ( final ValuePair< Double, Integer > pair : hist )
		series.add( pair.getA(), pair.getB() );

	final XYSeriesCollection dataset = new XYSeriesCollection( series );
	dataset.setAutoWidth( true );

	return dataset;
}
 
Example #12
Source File: Resave_HDF5.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public static Pair< SpimData2, List< String > > createXMLObject(
		final SpimData2 spimData,
		final List< ViewId > viewIds,
		final Parameters params,
		final ProgressWriter progressWriter,
		final boolean useRightAway )
{
	// Re-assemble a new SpimData object containing the subset of viewsetups and timepoints selected
	final List< String > filesToCopy = new ArrayList< String >();
	final SpimData2 newSpimData = Resave_TIFF.assemblePartialSpimData2( spimData, viewIds, params.seqFile.getParentFile(), filesToCopy );
	final ArrayList< Partition > partitions = Generic_Resave_HDF5.getPartitions( newSpimData, params );

	final Hdf5ImageLoader hdf5Loader;

	if ( useRightAway )
		hdf5Loader = new Hdf5ImageLoader( params.hdf5File, partitions, newSpimData.getSequenceDescription(), true );
	else
		hdf5Loader = new Hdf5ImageLoader( params.hdf5File, partitions, null, false );
	
	newSpimData.getSequenceDescription().setImgLoader( hdf5Loader );
	newSpimData.setBasePath( params.seqFile.getParentFile() );

	return new ValuePair< SpimData2, List< String > >( newSpimData, filesToCopy );
}
 
Example #13
Source File: SpimDataFilteringAndGrouping.java    From BigStitcher with GNU General Public License v2.0 6 votes vote down vote up
public List<Pair<? extends Group< ? extends BasicViewDescription< ? extends BasicViewSetup > >, ? extends Group< ? extends BasicViewDescription< ? extends BasicViewSetup >>>> getComparisons()
{
	final List<Pair<? extends Group< ? extends BasicViewDescription< ? extends BasicViewSetup > >, ? extends Group< ? extends BasicViewDescription< ? extends BasicViewSetup >>>> res = new ArrayList<>();
	
	// filter first
	final List<BasicViewDescription< ? > > ungroupedElements =
			SpimDataTools.getFilteredViewDescriptions( data.getSequenceDescription(), filters);
	// then group
	final List< Group< BasicViewDescription< ?  > >> groupedElements = 
			Group.combineBy(ungroupedElements, groupingFactors);
	
	// go through possible group pairs
	for (int i = 0; i < groupedElements.size(); ++i)
		for(int j = i+1; j < groupedElements.size(); ++j)
		{
			// we will want to process the pair if:
			// the groups do not differ along an axis along which we want to treat elements individually (e.g. Angle)
			// but they differ along an axis that we want to register (e.g Tile)
			if (!groupsDifferByAny( groupedElements.get( i ), groupedElements.get( j ), axesOfApplication ) 
					&& groupsDifferByAny( groupedElements.get( i ), groupedElements.get( j ), axesOfComparison ))
				res.add(new ValuePair<>(groupedElements.get( i ), groupedElements.get( j )));
		}
	return res;
}
 
Example #14
Source File: AutomaticReorientation.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
protected Pair< double[], double[] > determineSizeSimple( final ArrayList< ChannelProcess > channelsToUse, final int detections )
{
	final List< double[] > points = getAllDetectionsInGlobalCoordinates( channelsToUse, detections );

	if ( points.size() < 1 )
	{
		IOFunctions.println( "At least one point is required. Stopping" );
		return null;
	}

	final double[] min = points.get( 0 ).clone();
	final double[] max = min.clone();

	for ( final double[] p : points )
		for ( int d = 0; d < p.length; ++d )
		{
			min[ d ] = Math.min( min[ d ], p[ d ] );
			max[ d ] = Math.max( max[ d ], p[ d ] );
		}

	IOFunctions.println( "Min (direct): " + Util.printCoordinates( min ) );
	IOFunctions.println( "Max (direct): " + Util.printCoordinates( max ) );

	return new ValuePair< double[], double[] >( min, max );
}
 
Example #15
Source File: AutomaticReorientation.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
protected Pair< Integer, Integer > numReorientated()
{
	final ViewRegistrations vrs = spimData.getViewRegistrations();

	int isReorientated = 0;
	int sumViews = 0;

	for ( final ViewId viewId : viewIdsToProcess )
	{
		final ViewDescription vd = spimData.getSequenceDescription().getViewDescription( viewId );
		
		if ( !vd.isPresent() )
			continue;

		final ViewRegistration vr = vrs.getViewRegistration( viewId );
		final ViewTransform vt = vr.getTransformList().get( 0 );

		++sumViews;

		if ( vt.hasName() && vt.getName().startsWith( reorientationDescription ) )
				++isReorientated;
	}

	return new ValuePair< Integer, Integer >( isReorientated, sumViews );
}
 
Example #16
Source File: AbstractMeshCacheLoader.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Pair<float[], float[]> get(final ShapeKey<K> key) throws Exception
{

	//		if ( key.meshSimplificationIterations() > 0 )
	//		{
	// TODO deal with mesh simplification
	//		}

	LOG.debug("key={}, getMaskGenerator={}", key, getMaskGenerator);
	final RandomAccessibleInterval<BoolType> mask = Converters.convert(
			data.get(),
			getMaskGenerator.apply(key.shapeId(), key.minLabelRatio()),
			new BoolType(false)
		);

	final float[] mesh = new MarchingCubes<>(
			Views.extendZero(mask),
			key.interval(),
			transform).generateMesh();
	final float[] normals = new float[mesh.length];
	if (key.smoothingIterations() > 0)
	{
		final float[] smoothMesh = Smooth.smooth(mesh, key.smoothingLambda(), key.smoothingIterations());
		System.arraycopy(smoothMesh, 0, mesh, 0, mesh.length);
	}
	Normals.normals(mesh, normals);
	AverageNormals.averagedNormals(mesh, normals);

	for (int i = 0; i < normals.length; ++i)
		normals[i] *= -1;

	return new ValuePair<>(mesh, normals);
}
 
Example #17
Source File: Histogram.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static ValuePair< Double, Double > getMinMax( final List< Double > data )
{
	// compute min/max/size
	double min = data.get( 0 );
	double max = data.get( 0 );

	for ( final double v : data )
	{
		min = Math.min( min, v );
		max = Math.max( max, v );
	}

	return new ValuePair< >( min, max );
}
 
Example #18
Source File: DHMMetaData.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public static Pair< List< String >, String > loadTimepoints ( final File dataDir )
{
	if ( !dataDir.exists() )
	{
		IOFunctions.println( dataDir.getAbsolutePath() + " does not exist" );
		return null;
	}

	final ArrayList< String > list = new ArrayList< String >();

	final String regex = "^[0-9]+\\.[tifTIF]+";

	final String[] files = dataDir.list();
	Arrays.sort( files );

	String extension = null;

	for ( final String t : files )
		if ( t.matches( regex ) )
		{
			list.add( t.split(  "\\." )[ 0 ] );

			String ext = t.substring( t.indexOf( "." ), t.length() );
			if ( extension == null )
			{
				extension = ext;
			}
			else if ( !ext.equals( extension ) )
			{
				IOFunctions.println( "Extension of filenames is not consistent. Was before '" + extension + "', now is '" + ext + "'. Stopping" );
				return null;
			}
		}

	return new ValuePair< List< String >, String >( list, extension );
}
 
Example #19
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 #20
Source File: MultipageTiffReader.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
private void readIndexMap( final FileChannel fileChannel, final HashMap< String, Pair< Long, FileChannel > > indexMap_ ) throws IOException
{
	final long offset = readOffsetHeaderAndOffset( INDEX_MAP_OFFSET_HEADER, 8, fileChannel );
	final ByteBuffer header = readIntoBuffer( offset, 8, fileChannel );
	if ( header.getInt(0) != INDEX_MAP_HEADER )
		throw new RuntimeException( "Error reading index map header" );

	final int numMappings = header.getInt( 4 );
	final ByteBuffer mapBuffer = readIntoBuffer( offset + 8, 20 * numMappings, fileChannel );
	for ( int i = 0; i < numMappings; ++i )
	{
		final int channel = mapBuffer.getInt( i * 20 );
		final int slice = mapBuffer.getInt( i * 20 + 4 );
		final int frame = mapBuffer.getInt( i * 20 + 8 );
		final int position = mapBuffer.getInt( i * 20 + 12 );
		final long imageOffset = unsignInt( mapBuffer.getInt( i * 20 + 16 ) );
		if ( imageOffset == 0 )
			break; // end of index map reached

		// If a duplicate label is read, forget about the previous one
		// if data has been intentionally overwritten, this gives the most
		// current version
		final String label = generateLabel( channel, slice, frame, position );
		if ( indexMap_.containsKey( label ) )
			IOFunctions.printlnSafe( "ERROR!!! Label: " + label + " already present." );

		//System.out.println( label + " " + getFileForFileChannel( fileChannel ).getName() );

		indexMap_.put( label, new ValuePair< Long, FileChannel >( imageOffset, fileChannel ) );
	}
}
 
Example #21
Source File: MultipageTiffReader.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
private Pair< Object, HashMap< String, Object > > readTaggedImage( final IFDData data, final FileChannel fileChannel ) throws IOException
{
	final ByteBuffer pixelBuffer = ByteBuffer.allocate( (int)data.bytesPerImage).order( byteOrder_ );
	final ByteBuffer mdBuffer = ByteBuffer.allocate( (int)data.mdLength).order( byteOrder_ );
	fileChannel.read( pixelBuffer, data.pixelOffset );
	fileChannel.read( mdBuffer, data.mdOffset );

	final HashMap< String, Object > md = parseJSONSimple( getString( mdBuffer ) );

	if ( byteDepth_ == 0 )
		getRGBAndByteDepth( md );

	if ( rgb_ )
	{
		IOFunctions.printlnSafe( "RGB types not supported." );
		return null;
	}
	else
	{
		if (byteDepth_ == 1)
		{
			return new ValuePair<Object, HashMap< String, Object >>( pixelBuffer.array(), md );
		}
		else
		{
			final short[] pix = new short[ pixelBuffer.capacity() / 2 ];
			for ( int i = 0; i < pix.length; ++i )
				pix[ i ] = pixelBuffer.getShort( i * 2 );

			return new ValuePair<Object, HashMap< String, Object >>( pix, md );
		}
	}
}
 
Example #22
Source File: AutomaticReorientation.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test one major axis for the minimal bounding box volume required
 * 
 * @param v - normalized vector
 * @param points - all points
 * @return - the volume and minX, minY, minZ, maxX, maxY, maxZ as Pair
 */
protected Pair< Double, double[] > testAxis( final Vector3d v, final List< double[] > points )
{
	// mapping v onto the x axis
	final Vector3d xAxis = new Vector3d( 1, 0, 0 );
	final Transform3D t = getRotation( v, xAxis );

	final Point3d tmp = new Point3d();

	double minX = Double.MAX_VALUE;
	double minY = Double.MAX_VALUE;
	double minZ = Double.MAX_VALUE;

	double maxX = -Double.MAX_VALUE;
	double maxY = -Double.MAX_VALUE;
	double maxZ = -Double.MAX_VALUE;

	for ( final double[] p : points )
	{
		// transform onto the x-axis
		tmp.set( p[ 0 ], p[ 1 ], p[ 2 ] );
		t.transform( tmp );

		minX = Math.min( minX, tmp.x );
		minY = Math.min( minY, tmp.y );
		minZ = Math.min( minZ, tmp.z );

		maxX = Math.max( maxX, tmp.x );
		maxY = Math.max( maxY, tmp.y );
		maxZ = Math.max( maxZ, tmp.z );
	}

	return new ValuePair< Double, double[] >(
			( maxX - minX ) * ( maxY - minY ) * ( maxZ - minZ ),
			new double[]{ minX, minY, minZ, maxX, maxY, maxZ } );
}
 
Example #23
Source File: BoxCount.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Counts the number of boxes that have foreground in the interval repeatedly with
 * different size boxes
 *
 * @param input An n-dimensional binary interval.
 * @return A list of (log(foreground count), -log(box size))
 *         {@link ValuePair} objects for curve fitting
 */
@Override
public List<ValuePair<DoubleType, DoubleType>> calculate(
	final RandomAccessibleInterval<B> input)
{
	if (scaling < 1.0 || (scaling == 1.0 && maxSize > minSize)) {
		throw new IllegalArgumentException("Scaling must be > 1.0 or algorithm won't stop.");
	}

	final List<ValuePair<DoubleType, DoubleType>> points = new ArrayList<>();
	final int dimensions = input.numDimensions();
	final long[] sizes = new long[dimensions];
	input.dimensions(sizes);
	for (long boxSize = maxSize; boxSize >= minSize; boxSize /=
		scaling)
	{
		final long numTranslations = limitTranslations(boxSize,
				1 + gridMoves);
		final long translationAmount = boxSize / numTranslations;
		final Stream<long[]> translations = translationStream(
				numTranslations, translationAmount, dimensions - 1,
				new long[dimensions]);
		final LongStream foregroundCounts = countTranslatedGrids(input,
			translations, sizes, boxSize);
		final long foreground = foregroundCounts.min().orElse(0);
		final double logSize = -Math.log(boxSize);
		final double logCount = Math.log(foreground);
		final ValuePair<DoubleType, DoubleType> point = new ValuePair<>(
				new DoubleType(logSize), new DoubleType(logCount));
		points.add(point);
	}
	return points;
}
 
Example #24
Source File: DefaultMinorMajorAxis.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Pair<DoubleType, DoubleType> calculate(final Polygon2D input) {
	
	List<RealLocalizable> points = new ArrayList<>(GeomUtils.vertices(input));

	// Sort RealLocalizables of P by x-coordinate (in case of a tie,
	// sort by
	// y-coordinate). Sorting is counter clockwise.
	Collections.sort(points, new Comparator<RealLocalizable>() {

		@Override
		public int compare(final RealLocalizable o1, final RealLocalizable o2) {
			final Double o1x = new Double(o1.getDoublePosition(0));
			final Double o2x = new Double(o2.getDoublePosition(0));
			final int result = o2x.compareTo(o1x);
			if (result == 0) {
				return new Double(o2.getDoublePosition(1)).compareTo(new Double(o1.getDoublePosition(1)));
			}
			return result;
		}
	});
	points.add(points.get(0));

	// calculate minor and major axis
	double[] minorMajorAxis = getMinorMajorAxis(input, points);
	return new ValuePair<>(new DoubleType(minorMajorAxis[0]), new DoubleType(minorMajorAxis[1]));
}
 
Example #25
Source File: DefaultMaximumFeret.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Pair<RealLocalizable, RealLocalizable> calculate(Polygon2D input) {
	final List<? extends RealLocalizable> points = GeomUtils.vertices(function
		.calculate(input));

	double distance = Double.NEGATIVE_INFINITY;
	RealLocalizable p0 = points.get(0);
	RealLocalizable p1 = points.get(0);
	for (int i = 0; i < points.size(); i++) {
		for (int j = i + 2; j < points.size(); j++) {
			final RealLocalizable tmpP0 = points.get(i);
			final RealLocalizable tmpP1 = points.get(j);

			final double tmp = Math.sqrt(Math.pow(tmpP0.getDoublePosition(0) - tmpP1
				.getDoublePosition(0), 2) + Math.pow(tmpP0.getDoublePosition(1) -
					tmpP1.getDoublePosition(1), 2));

			if (tmp > distance) {
				distance = tmp;
				p0 = tmpP0;
				p1 = tmpP1;
			}
		}
	}

	return new ValuePair<>(p0, p1);
}
 
Example #26
Source File: MatchIntensities.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public Matcher(
		final Rectangle roi,
		final ValuePair< Patch, Patch > patchPair,
		final HashMap< Patch, ArrayList< Tile< ? > > > coefficientsTiles,
		final PointMatchFilter filter,
		final double scale,
		final int numCoefficients )
{
	this.roi = roi;
	this.patchPair = patchPair;
	this.coefficientsTiles = coefficientsTiles;
	this.filter = filter;
	this.scale = scale;
	this.numCoefficients = numCoefficients;
}
 
Example #27
Source File: IlluminationSelectionPreviewGUI.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
/**
 * zip two collections into one List of Pairs [(s_o, t_0), (s_1, t_1), ...]
 * the size of the result will be the smaller size of the two input Collections 
 * @param s first
 * @param t second
 * @param <S> first item type
 * @param <T> second item type
 * @return zipped list of pairs
 */
public static <S,T> List<Pair<S,T>> zip(Collection<S> s, Collection<T> t)
{
	final List<Pair<S,T>> res = new ArrayList<>();
	
	Iterator< S > it1 = s.iterator();
	Iterator< T > it2 = t.iterator();
	
	while(it1.hasNext() && it2.hasNext())
		res.add( new ValuePair<>(it1.next(), it2.next()) );
	
	return res;
}
 
Example #28
Source File: TransformTools.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public static Pair<AffineGet, AffineGet> decomposeIntoAffineAndTranslation(AffineGet tr)
{
	AffineTransform3D t = new AffineTransform3D();
	t.set( tr.getRowPackedCopy() );
	t.set( 0, 0, 3 );
	t.set( 0, 1, 3 );
	t.set( 0, 2, 3 );
	AffineTransform3D tt = new AffineTransform3D();
	tt.set( tr.get( 0, 3 ), 0, 3 );
	tt.set( tr.get( 1, 3 ), 1, 3 );
	tt.set( tr.get( 2, 3 ), 2, 3 );
	
	return new ValuePair< AffineGet, AffineGet >( t, tt );
}
 
Example #29
Source File: LinkOverlay.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public void setSelectedLink(Pair<Group<ViewId>, Group<ViewId>> link)
{
	if (link == null)
		selectedLink = null;
	else
		selectedLink = new ValuePair<>( link.getA(), link.getB() );
}
 
Example #30
Source File: PairwiseStitching.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public static <T extends RealType< T >, C extends Comparable< C >> List< PairwiseStitchingResult< C > > getPairwiseShiftsLucasKanade(
		final Map< C, RandomAccessibleInterval< T > > rais, final Map< C, TranslationGet > translations,
		final LucasKanadeParameters params, final ExecutorService service)
{
	List< C > indexes = new ArrayList< >( rais.keySet() );
	Collections.sort( indexes );

	List< PairwiseStitchingResult< C > > result = new ArrayList< >();

	// got through all pairs with index1 < index2
	for ( int i = 0; i < indexes.size(); i++ )
	{
		for ( int j = i + 1; j < indexes.size(); j++ )
		{
			Pair< AffineTransform, Double > resT = getShiftLucasKanade( rais.get( indexes.get( i ) ), rais.get( indexes.get( j ) ),
					translations.get( indexes.get( i ) ), translations.get( indexes.get( j ) ), params, service );

			if ( resT != null )
			{
				Set<C> setA = new HashSet<>();
				setA.add( indexes.get( i ) );
				Set<C> setB = new HashSet<>();
				setA.add( indexes.get( j ) );
				Pair< Group<C>, Group<C> > key = new ValuePair<>(new Group<>(setA), new Group<>(setB));
				result.add( new PairwiseStitchingResult< C >( key, null, resT.getA() , resT.getB(), 0.0 ) );
			}
			
		}
	}

	return result;
}