1 package com.github.celldynamics.quimp.plugin.protanalysis;
2
3 import java.awt.Polygon;
4 import java.awt.geom.Point2D;
5 import java.util.Collection;
6
7 import org.apache.commons.lang3.NotImplementedException;
8 import org.scijava.vecmath.Point2d;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11
12 import com.github.celldynamics.quimp.plugin.qanalysis.STmap;
13
14 import ij.plugin.filter.MaximumFinder;
15 import ij.process.ByteProcessor;
16 import ij.process.ImageProcessor;
17
18
19
20
21
22
23
24
25
26 public class MaximaFinder {
27
28
29
30
31 static final Logger LOGGER = LoggerFactory.getLogger(MaximaFinder.class.getName());
32 private ImageProcessor ip;
33 private Polygon maxima;
34
35
36
37
38
39
40
41
42
43
44
45
46
47 public MaximaFinder(ImageProcessor ip) {
48 this.ip = ip;
49 maxima = null;
50 }
51
52
53
54
55
56
57
58
59 public void computeMaximaIJ(double tolerance) {
60 MaximumFinder mf = new MaximumFinder();
61
62 ByteProcessor ret = mf.findMaxima(ip, tolerance, MaximumFinder.SINGLE_POINTS, false);
63 maxima = new Polygon();
64 for (int x = 0; x < ret.getWidth(); ++x) {
65 for (int y = 0; y < ret.getHeight(); ++y) {
66 if (ret.get(x, y) > 0) {
67 maxima.addPoint(x, y);
68 }
69 }
70 }
71 LOGGER.debug("Found maxima: " + maxima.npoints);
72 }
73
74
75
76
77
78
79
80
81
82
83 public void computeMaximaImage(ImageProcessor mximaMap) {
84
85 throw new NotImplementedException("Not implemented");
86 }
87
88
89
90
91
92
93
94
95
96
97 public void setMaximad(Collection<Point2d> maxi) {
98 maxima = new Polygon();
99 for (Point2d p : maxi) {
100 maxima.addPoint((int) p.getX(), (int) p.getY());
101 }
102
103 }
104
105
106
107
108
109
110
111
112
113
114
115
116 public void setMaxima(Collection<? extends Point2D> maxi) {
117 maxima = new Polygon();
118 for (Point2D p : maxi) {
119 maxima.addPoint((int) p.getX(), (int) p.getY());
120 }
121 }
122
123
124
125
126
127
128
129
130 public double[] getMaxValues() {
131 if (maxima == null) {
132 return new double[0];
133 }
134 double[] ret = new double[maxima.npoints];
135 for (int i = 0; i < maxima.npoints; i++) {
136 ret[i] = ip.getf(maxima.xpoints[i], maxima.ypoints[i]);
137 }
138 return ret;
139 }
140
141
142
143
144
145
146
147
148 public Polygon getMaxima() {
149 if (maxima == null) {
150 return new Polygon();
151 }
152 return maxima;
153 }
154
155
156
157
158
159
160 public int getMaximaNumber() {
161 if (maxima == null) {
162 return 0;
163 }
164 return maxima.npoints;
165 }
166 }