Skip to content

Commit 41d8d66

Browse files
Merge branch 'JaneliaSciComp:main' into overlap_only_patch
2 parents be07892 + 185945c commit 41d8d66

11 files changed

Lines changed: 94 additions & 65 deletions

install

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ install_command detect-interestpoints "net.preibisch.bigstitcher.spark.SparkInte
124124
install_command match-interestpoints "net.preibisch.bigstitcher.spark.SparkGeometricDescriptorMatching"
125125
install_command stitching "net.preibisch.bigstitcher.spark.SparkPairwiseStitching"
126126
install_command solver "net.preibisch.bigstitcher.spark.Solver"
127+
install_command match-intensities "net.preibisch.bigstitcher.spark.SparkIntensityMatching"
128+
install_command solve-intensities "net.preibisch.bigstitcher.spark.IntensitySolver"
127129
install_command create-fusion-container "net.preibisch.bigstitcher.spark.CreateFusionContainer"
128130
install_command affine-fusion "net.preibisch.bigstitcher.spark.SparkAffineFusion"
129131
install_command nonrigid-fusion "net.preibisch.bigstitcher.spark.SparkNonRigidFusion"

pom.xml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,14 @@
9696
<bigdataviewer-core.version>10.6.1</bigdataviewer-core.version>
9797
<bigdataviewer-vistools.version>1.0.0-beta-36</bigdataviewer-vistools.version>
9898
-->
99-
<imglib2.version>7.1.4</imglib2.version>
100-
<imglib2-algorithm.version>0.18.0</imglib2-algorithm.version>
101-
<bigdataviewer-core.version>10.6.4</bigdataviewer-core.version>
99+
<imglib2.version>8.0.0</imglib2.version>
100+
<imglib2-cache.version>1.0.0-beta-20</imglib2-cache.version>
101+
<imglib2-algorithm.version>0.18.2</imglib2-algorithm.version>
102+
<bigdataviewer-core.version>10.6.5</bigdataviewer-core.version>
103+
<bigdataviewer-n5.version>1.0.2</bigdataviewer-n5.version>
104+
102105
<spim_data.version>2.3.5</spim_data.version>
103-
<multiview-reconstruction.version>7.0.5</multiview-reconstruction.version>
106+
<multiview-reconstruction.version>8.0.0</multiview-reconstruction.version>
104107
<BigStitcher.version>2.5.0</BigStitcher.version>
105108

106109
<n5-universe.version>2.3.0</n5-universe.version>
@@ -284,6 +287,11 @@
284287
<groupId>ome</groupId>
285288
<artifactId>formats-gpl</artifactId>
286289
</exclusion>
290+
<!-- in n5-google-cloud -->
291+
<exclusion>
292+
<groupId>javax.annotation</groupId>
293+
<artifactId>javax.annotation-api</artifactId>
294+
</exclusion>
287295
</exclusions>
288296
</dependency>
289297
<dependency>

src/main/java/net/preibisch/bigstitcher/spark/SparkAffineFusion.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import net.imglib2.FinalInterval;
5353
import net.imglib2.Interval;
5454
import net.imglib2.RandomAccessibleInterval;
55+
import net.imglib2.algorithm.blocks.BlockAlgoUtils;
5556
import net.imglib2.algorithm.blocks.BlockSupplier;
5657
import net.imglib2.converter.Converter;
5758
import net.imglib2.converter.RealUnsignedByteConverter;
@@ -558,7 +559,7 @@ else if ( dataType == DataType.UINT16 )
558559
}
559560

560561
//final RandomAccessibleInterval img;
561-
final BlockSupplier blockSupplier;
562+
final BlockSupplier< ? > blockSupplier;
562563
final FinalInterval interval = new FinalInterval( bbMin, bbMax );
563564

564565
if ( masks )
@@ -581,7 +582,7 @@ else if ( dataType == DataType.UINT16 )
581582
//
582583
// PREFETCHING, TODO: should be part of BlkAffineFusion.init
583584
//
584-
final OverlappingBlocks overlappingBlocks = OverlappingBlocks.find( dataLocal, overlappingViews, fusedBlock );
585+
final OverlappingBlocks overlappingBlocks = OverlappingBlocks.find( dataLocal, registrations, overlappingViews, fusedBlock );
585586
if ( overlappingBlocks.overlappingViews().isEmpty() )
586587
return gridBlock;
587588

@@ -605,6 +606,7 @@ else if ( dataType == DataType.UINT16 )
605606
registrations,
606607
dataLocal.getSequenceDescription().getViewDescriptions(),
607608
fusionType,//fusion.getFusionType(),
609+
Double.NaN,
608610
null, // map<old,new> will go here
609611
1, // linear interpolation
610612
coefficients, // intensity correction
@@ -622,7 +624,7 @@ else if ( dataType == DataType.UINT16 )
622624
blockMax[ d ] = Math.min( Intervals.zeroMin( interval ).max( d ), blockMin[ d ] + gridBlock[1][ d ] - 1 );
623625

624626
final RandomAccessibleInterval image;
625-
final RandomAccessibleInterval img = BlkAffineFusion.arrayImg( blockSupplier, new FinalInterval( blockMin, blockMax ) );
627+
final RandomAccessibleInterval img = BlockAlgoUtils.arrayImg( blockSupplier, new FinalInterval( blockMin, blockMax ) );
626628

627629
// 5D OME-ZARR CONTAINER
628630
if ( storageType == StorageFormat.ZARR )

src/main/java/net/preibisch/bigstitcher/spark/SparkGeometricDescriptorMatching.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,13 @@ public enum Method { FAST_ROTATION, FAST_TRANSLATION, PRECISE_TRANSLATION, ICP }
139139
@Option(names = { "-rmir", "--ransacMinInlierRatio" }, description = "ransac min inlier ratio (default: 0.1)")
140140
protected Double ransacMinInlierRatio = 0.1;
141141

142-
@Option(names = { "-rmif", "--ransacMinInlierFactor" }, description = "ransac min inlier factor, i.e. how many time the minimal number of matches need to found, e.g. affine needs 4 matches, 3x means at least 12 matches required (default: 3.0)")
143-
protected Double ransacMinInlierFactor = 3.0;
142+
@Option(names = { "-rmni", "--ransacMinNumInliers" }, description = "ransac minimal number of required inliers (default: 12)")
143+
protected Integer ransacMinNumInliers = 12;
144+
145+
@Option(names = { "-rmc", "--ransacMultiConsensus" }, description = "ransac perform multiconsensus matching (default: false)")
146+
protected boolean ransacMultiConsensus = false;
147+
144148

145-
146149
@Option(names = { "-ime", "--icpMaxError" }, description = "ICP max error in pixels (default: 5.0)")
147150
protected Double icpMaxError = 5.0;
148151

@@ -220,7 +223,8 @@ else if ( ransacIterations == null )
220223
final int ransacIterations = this.ransacIterations;
221224
final double ransacMaxEpsilon = this.ransacMaxError;
222225
final double ransacMinInlierRatio = this.ransacMinInlierRatio;
223-
final double ransacMinInlierFactor = this.ransacMinInlierFactor;
226+
final int ransacMinNumInliers = this.ransacMinNumInliers;
227+
final boolean ransacMultiConsensus = this.ransacMultiConsensus;
224228
final double icpMaxError = this.icpMaxError;
225229
final int icpMaxIterations = this.icpIterations;
226230
final boolean icpUseRANSAC = this.icpUseRANSAC;
@@ -300,7 +304,7 @@ else if ( ransacIterations == null )
300304
System.out.println( Group.pvid( element.getKey() ) + ", '" + subElement.getKey() + "' : " + subElement.getValue().size() );
301305
}
302306

303-
final RANSACParameters rp = new RANSACParameters( (float)ransacMaxEpsilon, (float)ransacMinInlierRatio, (float)ransacMinInlierFactor, ransacIterations );
307+
final RANSACParameters rp = new RANSACParameters( (float)ransacMaxEpsilon, (float)ransacMinInlierRatio, ransacMinNumInliers, ransacIterations, ransacMultiConsensus );
304308
final Model< ? > model = createModelInstance(transformationModel, regularizationModel, lambda);
305309

306310
final MatcherPairwise< InterestPoint > matcher = createMatcherInstance(
@@ -424,7 +428,7 @@ else if ( ransacIterations == null )
424428
groupedInterestpoints.put( task.vB, ipGrouping.group( task.vB ) );
425429
IOFunctions.println( task.vA + " <=> " + task.vB + ": Grouping interestpoints for " + task.vB + " (" + ipGrouping.countBefore() + " >>> " + ipGrouping.countAfter() + ")" );
426430

427-
final RANSACParameters rp = new RANSACParameters( (float)ransacMaxEpsilon, (float)ransacMinInlierRatio, (float)ransacMinInlierFactor, ransacIterations );
431+
final RANSACParameters rp = new RANSACParameters( (float)ransacMaxEpsilon, (float)ransacMinInlierRatio, ransacMinNumInliers, ransacIterations, ransacMultiConsensus );
428432
final Model< ? > model = createModelInstance(transformationModel, regularizationModel, lambda);
429433

430434
final MatcherPairwise< GroupedInterestPoint< ViewId > > matcher = createMatcherInstance(
@@ -609,7 +613,7 @@ else if ( registrationMethod == Method.PRECISE_TRANSLATION )
609613
rp.getMinInlierRatio(),
610614
rp.getMaxEpsilon(),
611615
rp.getNumIterations(),
612-
Math.round( rp.getMinInlierFactor() * model.getMinNumMatches() ) );
616+
rp.getMinNumMatches() );
613617
matcher = new IterativeClosestPointPairwise<>( ip );
614618
}
615619

src/main/java/net/preibisch/bigstitcher/spark/SparkIntensityMatching.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434

3535
public class SparkIntensityMatching extends AbstractSelectableViews
3636
{
37+
public enum IntensityMatchingMethod
38+
{
39+
RANSAC, HISTOGRAM
40+
}
41+
3742
@Option(names = { "--numCoefficients" }, description = "number of coefficients per dimension (default: 8,8,8)")
3843
private String numCoefficientsString = "8,8,8";
3944

@@ -52,19 +57,23 @@ public class SparkIntensityMatching extends AbstractSelectableViews
5257
@Option(names = { "--minNumCandidates" }, description = "minimum number of (non-discarded) overlapping pixels required to match overlapping coefficient regions (default: 1000)")
5358
private int minNumCandidates = 1000;
5459

60+
@Option(names = {"--method"}, defaultValue = "RANSAC", showDefaultValue = CommandLine.Help.Visibility.ALWAYS,
61+
description = "Method to match intensities between overlapping views: RANSAC or HISTOGRAM")
62+
private IntensityMatchingMethod intensityMatchingMethod;
63+
5564
@CommandLine.Option(names = { "--numIterations" }, description = "number of RANSAC iterations (default: 1000)")
5665
private int iterations = 1000;
5766

58-
@CommandLine.Option(names = { "--maxEpsilon" }, description = "maximal allowed transfer error (default: 5.1)")
67+
@CommandLine.Option(names = { "--maxEpsilon" }, description = "maximal allowed transfer error (default: 5.1, only for RANSAC method)")
5968
private double maxEpsilon = 0.02 * 255;
6069

61-
@CommandLine.Option(names = { "--minInlierRatio" }, description = "minimal ratio of of inliers to number of candidates (default: 0.1)")
70+
@CommandLine.Option(names = { "--minInlierRatio" }, description = "minimal ratio of of inliers to number of candidates (default: 0.1, only for RANSAC method)")
6271
private double minInlierRatio = 0.1;
6372

64-
@CommandLine.Option(names = { "--minNumInliers" }, description = "minimally required absolute number of inliers (default: 10)")
73+
@CommandLine.Option(names = { "--minNumInliers" }, description = "minimally required absolute number of inliers (default: 10, only for RANSAC method)")
6574
private int minNumInliers = 10;
6675

67-
@CommandLine.Option(names = { "--maxTrust" }, description = "reject candidates with a cost larger than maxTrust * median cost (default: 3)")
76+
@CommandLine.Option(names = { "--maxTrust" }, description = "reject candidates with a cost larger than maxTrust * median cost (default: 3, only for RANSAC method)")
6877
private double maxTrust = 3.0;
6978

7079
private SpimData2 dataGlobal;
@@ -100,6 +109,7 @@ public Void call() throws Exception
100109
final double minInlierRatio = this.minInlierRatio;
101110
final int minNumInliers = this.minNumInliers;
102111
final double maxTrust = this.maxTrust;
112+
final IntensityMatchingMethod method = this.intensityMatchingMethod;
103113

104114
new ViewPairCoefficientMatchesIO( outputURI ).writeCoefficientsSize( coefficientsSize );
105115

@@ -156,8 +166,18 @@ public Void call() throws Exception
156166
viewPairRDD.foreach( views -> {
157167
final SpimData2 dataLocal = Spark.getSparkJobSpimData2( xmlURI );
158168
System.out.println( "(" + new Date( System.currentTimeMillis() ) + "): " + views._1().getViewSetupId() + "<>" + views._2().getViewSetupId() );
159-
final ViewPairCoefficientMatches matches = IntensityCorrection.match( dataLocal, views._1(), views._2(), renderScale, coefficientsSize,
160-
minIntensityThreshold, maxIntensityThreshold, minNumCandidates, iterations, maxEpsilon, minInlierRatio, minNumInliers, maxTrust );
169+
170+
final ViewPairCoefficientMatches matches;
171+
if ( method == IntensityMatchingMethod.RANSAC )
172+
{
173+
matches = IntensityCorrection.matchRansac( dataLocal, views._1(), views._2(), renderScale, coefficientsSize,
174+
minIntensityThreshold, maxIntensityThreshold, minNumCandidates, iterations, maxEpsilon, minInlierRatio, minNumInliers, maxTrust );
175+
}
176+
else // method == IntensityMatchingMethod.HISTOGRAM
177+
{
178+
matches = IntensityCorrection.matchHistograms( dataLocal, views._1(), views._2(), renderScale, coefficientsSize,
179+
minIntensityThreshold, maxIntensityThreshold, minNumCandidates );
180+
}
161181
final ViewPairCoefficientMatchesIO matchWriter = new ViewPairCoefficientMatchesIO(outputURI);
162182
matchWriter.write( matches );
163183
} );

src/main/java/net/preibisch/bigstitcher/spark/SparkInterestPointDetection.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
import net.preibisch.mvrecon.process.downsampling.Downsample;
9292
import net.preibisch.mvrecon.process.downsampling.DownsampleTools;
9393
import net.preibisch.mvrecon.process.downsampling.lazy.LazyDownsample2x;
94+
import net.preibisch.mvrecon.process.fusion.transformed.TransformVirtual;
9495
import net.preibisch.mvrecon.process.interestpointdetection.InterestPointTools;
9596
import net.preibisch.mvrecon.process.interestpointdetection.methods.dog.DoGImgLib2;
9697
import net.preibisch.mvrecon.process.interestpointdetection.methods.dog.DoGParameters;
@@ -242,13 +243,20 @@ public Void call() throws Exception
242243
// assemble all pairs for parallelization with Spark
243244
final ArrayList< Tuple2< ViewId, ViewId > > metadataJobs = new ArrayList<>();
244245

246+
final HashMap< ViewId, AffineTransform3D > registrations =
247+
TransformVirtual.adjustAllTransforms(
248+
viewIdsGlobal,
249+
dataGlobal.getViewRegistrations().getViewRegistrations(),
250+
Double.NaN,
251+
Double.NaN );
252+
245253
for ( final ViewId viewDesc : viewIdsGlobal )
246254
{
247255
final ViewId viewId = new ViewId( viewDesc.getTimePointId(), viewDesc.getViewSetupId() );
248256

249257
if ( onlyOverlappingRegions )
250258
{
251-
for ( final ViewId otherViewId : OverlappingViews.findAllOverlappingViewsFor( viewId, dataGlobal, viewIdsGlobal ) )
259+
for ( final ViewId otherViewId : OverlappingViews.findAllOverlappingViewsFor( viewId, dataGlobal, registrations, viewIdsGlobal ) )
252260
{
253261
if ( !otherViewId.equals( viewId ) )
254262
{
@@ -514,7 +522,7 @@ public Void call() throws Exception
514522

515523
// here we put in the inverse mipmap transform and pretend its a fusion so we can re-use Tobi's code
516524
// that finds which blocks need to be prefetched from an input image
517-
final List< PrefetchPixel< ? > > prefetchBlocks = ViewUtil.findOverlappingBlocks( data, viewId, input.getB().inverse(), processInterval, maxKernelSize );
525+
final List< PrefetchPixel< ? > > prefetchBlocks = ViewUtil.findOverlappingBlocks( data, viewId, processInterval, input.getB().inverse(), maxKernelSize );
518526

519527
System.out.println( "Prefetching " + prefetchBlocks.size() + " blocks for " + Group.pvid(viewId) + ", " + Util.printInterval( processInterval ) );
520528

src/main/java/net/preibisch/bigstitcher/spark/SparkNonRigidFusion.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ else if ( uint16 )
331331
final ViewId viewId = Spark.deserializeViewIds(serializedViewIds, i);
332332

333333
// expand by 50 to be conservative for non-rigid overlaps
334-
final Interval boundingBox = ViewUtil.getTransformedBoundingBox( dataLocal, viewId );
334+
dataLocal.getViewRegistrations().getViewRegistration( viewId ).updateModel();
335+
final Interval boundingBox = ViewUtil.getTransformedBoundingBox( dataLocal, viewId, dataLocal.getViewRegistrations().getViewRegistration( viewId ).getModel() );
335336
final Interval bounds = Intervals.expand( boundingBox, 50 );
336337
// TODO: estimate the "50" from the distance of corresponding, transformed interest points
337338

@@ -351,12 +352,14 @@ else if ( uint16 )
351352

352353
for ( final ViewId viewId : allViews )
353354
{
354-
final Interval boundingBoxView = ViewUtil.getTransformedBoundingBox( dataLocal, viewId );
355+
dataLocal.getViewRegistrations().getViewRegistration( viewId ).updateModel();
356+
final Interval boundingBoxView = ViewUtil.getTransformedBoundingBox( dataLocal, viewId, dataLocal.getViewRegistrations().getViewRegistration( viewId ).getModel() );
355357
final Interval boundsView = Intervals.expand( boundingBoxView, 25 );
356358

357359
for ( final ViewId fusedId : viewsToFuse )
358360
{
359-
final Interval boundingBoxFused = ViewUtil.getTransformedBoundingBox( dataLocal, fusedId );
361+
dataLocal.getViewRegistrations().getViewRegistration( fusedId ).updateModel();
362+
final Interval boundingBoxFused = ViewUtil.getTransformedBoundingBox( dataLocal, fusedId, dataLocal.getViewRegistrations().getViewRegistration( fusedId ).getModel() );
360363
final Interval boundsFused = Intervals.expand( boundingBoxFused, 25 );
361364

362365
if ( ViewUtil.overlaps( boundsView, boundsFused ))

src/main/java/net/preibisch/bigstitcher/spark/abstractcmdline/AbstractBasic.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
public abstract class AbstractBasic extends AbstractInfrastructure implements Callable<Void>, Serializable
3838
{
39+
static { net.preibisch.legacy.io.IOFunctions.printIJLog = false; }
40+
3941
private static final long serialVersionUID = -4916959775650710928L;
4042

4143
@Option(names = { "-x", "--xml" }, required = true, description = "Path to the existing BigStitcher project xml, e.g. -x /home/project.xml or -x s3://mybucket/data/dataset.xml or -x file:/home/project.xml")

src/main/java/net/preibisch/bigstitcher/spark/fusion/OverlappingBlocks.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package net.preibisch.bigstitcher.spark.fusion;
2323

2424
import java.util.ArrayList;
25+
import java.util.HashMap;
2526
import java.util.List;
2627
import java.util.concurrent.Callable;
2728
import java.util.concurrent.ExecutorService;
@@ -30,6 +31,7 @@
3031
import mpicbg.spim.data.SpimData;
3132
import mpicbg.spim.data.sequence.ViewId;
3233
import net.imglib2.Interval;
34+
import net.imglib2.realtransform.AffineTransform3D;
3335
import net.imglib2.util.Intervals;
3436
import net.preibisch.bigstitcher.spark.util.ViewUtil;
3537
import net.preibisch.bigstitcher.spark.util.ViewUtil.PrefetchPixel;
@@ -46,7 +48,9 @@ public class OverlappingBlocks
4648
* {@code interval}.
4749
*
4850
* @param data
49-
* has all images and transformations
51+
* has all image sizes
52+
* @param registrations
53+
* registrations, maybe updated to reflect anisotropy
5054
* @param viewIds
5155
* which views to check
5256
* @param interval
@@ -55,6 +59,7 @@ public class OverlappingBlocks
5559
*/
5660
public static OverlappingBlocks find(
5761
final SpimData data,
62+
final HashMap< ViewId, AffineTransform3D > registrations,
5863
final List<ViewId> viewIds,
5964
Interval interval )
6065
{
@@ -66,11 +71,11 @@ public static OverlappingBlocks find(
6671

6772
for ( final ViewId viewId : viewIds )
6873
{
69-
final Interval bounds = ViewUtil.getTransformedBoundingBox( data, viewId );
74+
final Interval bounds = ViewUtil.getTransformedBoundingBox( data, viewId, registrations.get( viewId ) );
7075
if ( ViewUtil.overlaps( expandedInterval, bounds ) )
7176
{
7277
// determine which Cells exactly we need to compute the fused block
73-
final List< PrefetchPixel< ? > > blocks = ViewUtil.findOverlappingBlocks( data, viewId, interval );
78+
final List< PrefetchPixel< ? > > blocks = ViewUtil.findOverlappingBlocks( data, viewId, interval, registrations.get( viewId ) );
7479
if ( !blocks.isEmpty() )
7580
{
7681
prefetch.addAll( blocks );

0 commit comments

Comments
 (0)