-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTransformCoordinates.java
More file actions
95 lines (75 loc) · 2.46 KB
/
Copy pathTransformCoordinates.java
File metadata and controls
95 lines (75 loc) · 2.46 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
package transform;
import java.util.List;
import data.STData;
import filter.FilterFactory;
import filter.Filters;
import filter.MeanFilterFactory;
import imglib2.SteppingIntervalIterator;
import net.imglib2.FinalInterval;
import net.imglib2.Interval;
import net.imglib2.IterableRealInterval;
import net.imglib2.type.numeric.RealType;
import net.imglib2.util.Util;
public class TransformCoordinates
{
public static < T extends RealType< T > > IterableRealInterval< T > sample(
final IterableRealInterval< T > data,
final double distance )
{
return sample(
data,
Util.getArrayFromValue( (int)Math.round( Math.ceil( distance ) ), data.numDimensions() ),
new MeanFilterFactory<>( data.iterator().next().createVariable(), distance ) );
}
public static < S extends RealType< S >, T extends RealType< T > > IterableRealInterval< T > sample(
final IterableRealInterval< S > data,
final int[] steps,
final FilterFactory< S, T > filterFactory )
{
final long[] min = new long[ data.numDimensions() ];
final long[] max = new long[ data.numDimensions() ];
for ( int d = 0; d < min.length; ++d )
{
min[ d ] = Math.round( data.realMin( d ) );
max[ d ] = Math.round( data.realMax( d ) );
}
final Interval interval = new FinalInterval( min, max );
return Filters.filter( data, new SteppingIntervalIterator( interval, steps ), filterFactory );
}
public static void zeroMin( final STData data )
{
final int n = data.numDimensions();
final double[] min = new double[ n ];
data.realMin( min );
final List< double[] > locations = data.getLocationsCopy();
for (final double[] loc : locations) {
for (int d = 0; d < n; ++d)
loc[d] -= min[d];
}
data.setLocations( locations );
}
public static void translate( final STData data, final double[] vector )
{
final int n = data.numDimensions();
final List< double[] > locations = data.getLocationsCopy();
for (final double[] loc : locations) {
for (int d = 0; d < n; ++d)
loc[d] += vector[d];
}
data.setLocations( locations );
}
public static void scale( final STData data, final double scale )
{
scale( data, Util.getArrayFromValue( scale, data.numDimensions() ) );
}
public static void scale( final STData data, final double[] scale )
{
final int n = data.numDimensions();
final List< double[] > locations = data.getLocationsCopy();
for (final double[] loc : locations) {
for (int d = 0; d < n; ++d)
loc[d] *= scale[d];
}
data.setLocations( locations );
}
}