1 package com.github.celldynamics.quimp.plugin.randomwalk;
2
3 import java.util.List;
4 import java.util.ListIterator;
5
6 import org.apache.commons.math3.linear.RealMatrix;
7
8 import com.github.celldynamics.quimp.plugin.randomwalk.RandomWalkSegmentation.SeedTypes;
9 import com.github.celldynamics.quimp.utils.QuimPArrayUtils;
10
11 import ij.ImageStack;
12 import ij.process.ImageProcessor;
13
14
15
16
17
18
19
20
21
22
23 @SuppressWarnings("serial")
24 public class ProbabilityMaps extends ListMap<RealMatrix> {
25
26
27
28
29 public ProbabilityMaps() {
30 super();
31 }
32
33
34
35
36
37
38
39
40
41
42 public double[][][] convertTo3dMatrix(Object key) {
43 List<RealMatrix> maps = get(key);
44
45 if (maps == null || maps.isEmpty()) {
46 return null;
47 }
48
49 int width = maps.get(0).getColumnDimension();
50 int height = maps.get(0).getRowDimension();
51 int depth = maps.size();
52 for (int i = 1; i < depth; i++) {
53 RealMatrix tmp = maps.get(i);
54 if (tmp.getRowDimension() != height || tmp.getColumnDimension() != width) {
55 throw new IllegalArgumentException("All maps must have the same resoultion");
56 }
57 }
58 double[][][] ret = new double[depth][][];
59 ListIterator<RealMatrix> it = maps.listIterator();
60 while (it.hasNext()) {
61 ret[it.nextIndex()] = it.next().getData();
62 }
63
64 return ret;
65 }
66
67
68
69
70
71
72
73
74 public ImageStack convertToImageStack(Object key) {
75 List<RealMatrix> maps = get(key);
76
77 if (maps == null || maps.isEmpty()) {
78 return null;
79 }
80
81 int width = maps.get(0).getColumnDimension();
82 int height = maps.get(0).getRowDimension();
83 int depth = maps.size();
84 for (int i = 1; i < depth; i++) {
85 RealMatrix tmp = maps.get(i);
86 if (tmp.getRowDimension() != height || tmp.getColumnDimension() != width) {
87 throw new IllegalArgumentException("All maps must have the same resoultion");
88 }
89 }
90 ImageStack is = new ImageStack(width, height);
91 for (RealMatrix m : maps) {
92 ImageProcessor fp = QuimPArrayUtils.realMatrix2ImageProcessor(m);
93 is.addSlice(fp);
94 }
95 return is;
96 }
97 }