-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathTestIntensityAdjustment.java
More file actions
171 lines (141 loc) · 7.28 KB
/
Copy pathTestIntensityAdjustment.java
File metadata and controls
171 lines (141 loc) · 7.28 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
/*-
* #%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.List;
import ij.ImageJ;
import mpicbg.models.AffineModel1D;
import mpicbg.models.IdentityModel;
import mpicbg.models.InterpolatedAffineModel1D;
import mpicbg.models.Point;
import mpicbg.models.PointMatch;
import mpicbg.models.TranslationModel1D;
import mpicbg.spim.data.SpimDataException;
import mpicbg.spim.data.sequence.ViewId;
import net.imglib2.Interval;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.imageplus.ImagePlusImgFactory;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.util.Pair;
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.process.export.DisplayImage;
import net.preibisch.mvrecon.process.fusion.FusionTools;
import net.preibisch.mvrecon.process.fusion.intensityadjust.IntensityAdjustmentTools;
import net.preibisch.mvrecon.process.fusion.transformed.TransformVirtual;
import net.preibisch.mvrecon.process.interestpointregistration.pairwise.constellation.grouping.Group;
public class TestIntensityAdjustment
{
public static void main( String[] args ) throws SpimDataException
{
final HashMap< Pair< Integer, Integer >, ArrayList< PointMatch > > intensityMatches = new HashMap<>();
final ArrayList< PointMatch > pm01 = new ArrayList<>();
pm01.add( new PointMatch( new Point( new double[] { 5 } ), new Point( new double[] { 10 } ) ) );
pm01.add( new PointMatch( new Point( new double[] { 10 } ), new Point( new double[] { 20 } ) ) );
pm01.add( new PointMatch( new Point( new double[] { 50 } ), new Point( new double[] { 100 } ) ) );
final ArrayList< PointMatch > pm02 = new ArrayList<>();
pm02.add( new PointMatch( new Point( new double[] { 5 } ), new Point( new double[] { 15 } ) ) );
pm02.add( new PointMatch( new Point( new double[] { 10 } ), new Point( new double[] { 30 } ) ) );
pm02.add( new PointMatch( new Point( new double[] { 50 } ), new Point( new double[] { 150 } ) ) );
final ArrayList< PointMatch > pm12 = new ArrayList<>();
pm12.add( new PointMatch( new Point( new double[] { 1 } ), new Point( new double[] { 1.5f } ) ) );
pm12.add( new PointMatch( new Point( new double[] { 10 } ), new Point( new double[] { 15 } ) ) );
intensityMatches.put( new ValuePair< Integer, Integer >( 0, 1 ), pm01 );
intensityMatches.put( new ValuePair< Integer, Integer >( 0, 2 ), pm02 );
intensityMatches.put( new ValuePair< Integer, Integer >( 1, 2 ), pm12 );
final HashMap< Integer, ViewId > viewMap = new HashMap<>();
viewMap.put( 0, new ViewId( 0, 1 ) );
viewMap.put( 1, new ViewId( 0, 2 ) );
viewMap.put( 2, new ViewId( 0, 3 ) );
//IntensityAdjustmentTools.runGlobal( intensityMatches, viewMap, new AffineModel1D() );
//System.exit( 0 );
new ImageJ();
// generate 4 views with 1000 corresponding beads, single timepoint
//
//SpimData2 spimData = SpimData2.convert( SimulatedBeadsImgLoader.spimdataExample( new int[]{ 0, 90, 135 } ) );
SpimData2 spimData = new XmlIoSpimData2().load( URI.create( "/Users/spreibi/Documents/BIMSB/Projects/CLARITY/Big Data Sticher/Neubias_preibisch/GridBalance/dataset.xml" ) );
System.out.println( "Views present:" );
for ( final ViewId viewId : spimData.getSequenceDescription().getViewDescriptions().values() )
System.out.println( Group.pvid( viewId ) );
testBalance( spimData );
}
public static void testBalance( final SpimData2 spimData )
{
//Interval bb = TestBoundingBox.testBoundingBox( spimData, false );
Interval bb = spimData.getBoundingBoxes().getBoundingBoxes().get( 0 );
System.out.println( bb );
// select views to process
final List< ViewId > viewIds = new ArrayList< ViewId >();
viewIds.addAll( spimData.getSequenceDescription().getViewDescriptions().values() );
// filter not present ViewIds
final List< ViewId > removed = SpimData2.filterMissingViews( spimData, viewIds );
IOFunctions.println( new Date( System.currentTimeMillis() ) + ": Removed " + removed.size() + " views because they are not present." );
// downsampling
double downsampling = 2;
double downsamplingEstimation = 20;
//
// display virtually fused
//
final InterpolatedAffineModel1D< InterpolatedAffineModel1D< AffineModel1D, TranslationModel1D >, IdentityModel > model =
new InterpolatedAffineModel1D<>(
new InterpolatedAffineModel1D<>( new AffineModel1D(), new TranslationModel1D(), 0.1 ),
new IdentityModel(), 0.1 );
final HashMap< ViewId, AffineModel1D > intensityMapping =
IntensityAdjustmentTools.computeIntensityAdjustment( spimData, viewIds, model, bb, downsamplingEstimation, Integer.MAX_VALUE, null );
// adjust bounding box
bb = FusionTools.createDownsampledBoundingBox( bb, downsampling ).getA();
// adjust registrations
final HashMap< ViewId, AffineTransform3D > registrations =
TransformVirtual.adjustAllTransforms(
viewIds,
spimData.getViewRegistrations().getViewRegistrations(),
Double.NaN,
downsampling );
final RandomAccessibleInterval< FloatType > virtualBalanced =
FusionTools.fuseVirtual(
spimData.getSequenceDescription().getImgLoader(),
registrations,
spimData.getSequenceDescription().getViewDescriptions(),
viewIds, FusionType.AVG, 1, FusionTools.defaultBlendingRange, bb, intensityMapping );
final RandomAccessibleInterval< FloatType > virtual =
FusionTools.fuseVirtual(
spimData.getSequenceDescription().getImgLoader(),
registrations,
spimData.getSequenceDescription().getViewDescriptions(),
viewIds, FusionType.AVG, 1, FusionTools.defaultBlendingRange, bb, null );
//
// actually fuse into an image multithreaded
//
final RandomAccessibleInterval< FloatType > fusedImg = FusionTools.copyImg( virtual, new ImagePlusImgFactory<>( new FloatType() ), new FloatType(), null, true );
final RandomAccessibleInterval< FloatType > fusedBalancedImg = FusionTools.copyImg( virtualBalanced, new ImagePlusImgFactory<>( new FloatType() ), new FloatType(), null, true );
DisplayImage.getImagePlusInstance( fusedImg, false, "Fused", 0, 255 ).show();
DisplayImage.getImagePlusInstance( fusedBalancedImg, false, "Fused Balanced", 0, 255 ).show();
}
}