-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathTestNonRigid.java
More file actions
216 lines (176 loc) · 8.01 KB
/
Copy pathTestNonRigid.java
File metadata and controls
216 lines (176 loc) · 8.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*-
* #%L
* Software for the reconstruction of multi-view microscopic acquisitions
* like Selective Plane Illumination Microscopy (SPIM) Data.
* %%
* Copyright (C) 2012 - 2024 Multiview Reconstruction developers.
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/
package net.preibisch.mvrecon.headless.fusion;
import java.net.URI;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ExecutorService;
import com.google.common.collect.Sets;
import ij.ImageJ;
import mpicbg.spim.data.SpimDataException;
import mpicbg.spim.data.sequence.ViewId;
import net.imglib2.Interval;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.util.Pair;
import net.imglib2.util.Util;
import net.imglib2.util.ValuePair;
import net.preibisch.legacy.io.IOFunctions;
import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType;
import net.preibisch.mvrecon.fiji.spimdata.SpimData2;
import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2;
import net.preibisch.mvrecon.fiji.spimdata.boundingbox.BoundingBox;
import net.preibisch.mvrecon.headless.boundingbox.TestBoundingBox;
import net.preibisch.mvrecon.process.deconvolution.DeconViews;
import net.preibisch.mvrecon.process.export.DisplayImage;
import net.preibisch.mvrecon.process.fusion.FusionTools;
import net.preibisch.mvrecon.process.fusion.transformed.TransformVirtual;
import net.preibisch.mvrecon.process.fusion.transformed.nonrigid.NonRigidTools;
public class TestNonRigid
{
public static void main( String[] args ) throws SpimDataException
{
new ImageJ();
SpimData2 spimData;
// load drosophila
spimData = new XmlIoSpimData2( ).load( URI.create( "/Users/preibischs/Documents/Microscopy/SPIM/HisYFP-SPIM/dataset.xml" ) );
Pair< List< ViewId >, Interval > fused = testInterpolation( spimData, "My Bounding Box" );
// for bounding box1111 test 128,128,128 vs 256,256,256 (no blocks), there are differences at the edges
compareToFusion( spimData, fused.getA(), fused.getB() );
}
public static void compareToFusion(
final SpimData2 spimData,
final List< ViewId > fused,
Interval boundingBox )
{
// downsampling
double downsampling = Double.NaN;
//
// display virtually fused
//
IOFunctions.println( new Date( System.currentTimeMillis() ) + ": starting with affine" );
// adjust bounding box
boundingBox = FusionTools.createDownsampledBoundingBox( boundingBox, downsampling ).getA();
// adjust registrations
final HashMap< ViewId, AffineTransform3D > registrations =
TransformVirtual.adjustAllTransforms(
fused,
spimData.getViewRegistrations().getViewRegistrations(),
Double.NaN,
downsampling );
final RandomAccessibleInterval< FloatType > virtual =
FusionTools.fuseVirtual(
spimData.getSequenceDescription().getImgLoader(),
registrations,
spimData.getSequenceDescription().getViewDescriptions(),
fused, FusionType.AVG_BLEND, boundingBox );
DisplayImage.getImagePlusInstance( virtual, false, "Fused Affine", 0, 255 ).show();
IOFunctions.println( new Date( System.currentTimeMillis() ) + ": done with affine" );
}
public static Pair< List< ViewId >, Interval > testInterpolation(
final SpimData2 spimData,
final String bbTitle )
{
Interval boundingBox = TestBoundingBox.getBoundingBox( spimData, bbTitle );
if ( boundingBox == null )
return null;
IOFunctions.println( BoundingBox.getBoundingBoxDescription( (BoundingBox)boundingBox ) );
// select views to process
final List< ViewId > viewsToFuse = new ArrayList< ViewId >(); // fuse
final List< ViewId > viewsToUse = new ArrayList< ViewId >(); // used to compute the non-rigid transform
viewsToUse.addAll( spimData.getSequenceDescription().getViewDescriptions().values() );
viewsToFuse.addAll( spimData.getSequenceDescription().getViewDescriptions().values() );
//viewsToFuse.add( new ViewId( 0, 0 ) );
//viewsToFuse.add( new ViewId( 0, 1 ) );
//viewsToFuse.add( new ViewId( 0, 2 ) );
//viewsToFuse.add( new ViewId( 0, 3 ) );
// filter not present ViewIds
List< ViewId > removed = SpimData2.filterMissingViews( spimData, viewsToUse );
IOFunctions.println( new Date( System.currentTimeMillis() ) + ": Removed " + removed.size() + " views because they are not present." );
removed = SpimData2.filterMissingViews( spimData, viewsToFuse );
IOFunctions.println( new Date( System.currentTimeMillis() ) + ": Removed " + removed.size() + " views because they are not present." );
// downsampling
final double downsampling = Double.NaN;
final double ds = Double.isNaN( downsampling ) ? 1.0 : downsampling;
final int cpd = Math.max( 1, (int)Math.round( 10 / ds ) );
//
// display virtually fused
//
final ArrayList< String > labels = new ArrayList<>();
//labels.add( "beads" );
//labels.add( "beads13" );
labels.add( "nuclei" );
final int interpolation = 1;
final float blendingRange = 40;
final long[] controlPointDistance = new long[] { cpd, cpd, cpd };
final double alpha = 1.0;
final boolean virtualGrid = false;
final boolean displayDistances = false;
final ExecutorService service = DeconViews.createExecutorService();
IOFunctions.println( new Date( System.currentTimeMillis() ) + ": controlPointDistance = " + Util.printCoordinates( controlPointDistance ) );
IOFunctions.println( new Date( System.currentTimeMillis() ) + ": starting with non-rigid" );
// adjust bounding box
boundingBox = FusionTools.createDownsampledBoundingBox( boundingBox, downsampling ).getA();
// adjust registrations
final HashMap< ViewId, AffineTransform3D > registrations =
TransformVirtual.adjustAllTransforms(
Sets.union( new HashSet<>( viewsToFuse ), new HashSet<>( viewsToUse ) ),
spimData.getViewRegistrations().getViewRegistrations(),
Double.NaN,
downsampling );
final RandomAccessibleInterval< FloatType > virtual =
NonRigidTools.fuseVirtualInterpolatedNonRigid(
spimData.getSequenceDescription().getImgLoader(),
registrations,
spimData.getViewInterestPoints().getViewInterestPoints(),
spimData.getSequenceDescription().getViewDescriptions(),
viewsToFuse,
viewsToUse,
labels,
FusionType.AVG_BLEND,
displayDistances,
controlPointDistance,
alpha,
virtualGrid,
interpolation,
blendingRange,
boundingBox,
null,
service );
service.shutdown();
//final RandomAccessibleInterval< FloatType > out = FusionTools.copyImgByPlane3d( virtual, new ImagePlusImgFactory< FloatType >( new FloatType() ), service, true );
//final RandomAccessibleInterval< FloatType > out = FusionTools.copyImg( virtual, new ImagePlusImgFactory< FloatType >(), new FloatType(), service, true );
//final RandomAccessibleInterval< FloatType > out = ImageJFunctions.wrapFloat( DisplayImage.getImagePlusInstance( virtual, false, "Fused Non-rigid", 0, 255 ) );
// Non-rigid fusion took: 314887 ms.
long time = System.currentTimeMillis();
DisplayImage.getImagePlusInstance( virtual, false, "Fused Non-rigid", 0, 255 ).show();
System.out.println( "Non-rigid fusion took: " + (System.currentTimeMillis() - time) + " ms.");
IOFunctions.println( new Date( System.currentTimeMillis() ) + ": done with non-rigid" );
return new ValuePair<>( viewsToFuse, boundingBox );
}
}