Skip to content

Commit d69f72a

Browse files
fix bug described here: JaneliaSciComp/BigStitcher-Spark#45
1 parent eac1e53 commit d69f72a

6 files changed

Lines changed: 37 additions & 46 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ else if ( dataType == DataType.UINT16 )
581581
//
582582
// PREFETCHING, TODO: should be part of BlkAffineFusion.init
583583
//
584-
final OverlappingBlocks overlappingBlocks = OverlappingBlocks.find( dataLocal, overlappingViews, fusedBlock );
584+
final OverlappingBlocks overlappingBlocks = OverlappingBlocks.find( dataLocal, registrations, overlappingViews, fusedBlock );
585585
if ( overlappingBlocks.overlappingViews().isEmpty() )
586586
return gridBlock;
587587

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import net.preibisch.mvrecon.process.downsampling.Downsample;
9090
import net.preibisch.mvrecon.process.downsampling.DownsampleTools;
9191
import net.preibisch.mvrecon.process.downsampling.lazy.LazyDownsample2x;
92+
import net.preibisch.mvrecon.process.fusion.transformed.TransformVirtual;
9293
import net.preibisch.mvrecon.process.interestpointdetection.InterestPointTools;
9394
import net.preibisch.mvrecon.process.interestpointdetection.methods.dog.DoGImgLib2;
9495
import net.preibisch.mvrecon.process.interestpointdetection.methods.dog.DoGParameters;
@@ -240,13 +241,20 @@ public Void call() throws Exception
240241
// assemble all pairs for parallelization with Spark
241242
final ArrayList< Tuple2< ViewId, ViewId > > metadataJobs = new ArrayList<>();
242243

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

247255
if ( onlyOverlappingRegions )
248256
{
249-
for ( final ViewId otherViewId : OverlappingViews.findAllOverlappingViewsFor( viewId, dataGlobal, viewIdsGlobal ) )
257+
for ( final ViewId otherViewId : OverlappingViews.findAllOverlappingViewsFor( viewId, dataGlobal, registrations, viewIdsGlobal ) )
250258
{
251259
if ( !otherViewId.equals( viewId ) )
252260
{
@@ -512,7 +520,7 @@ public Void call() throws Exception
512520

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

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

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/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 );

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

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,7 @@ public class OverlappingViews
2222
* @param spimData contains bounds and registrations for all views
2323
* @param viewIds which views to check
2424
* @param interval interval in world coordinates
25-
* @return views that overlap {@code interval}
26-
*/
27-
public static List<ViewId> findOverlappingViews(
28-
final SpimData spimData,
29-
final List<ViewId> viewIds,
30-
final Interval interval )
31-
{
32-
final List< ViewId > overlapping = new ArrayList<>();
33-
34-
// expand to be conservative ...
35-
final Interval expandedInterval = Intervals.expand( interval, 2 );
36-
37-
for ( final ViewId viewId : viewIds )
38-
{
39-
final Interval bounds = ViewUtil.getTransformedBoundingBox( spimData, viewId );
40-
if ( ViewUtil.overlaps( expandedInterval, bounds ) )
41-
overlapping.add( viewId );
42-
}
43-
44-
return overlapping;
45-
}
46-
47-
/**
48-
* Find all views among the given {@code viewIds} that overlap the given {@code interval}.
49-
* The image interval of each view is transformed into world coordinates
50-
* and checked for overlap with {@code interval}, with a conservative
51-
* extension of 2 pixels in each direction.
52-
*
53-
* @param spimData contains bounds and registrations for all views
54-
* @param viewIds which views to check
55-
* @param interval interval in world coordinates
25+
* @param registrations registrations for each view, may be adjusted for anisotropy
5626
* @return views that overlap {@code interval}
5727
*/
5828
public static List<ViewId> findOverlappingViews(
@@ -79,18 +49,19 @@ public static List<ViewId> findOverlappingViews(
7949
public static ArrayList< ViewId > findAllOverlappingViewsFor(
8050
final ViewId viewIdA,
8151
final SpimData spimData,
52+
final HashMap< ViewId, AffineTransform3D > registrations,
8253
final List<ViewId> viewIds)
8354
{
8455
final ArrayList< ViewId > overlappingViews = new ArrayList<>();
8556

86-
final Interval bounds1 = ViewUtil.getTransformedBoundingBox( spimData, viewIdA );
57+
final Interval bounds1 = ViewUtil.getTransformedBoundingBox( spimData, viewIdA, registrations.get( viewIdA ) );
8758

8859
for ( final ViewId viewIdB : viewIds )
8960
{
9061
if ( viewIdA.equals( viewIdB ) )
9162
continue;
9263

93-
final Interval bounds2 = ViewUtil.getTransformedBoundingBox( spimData, viewIdB );
64+
final Interval bounds2 = ViewUtil.getTransformedBoundingBox( spimData, viewIdB, registrations.get( viewIdB ) );
9465

9566
if ( ViewUtil.overlaps( bounds1, bounds2 ) )
9667
overlappingViews.add( viewIdB );

src/main/java/net/preibisch/bigstitcher/spark/util/ViewUtil.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,15 @@ public static ViewRegistration getViewRegistration(final SpimData data, final Vi
136136
* This transforms the image dimension for {@code viewId} with the {@code
137137
* ViewRegistration} for {@code viewId}, and takes the bounding box.
138138
*/
139+
/*
139140
public static Interval getTransformedBoundingBox( final SpimData data, final ViewId viewId ) throws IllegalArgumentException
140141
{
141142
final Dimensions dim = getDimensions( data, viewId );
142143
final ViewRegistration reg = getViewRegistration( data, viewId );
143144
144145
return Intervals.smallestContainingInterval( reg.getModel().estimateBounds( new FinalInterval( dim ) ) );
145146
}
147+
*/
146148

147149
/**
148150
* Get the estimated bounding box of the specified view in world coordinates.
@@ -173,15 +175,17 @@ public static String viewIdToString(final ViewId viewId) {
173175
* which view to check
174176
* @param fusedBlock
175177
* the interval that will be processed (in world coordinates)
176-
*
178+
* @param model
179+
* the transformation model applied to the View during fusion
177180
* @return a list of {@code PrefetchPixel} callables that will each prefetch one cell.
178181
*/
179182
public static List< PrefetchPixel< ? > > findOverlappingBlocks(
180183
final SpimData data,
181184
final ViewId viewId,
182-
final Interval fusedBlock )
185+
final Interval fusedBlock,
186+
final AffineTransform3D model )
183187
{
184-
return findOverlappingBlocks(data, viewId, data.getViewRegistrations().getViewRegistration( viewId ).getModel(), fusedBlock, 1 );
188+
return findOverlappingBlocks(data, viewId, fusedBlock, model, 1 );
185189
}
186190

187191
/**
@@ -206,8 +210,8 @@ public static String viewIdToString(final ViewId viewId) {
206210
public static List< PrefetchPixel< ? > > findOverlappingBlocks(
207211
final SpimData data,
208212
final ViewId viewId,
209-
final AffineTransform3D model,
210213
final Interval fusedBlock,
214+
final AffineTransform3D model,
211215
final int expand )
212216
{
213217
final List< PrefetchPixel< ? > > prefetch = new ArrayList<>();

0 commit comments

Comments
 (0)