Skip to content

Commit 78d5f2d

Browse files
committed
added thining iterations parameters
1 parent a258bea commit 78d5f2d

File tree

4 files changed

+94
-6
lines changed

4 files changed

+94
-6
lines changed

src/org/openstreetmap/josm/plugins/areaselector/AreaSelectorAction.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
*/
4848
public class AreaSelectorAction extends MapMode implements MouseListener {
4949

50-
protected int colorThreshold=ImageAnalyzer.DEFAULT_COLORTHRESHOLD;
50+
protected int colorThreshold=ImageAnalyzer.DEFAULT_COLORTHRESHOLD, thinningIterations=ImageAnalyzer.DEFAULT_THINNING_ITERATIONS;
5151
protected double toleranceDist=ImageAnalyzer.DEFAULT_TOLERANCEDIST,toleranceAngle=ImageAnalyzer.DEFAULT_TOLERANCEANGLE;
5252

5353
protected boolean showAddressDialog=true,mergeNodes=true;
@@ -58,7 +58,8 @@ public class AreaSelectorAction extends MapMode implements MouseListener {
5858
PREF_TOLERANCEDIST=PLUGIN_NAME+".tolerancedist",
5959
PREF_TOLERANCEANGLE=PLUGIN_NAME+".toleranceangle",
6060
PREF_SHOWADDRESSDIALOG=PLUGIN_NAME+".showaddressdialog",
61-
PREF_MERGENODES=PLUGIN_NAME+".mergenodes";
61+
PREF_MERGENODES=PLUGIN_NAME+".mergenodes",
62+
PREF_THINNING_ITERATIONS=PLUGIN_NAME+".thinning_iterations";
6263

6364

6465
protected Logger log = Logger.getLogger(AreaSelectorAction.class.getCanonicalName());
@@ -316,6 +317,25 @@ public void setColorThreshold(int colorThreshold) {
316317
Main.pref.put(PREF_COLORTHRESHOLD, Integer.toString(colorThreshold));
317318
this.colorThreshold = colorThreshold;
318319
}
320+
321+
322+
public int getThinningIterations() {
323+
// refresh from prefs
324+
try{
325+
this.thinningIterations=Integer.parseInt(Main.pref.get(PREF_THINNING_ITERATIONS, Integer.toString(ImageAnalyzer.DEFAULT_THINNING_ITERATIONS)));
326+
}catch(NumberFormatException th){
327+
log.warn("Could not load thinning iterations",th);
328+
}
329+
return thinningIterations;
330+
}
331+
332+
/**
333+
* @param thinningIterations the thinningIterations to set
334+
*/
335+
public void setThinningIterations(int thinningIterations) {
336+
Main.pref.put(PREF_THINNING_ITERATIONS, Integer.toString(thinningIterations));
337+
this.thinningIterations = thinningIterations;
338+
}
319339

320340
/**
321341
* @return the toleranceDist

src/org/openstreetmap/josm/plugins/areaselector/ImageAnalyzer.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ public class ImageAnalyzer {
102102
// gaussian blur radius
103103
public static final int DEFAULT_BLURRADIUS = 10;
104104
protected int blurRadius = DEFAULT_BLURRADIUS;
105-
105+
106+
// default thinning iterations = 3
107+
public static final int DEFAULT_THINNING_ITERATIONS = 2;
108+
protected int thinningIterations = DEFAULT_THINNING_ITERATIONS;
106109

107110

108111

@@ -160,6 +163,14 @@ public void initUI() {
160163
final JLabel toleranceAngleLabel = new JLabel("Tolerance Angle: ");
161164
textAreaPanel.add(toleranceAngleLabel);
162165
textAreaPanel.add(toleranceAngleTextArea);
166+
167+
final JTextArea thinningIterationsTextArea=new JTextArea(1,5);
168+
thinningIterationsTextArea.setText(""+(thinningIterations));
169+
final JLabel thinningIterationsLabel = new JLabel("Thinning Iterations: ");
170+
textAreaPanel.add(thinningIterationsLabel);
171+
textAreaPanel.add(thinningIterationsTextArea);
172+
173+
163174

164175

165176
JButton refreshButton=new JButton("Refresh");
@@ -173,6 +184,8 @@ public void actionPerformed(ActionEvent e) {
173184
toleranceDist=Double.parseDouble(toleranceDistTextArea.getText());
174185

175186
toleranceAngle=Double.parseDouble(toleranceAngleTextArea.getText());
187+
188+
thinningIterations=Integer.parseInt(thinningIterationsTextArea.getText());
176189

177190

178191
getArea();
@@ -522,7 +535,7 @@ public BufferedImage skeletonize(BufferedImage image){
522535
}
523536
}
524537

525-
for(int j=0;j<3;j++){
538+
for(int j=0;j<thinningIterations;j++){
526539

527540
int [] thinningKernel1= {
528541
0, 0, 0,
@@ -1078,6 +1091,21 @@ public int getBlurRadius() {
10781091
public void setBlurRadius(int blurRadius) {
10791092
this.blurRadius = blurRadius;
10801093
}
1094+
1095+
/**
1096+
* @return the thinningIterations
1097+
*/
1098+
public int getThinningIterations() {
1099+
return thinningIterations;
1100+
}
1101+
1102+
/**
1103+
* @param thinningIterations the thinningIterations to set
1104+
*/
1105+
public void setThinningIterations(int thinningIterations) {
1106+
this.thinningIterations = thinningIterations;
1107+
}
1108+
10811109

10821110
/**
10831111
* @param args

src/org/openstreetmap/josm/plugins/areaselector/preferences/AreaSelectorPreference.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void addGui(PreferenceTabbedPane gui) {
3737
prefPanel.setColorThreshold(areaSelectorAction.getColorThreshold());
3838
prefPanel.setToleranceDist(areaSelectorAction.getToleranceDist());
3939
prefPanel.setToleranceAngle(areaSelectorAction.getToleranceAngle());
40+
prefPanel.setThinningIterations(areaSelectorAction.getThinningIterations());
4041
prefPanel.setShowAddressDialog(areaSelectorAction.getShowAddressDialog());
4142
prefPanel.setMergeNodes(areaSelectorAction.getMergeNodes());
4243

@@ -59,6 +60,7 @@ public boolean ok() {
5960
areaSelectorAction.setColorThreshold(prefPanel.getColorThreshold());
6061
areaSelectorAction.setToleranceDist(prefPanel.getToleranceDist());
6162
areaSelectorAction.setToleranceAngle(prefPanel.getToleranceAngle());
63+
areaSelectorAction.setThinningIterations(prefPanel.getThinningIterations());
6264
areaSelectorAction.setShowAddressDialog(prefPanel.getShowAddressDialog());
6365
areaSelectorAction.setMergeNodes(prefPanel.getMergeNodes());
6466
return false;

src/org/openstreetmap/josm/plugins/areaselector/preferences/PreferencesPanel.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ public class PreferencesPanel extends JPanel {
2424
private JTextField txtColorThreshold;
2525
private JTextField txtToleranceDist;
2626
private JTextField txtToleranceAngle;
27+
private JTextField txtThinningIterations;
2728

2829
private JCheckBox ckbxShowAddressDialog;
2930
private JCheckBox ckbxMergeNodes;
30-
31+
3132
/**
3233
* Constructs a new {@code PreferencesPanel}.
3334
*/
@@ -115,7 +116,6 @@ private void initialize() {
115116
txtToleranceAngle.setColumns(10);
116117

117118
JLabel lbluserInterfaceSettings = new JLabel("<html><p><b>"+tr("Plugin Settings")+"</b></p></html>");
118-
sl_panel.putConstraint(SpringLayout.NORTH, lbluserInterfaceSettings, 40, SpringLayout.SOUTH, lblToleranceAngle);
119119
sl_panel.putConstraint(SpringLayout.WEST, lbluserInterfaceSettings, 0, SpringLayout.WEST, lblAlgorithmSettings);
120120
add(lbluserInterfaceSettings);
121121

@@ -138,6 +138,24 @@ private void initialize() {
138138
sl_panel.putConstraint(SpringLayout.WEST, ckbxMergeNodes, 0, SpringLayout.WEST, ckbxShowAddressDialog);
139139
sl_panel.putConstraint(SpringLayout.SOUTH, ckbxMergeNodes, 0, SpringLayout.SOUTH, lblMergeNodesWithNeighbor);
140140
add(ckbxMergeNodes);
141+
142+
JLabel lblThinningIterationsExplanation = new JLabel("<html><p>"+tr("How often thinning operation should be applied (Default {0}).",ImageAnalyzer.DEFAULT_THINNING_ITERATIONS)+"</p></html>");
143+
sl_panel.putConstraint(SpringLayout.NORTH, lblThinningIterationsExplanation, 40, SpringLayout.NORTH, lblToleranceAngle);
144+
sl_panel.putConstraint(SpringLayout.WEST, lblThinningIterationsExplanation, 0, SpringLayout.WEST, lblAlgorithmSettings);
145+
add(lblThinningIterationsExplanation);
146+
147+
JLabel lblThinningIterations = new JLabel(tr("Thinning Iterations"));
148+
sl_panel.putConstraint(SpringLayout.NORTH, lbluserInterfaceSettings, 40, SpringLayout.SOUTH, lblThinningIterations);
149+
sl_panel.putConstraint(SpringLayout.NORTH, lblThinningIterations, 10, SpringLayout.SOUTH, lblThinningIterationsExplanation);
150+
sl_panel.putConstraint(SpringLayout.WEST, lblThinningIterations, 0, SpringLayout.WEST, lblAlgorithmSettings);
151+
add(lblThinningIterations);
152+
153+
txtThinningIterations = new JTextField();
154+
sl_panel.putConstraint(SpringLayout.NORTH, txtThinningIterations, 10, SpringLayout.SOUTH, lblThinningIterationsExplanation);
155+
sl_panel.putConstraint(SpringLayout.EAST, txtThinningIterations, 0, SpringLayout.EAST, txtColorThreshold);
156+
txtThinningIterations.setText("0.4");
157+
txtThinningIterations.setColumns(10);
158+
add(txtThinningIterations);
141159
}
142160

143161
/**
@@ -232,4 +250,24 @@ public boolean getMergeNodes() {
232250
public void setMergeNodes(boolean merge){
233251
ckbxMergeNodes.setSelected(merge);
234252
}
253+
254+
/**
255+
* get Thinning Iterations
256+
* @return
257+
*/
258+
public int getThinningIterations() {
259+
try{
260+
return Integer.parseInt(txtThinningIterations.getText());
261+
}catch(NumberFormatException e){
262+
return ImageAnalyzer.DEFAULT_THINNING_ITERATIONS;
263+
}
264+
}
265+
266+
/**
267+
* set text field to value of thinning Iterations
268+
* @param thinningIterations
269+
*/
270+
public void setThinningIterations(int thinningIterations) {
271+
txtThinningIterations.setText(Integer.toString(thinningIterations));
272+
}
235273
}

0 commit comments

Comments
 (0)