Skip to content

Commit 673f10e

Browse files
moved example code for interest points to src/test
1 parent ed64375 commit 673f10e

3 files changed

Lines changed: 153 additions & 129 deletions

File tree

src/main/java/net/preibisch/mvrecon/fiji/spimdata/interestpoints/InterestPointsN5.java

Lines changed: 0 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.io.File;
2626
import java.net.URI;
2727
import java.util.ArrayList;
28-
import java.util.Arrays;
2928
import java.util.HashMap;
3029
import java.util.HashSet;
3130
import java.util.List;
@@ -39,148 +38,20 @@
3938
import org.janelia.saalfeldlab.n5.imglib2.N5Utils;
4039
import org.janelia.saalfeldlab.n5.universe.StorageFormat;
4140

42-
import ij.ImageJ;
43-
import mpicbg.spim.data.SpimDataException;
44-
import mpicbg.spim.data.registration.ViewRegistration;
45-
import mpicbg.spim.data.sequence.MultiResolutionSetupImgLoader;
46-
import mpicbg.spim.data.sequence.SequenceDescription;
47-
import mpicbg.spim.data.sequence.SetupImgLoader;
48-
import mpicbg.spim.data.sequence.ViewDescription;
4941
import mpicbg.spim.data.sequence.ViewId;
5042
import net.imglib2.RandomAccess;
5143
import net.imglib2.RandomAccessibleInterval;
52-
import net.imglib2.img.display.imagej.ImageJFunctions;
53-
import net.imglib2.multithreading.SimpleMultiThreading;
5444
import net.imglib2.position.FunctionRandomAccessible;
55-
import net.imglib2.realtransform.AffineTransform3D;
5645
import net.imglib2.type.numeric.integer.UnsignedLongType;
5746
import net.imglib2.type.numeric.real.DoubleType;
5847
import net.imglib2.util.Pair;
5948
import net.imglib2.util.ValuePair;
6049
import net.imglib2.view.Views;
6150
import net.preibisch.legacy.io.IOFunctions;
62-
import net.preibisch.mvrecon.fiji.spimdata.SpimData2;
63-
import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2;
64-
import net.preibisch.mvrecon.process.interestpointregistration.pairwise.constellation.grouping.Group;
6551
import util.URITools;
6652

6753
public class InterestPointsN5 extends InterestPoints
6854
{
69-
public static void main( String[] args ) throws SpimDataException
70-
{
71-
int viewSetupId = 1;
72-
73-
//
74-
// works without the XML, just loads the N5 directly
75-
//
76-
InterestPointsN5 ip = new InterestPointsN5(
77-
URI.create("/nrs/saalfeld/john/for/keller/danio_1_488/dataset-orig-tifs/3/"),
78-
"tpId_0_viewSetupId_" + viewSetupId + "/beads8v2" );
79-
80-
List<InterestPoint> points = ip.getInterestPointsCopy();
81-
82-
for ( final InterestPoint p : points )
83-
{
84-
//System.out.println( p.getId() + " " + Arrays.toString( p.getL() ));
85-
}
86-
87-
//
88-
// this needs the XML
89-
//
90-
SpimData2 data = new XmlIoSpimData2().load( URI.create("file:/nrs/saalfeld/john/for/keller/danio_1_488/dataset-orig-tifs/3/dataset-stephan.xml") );
91-
92-
ViewId myViewId = new ViewId( 0, viewSetupId );
93-
94-
// calibration etc
95-
SequenceDescription sd = data.getSequenceDescription();
96-
ViewDescription vd = sd.getViewDescription( myViewId );
97-
System.out.println( "voxelSize: " + Arrays.toString( vd.getViewSetup().getVoxelSize().dimensionsAsDoubleArray() ) );
98-
System.out.println( "tile id: " + vd.getViewSetup().getTile().getId() );
99-
100-
SetupImgLoader<?> setupImgLoader = sd.getImgLoader().getSetupImgLoader( myViewId.getViewSetupId() );
101-
102-
// full res
103-
RandomAccessibleInterval<?> img = setupImgLoader.getImage( myViewId.getTimePointId() );
104-
105-
// multi-res
106-
if ( MultiResolutionSetupImgLoader.class.isInstance( setupImgLoader ) )
107-
{
108-
RandomAccessibleInterval imgS3 = ((MultiResolutionSetupImgLoader)setupImgLoader).getImage( myViewId.getTimePointId(), 3 );
109-
double[][] mipMapSteps = ((MultiResolutionSetupImgLoader)setupImgLoader).getMipmapResolutions();
110-
AffineTransform3D[] mipMapT = ((MultiResolutionSetupImgLoader)setupImgLoader).getMipmapTransforms();
111-
new ImageJ();
112-
ImageJFunctions.show( imgS3 );
113-
}
114-
115-
// dealing with transforms
116-
Map<ViewId, ViewRegistration> rMap = data.getViewRegistrations().getViewRegistrations();
117-
ViewRegistration reg = rMap.get( myViewId );
118-
System.out.println( "num transformations: " + reg.getTransformList().size() );
119-
reg.updateModel();
120-
System.out.println( "concatenated model: " + reg.getModel() );
121-
122-
// dealing with interest points
123-
Map<ViewId, ViewInterestPointLists> iMap = data.getViewInterestPoints().getViewInterestPoints();
124-
ViewInterestPointLists iplists = iMap.get( myViewId );
125-
126-
System.out.println( "\navailable interest point labels:");
127-
iplists.getHashMap().keySet().forEach( k -> System.out.println( k ) );
128-
String myLabel = "beads8v2";
129-
InterestPoints ips = iplists.getInterestPointList( myLabel ); // this is net.preibisch.mvrecon.fiji.spimdata.interestpoints.InterestPointsN5
130-
131-
// load interest points
132-
List<InterestPoint> p = ips.getInterestPointsCopy();
133-
134-
for ( int j = 0; j < 15; ++j )
135-
{
136-
InterestPoint point = p.get( j );
137-
System.out.println( point.getId() + ": " + Arrays.toString( point.getL() ) );
138-
}
139-
140-
// load correspondences
141-
List<CorrespondingInterestPoints> cp = ips.getCorrespondingInterestPointsCopy();
142-
143-
AffineTransform3D myModel = rMap.get( myViewId ).getModel();
144-
145-
System.out.println( "\nCorrespondences" );
146-
for ( int k = 0; k < cp.size(); ++k )
147-
{
148-
CorrespondingInterestPoints cpoint = cp.get( k );
149-
150-
int myId = cpoint.getDetectionId();
151-
String otherLabel = cpoint.getCorrespodingLabel();
152-
ViewId otherViewId = cpoint.getCorrespondingViewId();
153-
int otherId = cpoint.getCorrespondingDetectionId();
154-
155-
InterestPoint myPoint = p.get( myId );
156-
157-
InterestPoints pOther = iMap.get( otherViewId ).getInterestPointList( otherLabel );
158-
InterestPoint otherPoint = pOther.getInterestPointsCopy().get( otherId );
159-
AffineTransform3D otherModel = rMap.get( otherViewId ).getModel();
160-
161-
myModel.apply( myPoint.getL(), myPoint.getW() );
162-
otherModel.apply( otherPoint.getL(), otherPoint.getW() );
163-
164-
System.out.println(
165-
Group.pvid( myViewId ) + " label=" + myLabel +" id=" + myId + ", l=" + Arrays.toString( myPoint.getL() ) + " corresponds to " +
166-
Group.pvid( otherViewId ) + " label=" + otherLabel +" id=" + otherId + ", l=" + Arrays.toString( otherPoint.getL() ) );
167-
168-
System.out.println( "w=" + Arrays.toString( myPoint.getW() ) + " >>> w=" + Arrays.toString( otherPoint.getW() ) );
169-
}
170-
171-
// load and modify all interest points
172-
iMap.values().forEach( list ->
173-
{
174-
list.getHashMap().keySet().forEach( label -> {
175-
list.getInterestPointList( label ).getInterestPointsCopy();
176-
list.getInterestPointList( label ).getCorrespondingInterestPointsCopy();
177-
list.getInterestPointList( label ).setBaseDir( URI.create("file:/nrs/saalfeld/john/for/keller/danio_1_488/dataset-orig-tifs/3/test/"));
178-
});
179-
});
180-
181-
new XmlIoSpimData2().save( data, URI.create("file:/nrs/saalfeld/john/for/keller/danio_1_488/dataset-orig-tifs/3/test/dataset-stephan-2.xml") );
182-
}
183-
18455
public static int defaultBlockSize = 300_000;
18556
public static final String baseN5 = "interestpoints.n5";
18657

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package net.preibisch.mvrecon.fiji.spimdata.interestpoints;
2+
3+
import java.net.URI;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
7+
import mpicbg.spim.data.SpimDataException;
8+
9+
public class ExampleDirectLoading
10+
{
11+
public static void main( String[] args ) throws SpimDataException
12+
{
13+
int viewSetupId = 1;
14+
15+
//
16+
// works without the XML, just loads the N5 directly
17+
//
18+
InterestPointsN5 ip = new InterestPointsN5(
19+
URI.create("/nrs/saalfeld/john/for/keller/danio_1_488/dataset-orig-tifs/3/"),
20+
"tpId_0_viewSetupId_" + viewSetupId + "/beads8v2" );
21+
22+
List<InterestPoint> points = ip.getInterestPointsCopy();
23+
24+
for ( final InterestPoint p : points )
25+
{
26+
System.out.println( p.getId() + " " + Arrays.toString( p.getL() ));
27+
}
28+
}
29+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package net.preibisch.mvrecon.fiji.spimdata.interestpoints;
2+
3+
import java.net.URI;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import ij.ImageJ;
9+
import mpicbg.spim.data.SpimDataException;
10+
import mpicbg.spim.data.registration.ViewRegistration;
11+
import mpicbg.spim.data.sequence.MultiResolutionSetupImgLoader;
12+
import mpicbg.spim.data.sequence.SequenceDescription;
13+
import mpicbg.spim.data.sequence.SetupImgLoader;
14+
import mpicbg.spim.data.sequence.ViewDescription;
15+
import mpicbg.spim.data.sequence.ViewId;
16+
import net.imglib2.RandomAccessibleInterval;
17+
import net.imglib2.img.display.imagej.ImageJFunctions;
18+
import net.imglib2.realtransform.AffineTransform3D;
19+
import net.preibisch.mvrecon.fiji.spimdata.SpimData2;
20+
import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2;
21+
import net.preibisch.mvrecon.process.interestpointregistration.pairwise.constellation.grouping.Group;
22+
23+
public class ExampleXMLBased
24+
{
25+
public static void main( String[] args ) throws SpimDataException
26+
{
27+
int viewSetupId = 1;
28+
//
29+
// this needs the XML
30+
//
31+
SpimData2 data = new XmlIoSpimData2().load( URI.create("file:/nrs/saalfeld/john/for/keller/danio_1_488/dataset-orig-tifs/3/dataset-stephan.xml") );
32+
33+
ViewId myViewId = new ViewId( 0, viewSetupId );
34+
35+
// calibration etc
36+
SequenceDescription sd = data.getSequenceDescription();
37+
ViewDescription vd = sd.getViewDescription( myViewId );
38+
System.out.println( "voxelSize: " + Arrays.toString( vd.getViewSetup().getVoxelSize().dimensionsAsDoubleArray() ) );
39+
System.out.println( "tile id: " + vd.getViewSetup().getTile().getId() );
40+
41+
SetupImgLoader<?> setupImgLoader = sd.getImgLoader().getSetupImgLoader( myViewId.getViewSetupId() );
42+
43+
// full res
44+
RandomAccessibleInterval<?> img = setupImgLoader.getImage( myViewId.getTimePointId() );
45+
46+
// multi-res
47+
if ( MultiResolutionSetupImgLoader.class.isInstance( setupImgLoader ) )
48+
{
49+
RandomAccessibleInterval imgS3 = ((MultiResolutionSetupImgLoader)setupImgLoader).getImage( myViewId.getTimePointId(), 3 );
50+
double[][] mipMapSteps = ((MultiResolutionSetupImgLoader)setupImgLoader).getMipmapResolutions();
51+
AffineTransform3D[] mipMapT = ((MultiResolutionSetupImgLoader)setupImgLoader).getMipmapTransforms();
52+
new ImageJ();
53+
ImageJFunctions.show( imgS3 );
54+
}
55+
56+
// dealing with transforms
57+
Map<ViewId, ViewRegistration> rMap = data.getViewRegistrations().getViewRegistrations();
58+
ViewRegistration reg = rMap.get( myViewId );
59+
System.out.println( "num transformations: " + reg.getTransformList().size() );
60+
reg.updateModel();
61+
System.out.println( "concatenated model: " + reg.getModel() );
62+
63+
// dealing with interest points
64+
Map<ViewId, ViewInterestPointLists> iMap = data.getViewInterestPoints().getViewInterestPoints();
65+
ViewInterestPointLists iplists = iMap.get( myViewId );
66+
67+
System.out.println( "\navailable interest point labels:");
68+
iplists.getHashMap().keySet().forEach( k -> System.out.println( k ) );
69+
String myLabel = "beads8v2";
70+
InterestPoints ips = iplists.getInterestPointList( myLabel ); // this is net.preibisch.mvrecon.fiji.spimdata.interestpoints.InterestPointsN5
71+
72+
// load interest points
73+
List<InterestPoint> p = ips.getInterestPointsCopy();
74+
75+
for ( int j = 0; j < Math.min( 15, p.size() ) ; ++j )
76+
{
77+
InterestPoint point = p.get( j );
78+
System.out.println( point.getId() + ": " + Arrays.toString( point.getL() ) );
79+
}
80+
81+
// load correspondences
82+
List<CorrespondingInterestPoints> cp = ips.getCorrespondingInterestPointsCopy();
83+
84+
AffineTransform3D myModel = rMap.get( myViewId ).getModel();
85+
86+
System.out.println( "\nCorrespondences" );
87+
for ( int k = 0; k < cp.size(); ++k )
88+
{
89+
CorrespondingInterestPoints cpoint = cp.get( k );
90+
91+
int myId = cpoint.getDetectionId();
92+
String otherLabel = cpoint.getCorrespodingLabel();
93+
ViewId otherViewId = cpoint.getCorrespondingViewId();
94+
int otherId = cpoint.getCorrespondingDetectionId();
95+
96+
InterestPoint myPoint = p.get( myId );
97+
98+
InterestPoints pOther = iMap.get( otherViewId ).getInterestPointList( otherLabel );
99+
InterestPoint otherPoint = pOther.getInterestPointsCopy().get( otherId );
100+
AffineTransform3D otherModel = rMap.get( otherViewId ).getModel();
101+
102+
myModel.apply( myPoint.getL(), myPoint.getW() );
103+
otherModel.apply( otherPoint.getL(), otherPoint.getW() );
104+
105+
System.out.println(
106+
Group.pvid( myViewId ) + " label=" + myLabel +" id=" + myId + ", l=" + Arrays.toString( myPoint.getL() ) + " corresponds to " +
107+
Group.pvid( otherViewId ) + " label=" + otherLabel +" id=" + otherId + ", l=" + Arrays.toString( otherPoint.getL() ) );
108+
109+
System.out.println( "w=" + Arrays.toString( myPoint.getW() ) + " >>> w=" + Arrays.toString( otherPoint.getW() ) );
110+
}
111+
112+
// load and modify all interest points
113+
iMap.values().forEach( list ->
114+
{
115+
list.getHashMap().keySet().forEach( label -> {
116+
list.getInterestPointList( label ).getInterestPointsCopy();
117+
list.getInterestPointList( label ).getCorrespondingInterestPointsCopy();
118+
list.getInterestPointList( label ).setBaseDir( URI.create("file:/nrs/saalfeld/john/for/keller/danio_1_488/dataset-orig-tifs/3/test/"));
119+
});
120+
});
121+
122+
new XmlIoSpimData2().save( data, URI.create("file:/nrs/saalfeld/john/for/keller/danio_1_488/dataset-orig-tifs/3/test/dataset-stephan-2.xml") );
123+
}
124+
}

0 commit comments

Comments
 (0)