-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeedGenerator.java
More file actions
144 lines (111 loc) · 3.1 KB
/
Copy pathSeedGenerator.java
File metadata and controls
144 lines (111 loc) · 3.1 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
142
143
144
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.LinkedList;
import ij.ImagePlus;
import ij.gui.ImageCanvas;
import ij.gui.ImageWindow;
import ij.process.ImageProcessor;
import ij.process.ImageStatistics;
/*
* SeedGenerator
* class wich provides methods to calculate seeds for region growing
*/
public class SeedGenerator implements MouseListener{
private ImageProcessor ip;
private LinkedList<Coord2D> seeds = new LinkedList<Coord2D>();
private boolean manual;
private ImageCanvas canvas;
private int nClick;
private int nSeeds;
private double imSTDV;
/**
* @param ip target {@code ImageProcessor}
*/
public SeedGenerator(ImageProcessor ip) {
this.ip = ip;
manual = false;
nClick = 0;
}
/**
* @return seeds {@code LinkedList}
*/
public LinkedList getSeeds() {
return seeds;
}
/**
* @param imp target {@code ImagePlus}
* @param nSeeds2 number of seeds
*/
public void selectSeedsManually(ImagePlus imp, int nSeeds2) {
// manual mode
manual = true;
// setting seeds number
this.nSeeds = nSeeds2;
// inizializzo la lista dei semi
this.seeds = new LinkedList<Coord2D>();
// resets click number
nClick = 0;
// ottengo il canvas e gli aggiungo un MouseListener
ImageWindow win = imp.getWindow();
ImageStatistics ims = imp.getStatistics();
this.imSTDV = ims.stdDev;
canvas = win.getCanvas();
canvas.addMouseListener(this);
}
/**
* @param e
*/
public void mouseClicked(MouseEvent e) {
nClick++;
if (manual && nClick==nSeeds) {
// IJ.write("Mouse clicked: ultimo seme");
int x = e.getX();
int y = e.getY();
//memorizzo le coordinate del punnto relative rispetto al canvas
int X = canvas.offScreenX(x);
int Y = canvas.offScreenY(y);
this.seeds.add(new Coord2D(X,Y));
// initializing seed grower
SeedsGrower sgr = new SeedsGrower(seeds,ip);
// starting growth
sgr.growSeeds();
// showing output
sgr.showOutput();
}
else if (manual && (nClick<nSeeds)) {
// IJ.write("Mouse clicked: seme "+nClick);
int x = e.getX();
int y = e.getY();
//memorizzo le coordinate del punto relative rispetto al canvas
int X = canvas.offScreenX(x);
int Y = canvas.offScreenY(y);
Coord2D point = new Coord2D(X, Y);
this.seeds.add(point);
}
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
* method that manages mouse click on the image by user collecting coordinates and using
* them to start the region growing algorithm
*/
public void mouseEntered(MouseEvent e) {
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
* not implemented
*/
public void mouseExited(MouseEvent e) {
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
* not implemented
*/
public void mousePressed(MouseEvent e) {
}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
* not implemented
*/
public void mouseReleased(MouseEvent e) {
}
}