6 import ij.plugin.frame.Recorder;
7 import ij.plugin.filter.PlugInFilter;
14 private double minThreshold;
15 private double maxThreshold;
16 boolean autoThreshold;
18 static boolean fill1 =
true;
19 static boolean fill2 =
true;
20 static boolean useBW =
true;
23 public void run(String arg) {
24 skipDialog = arg.equals(
"skip");
39 double saveMinThreshold = ip.getMinThreshold();
40 double saveMaxThreshold = ip.getMaxThreshold();
41 double saveMin = ip.getMin();
42 double saveMax = ip.getMax();
43 if (ip instanceof ByteProcessor)
44 {saveMin =0; saveMax = 255;}
45 autoThreshold = saveMinThreshold==ImageProcessor.NO_THRESHOLD;
47 boolean useBlackAndWhite =
true;
49 fill1 = fill2 = useBlackAndWhite =
true;
50 else if (!autoThreshold) {
51 GenericDialog gd =
new GenericDialog(
"Apply Lut");
52 gd.addCheckbox(
"Thresholded pixels to foreground color", fill1);
53 gd.addCheckbox(
"Remaining pixels to background color", fill2);
55 gd.addCheckbox(
"Black foreground, white background", useBW);
59 fill1 = gd.getNextBoolean();
60 fill2 = gd.getNextBoolean();
61 useBW = useBlackAndWhite = gd.getNextBoolean();
65 if (!(imp.
getType()==ImagePlus.GRAY8))
72 Recorder.record(
"setThreshold", (
int)saveMinThreshold, (
int)saveMaxThreshold);
73 minThreshold = ((saveMinThreshold-saveMin)/(saveMax-saveMin))*255.0;
74 maxThreshold = ((saveMaxThreshold-saveMin)/(saveMax-saveMin))*255.0;
79 int savePixel = ip.getPixel(0,0);
81 ip.setColor(Color.black);
83 ip.setColor(Toolbar.getForegroundColor());
85 fcolor = ip.getPixel(0,0);
87 ip.setColor(Color.white);
89 ip.setColor(Toolbar.getBackgroundColor());
91 bcolor = ip.getPixel(0,0);
92 ip.setColor(Toolbar.getForegroundColor());
93 ip.putPixel(0,0,savePixel);
95 int[] lut =
new int[256];
96 for (
int i=0; i<256; i++) {
97 if (i>=minThreshold && i<=maxThreshold)
98 lut[i] = fill1?fcolor:(byte)i;
100 lut[i] = fill2?bcolor:(byte)i;
103 int result = IJ.setupDialog(imp, 0);
109 void convertToByte(ImagePlus imp) {
110 ImageProcessor ip = imp.getProcessor();
111 imp.setProcessor(null, ip.convertToByte(
true));
114 void autoThreshold(ImagePlus imp) {
115 ImageStatistics stats = imp.getStatistics(MIN_MAX+MODE);
116 ImageProcessor ip = imp.getProcessor();
117 int threshold = ((ByteProcessor)ip).getAutoThreshold();
118 if ((stats.max-stats.mode)<(stats.mode-stats.min)) {
119 minThreshold = stats.min;
120 maxThreshold = threshold;
122 minThreshold = threshold;
123 maxThreshold = stats.max;