-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVisualizeAnnotations.java
More file actions
141 lines (121 loc) · 4.77 KB
/
VisualizeAnnotations.java
File metadata and controls
141 lines (121 loc) · 4.77 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
package examples;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
import bdv.util.BdvFunctions;
import bdv.util.BdvOptions;
import bdv.util.BdvStackSource;
import data.STData;
import data.STDataUtils;
import filter.FilterFactory;
import gui.STDataAssembly;
import gui.celltype.CellTypeExplorer;
import imglib2.StackedIterableRealInterval;
import imglib2.TransformedIterableRealInterval;
import io.Path;
import io.SpatialDataContainer;
import net.imglib2.FinalInterval;
import net.imglib2.Interval;
import net.imglib2.IterableRealInterval;
import net.imglib2.RealRandomAccessible;
import net.imglib2.realtransform.AffineTransform2D;
import net.imglib2.type.numeric.ARGBType;
import net.imglib2.type.numeric.integer.IntType;
import net.imglib2.util.Pair;
import net.imglib2.util.ValuePair;
import render.MaxDistanceParam;
import render.Render;
public class VisualizeAnnotations
{
// minimal GUI for cell type selection
// alignment
public static Pair< RealRandomAccessible< IntType >, Interval > createStack(
final List< STDataAssembly > stdata,
final String annotation,
final double spotSize,
final double spacingFactor,
final IntType outofbounds,
final List< FilterFactory< IntType, IntType > > filterFactorys,
final HashMap<Long, ARGBType> lut )
{
final ArrayList< IterableRealInterval< IntType > > slices = new ArrayList<>();
for (STDataAssembly stdatum : stdata)
slices.add(Render.getRealIterable(stdatum.data(), annotation, stdatum.transform(), filterFactorys, lut));
final double medianDistance = stdata.get( 0 ).statistics().getMedianDistance();
// gauss crisp
double gaussRenderSigma = medianDistance * 1.0;
//double gaussRenderRadius = medianDistance * 4;
final double spacing = medianDistance * spacingFactor;
final Interval interval2d = STDataUtils.getCommonIterableInterval( slices );
final long padding = Math.round(Math.ceil(gaussRenderSigma * 3));
final long[] minI = new long[] { interval2d.min(0 ), interval2d.min(1 ), - padding};
final long[] maxI = new long[] { interval2d.max( 0 ), interval2d.max( 1 ), Math.round( ( stdata.size() - 1 ) * spacing ) + padding};
final Interval interval = new FinalInterval( minI, maxI );
final StackedIterableRealInterval< IntType > stack = new StackedIterableRealInterval<>( slices, spacing );
return new ValuePair<>(
Render.renderNN( stack, outofbounds, new MaxDistanceParam( spotSize ) ),
interval );
}
public static void visualize2d(
final STData stdata,
final String annotation,
final double spotSize,
final AffineTransform2D transform )
{
final HashMap<Long, ARGBType > lut = new HashMap<>();
final RealRandomAccessible< IntType > rra = VisualizeAnnotations.visualize2d(
stdata,
annotation,
spotSize,
transform,
new IntType( -1 ),
null ,
lut );
final Interval interval = STDataUtils.getIterableInterval(
new TransformedIterableRealInterval<>(
stdata,
transform ) );
CellTypeExplorer cte = new CellTypeExplorer( lut );
BdvOptions options = BdvOptions.options().numRenderingThreads( Runtime.getRuntime().availableProcessors() ).is2D();
BdvStackSource< ? > source = BdvFunctions.show(
Render.switchableConvertToRGB( rra, new IntType( -1 ), new ARGBType(), lut, cte.panel() ),
interval,
annotation,
options );
source.setDisplayRange( 0, 255 );
source.setDisplayRangeBounds( 0, 2550 );
cte.panel().setBDV( source.getBdvHandle().getViewerPanel() );
//source.getBdvHandle().getViewerPanel().requestRepaint();
}
public static RealRandomAccessible< IntType > visualize2d(
final STData stdata,
final String annotation,
final double spotSize,
final AffineTransform2D transform,
final IntType outofbounds,
final List< FilterFactory< IntType, IntType > > filterFactorys, // optional
final HashMap<Long, ARGBType> lut )
{
final IterableRealInterval< IntType > data = Render.getRealIterable(stdata, annotation, transform, filterFactorys, lut);
return Render.renderNN( data, outofbounds, new MaxDistanceParam( spotSize ) );
}
public static void main( String[] args ) throws IOException
{
final ExecutorService service = Executors.newFixedThreadPool(8);
final List<STDataAssembly> puckData =
SpatialDataContainer.openExisting(Path.getPath() + "slide-seq-test.n5", service).openAllDatasets().stream()
.map(sdio ->
{try {return sdio.readData();} catch (IOException e) {throw new RuntimeException(e);}
}).collect(Collectors.toList());
visualize2d(
puckData.get( 12 ).data(),
"celltype",
puckData.get( 12 ).statistics().getMedianDistance() / 1.5,
puckData.get( 12 ).transform() );
service.shutdown();
}
}