1 package ij.plugin.filter;
23 isTextRoi = roi!=null && (roi instanceof TextRoi);
26 if (arg.equals(
"clear")) {
27 if (isTextRoi || isLineSelection())
28 return baseCapabilities;
31 }
else if (arg.equals(
"draw"))
32 return baseCapabilities;
33 else if (arg.equals(
"label")) {
37 return baseCapabilities;
38 }
else if (arg.equals(
"outside"))
44 public void run(ImageProcessor ip) {
45 if (arg.equals(
"clear"))
47 else if (isTextRoi && (arg.equals(
"draw") || arg.equals(
"fill")))
49 else if (arg.equals(
"fill"))
51 else if (arg.equals(
"draw"))
53 else if (arg.equals(
"label"))
55 else if (arg.equals(
"outside"))
59 boolean isLineSelection() {
60 return roi!=null && roi.getType()>=Roi.LINE && roi.getType()<=Roi.FREELINE;
63 public void clear(ImageProcessor ip) {
64 ip.setColor(Toolbar.getBackgroundColor());
65 if (isLineSelection())
69 ip.setColor(Toolbar.getForegroundColor());
72 public void fill(ImageProcessor ip) {
73 ip.setColor(Toolbar.getForegroundColor());
74 if (isLineSelection())
80 public void draw(ImageProcessor ip) {
81 ip.setColor(Toolbar.getForegroundColor());
87 public void label(ImageProcessor ip) {
88 if (Analyzer.getCounter()==0) {
89 IJ.showMessage(
"Label",
"Measurement counter is zero");
92 if (Analyzer.firstParticle<Analyzer.lastParticle)
93 drawParticleLabels(ip);
95 ip.setColor(Toolbar.getForegroundColor());
101 void drawParticleLabels(ImageProcessor ip) {
102 ResultsTable rt = ResultsTable.getResultsTable();
103 int count = rt.getCounter();
104 int first = Analyzer.firstParticle;
105 int last = Analyzer.lastParticle;
106 if (count==0 || first>=count || last>=count)
108 if (!rt.columnExists(ResultsTable.X_CENTROID)) {
109 IJ.showMessage(
"Label",
"\"Centroids\" required to label particles");
112 for (
int i=first; i<=last; i++) {
113 int x = (int)rt.getValue(ResultsTable.X_CENTROID, i);
114 int y = (int)rt.getValue(ResultsTable.Y_CENTROID, i);
115 drawLabel(ip, i+1,
new Rectangle(x,y,0,0));
119 void drawLabel(ImageProcessor ip) {
120 int count = Analyzer.getCounter();
121 if (count>0 && roi!=null)
122 drawLabel(ip, count, roi.getBounds());
125 void drawLabel(ImageProcessor ip,
int count, Rectangle r) {
126 Color foreground = Toolbar.getForegroundColor();
127 Color background = Toolbar.getBackgroundColor();
128 if (foreground.equals(background)) {
129 foreground = Color.black;
130 background = Color.white;
132 int size = r.width>50&&r.height>50?12:9;
133 ip.setFont(
new Font(
"SansSerif", Font.PLAIN, size));
134 String label =
"" + count;
135 int w = ip.getStringWidth(label);
136 int x = r.x + r.width/2 - w/2;
137 int y = r.y + r.height/2 + 6;
138 FontMetrics metrics = ip.getFontMetrics();
139 int h = metrics.getHeight();
140 ip.setColor(background);
141 ip.setRoi(x-1, y-h+2, w+1, h-3);
144 ip.setColor(foreground);
145 ip.drawString(label, x, y);
148 public synchronized void clearOutside(ImageProcessor ip) {
149 if (isLineSelection()) {
150 IJ.error(
"\"Clear Outside\" does not work with line selections.");
154 Rectangle r = ip.getRoi();
157 ip.setColor(Toolbar.getBackgroundColor());
163 int width = ip.getWidth();
164 int height = ip.getHeight();
165 ip.setRoi(0, 0, r.x, height);
167 ip.setRoi(r.x, 0, r.width, r.y);
169 ip.setRoi(r.x, r.y+r.height, r.width, height-(r.y+r.height));
171 ip.setRoi(r.x+r.width, 0, width-(r.x+r.width), height);
174 if (sliceCount==stackSize) {
175 ip.setColor(Toolbar.getForegroundColor());
176 Roi roi = imp.getRoi();
183 public void makeMask(ImageProcessor ip, Rectangle r) {
186 mask =
new ByteProcessor(r.width, r.height);
190 mask = mask.duplicate();