Skip to content

Commit

Permalink
2023.10.16 (1.54g30; Image>Adjust>Threshold)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasband committed Oct 16, 2023
1 parent 85ba5e5 commit 24983ae
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ij/ImageJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class ImageJ extends Frame implements ActionListener,

/** Plugins should call IJ.getVersion() or IJ.getFullVersion() to get the version string. */
public static final String VERSION = "1.54g";
public static final String BUILD = "27";
public static final String BUILD = "30";
public static Color backgroundColor = new Color(237,237,237);
/** SansSerif, 12-point, plain font. */
public static final Font SansSerif12 = new Font("SansSerif", Font.PLAIN, 12);
Expand Down
11 changes: 9 additions & 2 deletions ij/gui/GenericDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -2011,9 +2011,16 @@ public BrowseButtonListener(String label, TextField textField, String mode) {

public void actionPerformed(ActionEvent e) {
String path = null;
if (mode.equals("dir"))
if (mode.equals("dir")) {
String saveDefaultDir = OpenDialog.getDefaultDirectory();
String dir = this.textField.getText();
boolean setDefaultDir = dir!=null && !dir.equals("");
if (setDefaultDir)
OpenDialog.setDefaultDirectory(dir);
path = IJ.getDir("Select a Folder");
else {
if (setDefaultDir)
OpenDialog.setDefaultDirectory(saveDefaultDir);
} else {
OpenDialog od = new OpenDialog("Select a File", null);
String directory = od.getDirectory();
String name = od.getFileName();
Expand Down
10 changes: 9 additions & 1 deletion ij/macro/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4103,6 +4103,14 @@ String doDialog() {
gd.addToSameRow();
} else if (name.equals("setLocation")) {
gd.setLocation((int)getFirstArg(), (int)getLastArg());
} else if (name.equals("getLocation")) {
Variable v1 = getFirstVariable();
Variable v2 = getLastVariable();
Point loc = gd.getLocation();
int x = loc.x;
int y = loc.y;
v1.setValue(x);
v2.setValue(y);
} else if (name.equals("show")) {
interp.getParens();
gd.showDialog();
Expand Down Expand Up @@ -4136,7 +4144,7 @@ String doDialog() {
}
return null;
}

void addCheckboxGroup(GenericDialog gd) {
int rows = (int)getFirstArg();
int columns = (int)getNextArg();
Expand Down
2 changes: 1 addition & 1 deletion ij/plugin/frame/Recorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ void runCode() {
break;
}
}
if (text.charAt(end)=='\n')
if (end<text.length() && text.charAt(end)=='\n')
end--;
while (end<text.length()-1) {
end++;
Expand Down
46 changes: 31 additions & 15 deletions ij/plugin/frame/ThresholdAdjuster.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ThresholdAdjuster extends PlugInDialog implements PlugIn, Measureme
public static final String LOC_KEY = "threshold.loc";
public static final String MODE_KEY = "threshold.mode";
public static final String DARK_BACKGROUND = "threshold.dark";
public static final String NO_RESET = "threshold.no-reset";
public static final String RAW_VALUES = "threshold.raw";
public static final String SIXTEEN_BIT = "threshold.16-bit";
static final int RED=0, BLACK_AND_WHITE=1, OVER_UNDER=2;
Expand Down Expand Up @@ -61,12 +62,12 @@ public class ThresholdAdjuster extends PlugInDialog implements PlugIn, Measureme
boolean done;
int lutColor;
Choice methodChoice, modeChoice;
Checkbox darkBackground, stackCheckbox, rawValues, sixteenBitCheckbox;
Checkbox darkBackground, stackCheckbox, noResetCheckbox, rawValues, sixteenBitCheckbox;
boolean firstActivation = true;
boolean setButtonPressed;
boolean noReset = true;
boolean sixteenBit = true;
boolean sixteenBitChanged;
boolean sixteenBit = false;
boolean noResetChanged;
boolean enterPressed;
boolean windowActivated;

Expand Down Expand Up @@ -207,7 +208,7 @@ public ThresholdAdjuster() {

// checkboxes
panel = new Panel();
panel.setLayout(new GridLayout(2, 2));
panel.setLayout(new GridLayout(3, 2));
boolean db = Prefs.get(DARK_BACKGROUND, Prefs.blackBackground?true:false);
darkBackground = new Checkbox("Dark background");
darkBackground.setState(db);
Expand All @@ -217,16 +218,23 @@ public ThresholdAdjuster() {
stackCheckbox.setState(false);
stackCheckbox.addItemListener(this);
panel.add(stackCheckbox);
sixteenBit = Prefs.get(SIXTEEN_BIT, true);
noReset = sixteenBit;
noReset = Prefs.get(NO_RESET, true);
sixteenBit = Prefs.get(SIXTEEN_BIT, false);
if (sixteenBit)
noReset = true;
noResetCheckbox = new Checkbox("Don't reset range");
noResetCheckbox.setState(noReset);
noResetCheckbox.addItemListener(this);
panel.add(noResetCheckbox);
rawValues = new Checkbox("Raw values");
rawValues.setState(Prefs.get(RAW_VALUES, false));
rawValues.addItemListener(this);
panel.add(rawValues);
sixteenBitCheckbox = new Checkbox("16-bit histogram");
sixteenBitCheckbox.setState(sixteenBit);
sixteenBitCheckbox.addItemListener(this);
panel.add(sixteenBitCheckbox);
rawValues = new Checkbox("Raw values");
rawValues.setState(Prefs.get(RAW_VALUES, false));
rawValues.addItemListener(this);
panel.add(rawValues);

c.gridx = 0;
c.gridy = y++;
c.gridwidth = 2;
Expand Down Expand Up @@ -389,12 +397,17 @@ public synchronized void itemStateChanged(ItemEvent e) {
}
} else if (source==darkBackground) {
doBackground = true;
} else if (source==noResetCheckbox) {
noReset = noResetCheckbox.getState();
noResetChanged = true;
doAutoAdjust = true;
} else if (source==rawValues) {
ThresholdAdjuster.update();
} else if (source==sixteenBitCheckbox) {
sixteenBit = sixteenBitCheckbox.getState();
noReset = sixteenBit;
sixteenBitChanged = true;
if (sixteenBit)
noReset = true;
noResetChanged = true;
doAutoAdjust = true;
} else
doAutoAdjust = true;
Expand Down Expand Up @@ -486,9 +499,11 @@ boolean entireStack(ImagePlus imp) {
}

void autoSetLevels(ImagePlus imp) {
int bitDepth = imp.getBitDepth();
boolean darkb = darkBackground!=null && darkBackground.getState();
boolean stack = entireStack(imp);
String methodAndOptions = method+(darkb?" dark":"")+(sixteenBit?" 16-bit":"")+(stack?" stack":"");
boolean hist16 = sixteenBit && bitDepth!=32;
String methodAndOptions = method+(darkb?" dark":"")+(hist16?" 16-bit":"")+(stack?" stack":"")+(noReset?" no-reset":"");
imp.setAutoThreshold(methodAndOptions);
ImageProcessor ip = imp.getProcessor();
double level1 = ip.getMinThreshold();
Expand Down Expand Up @@ -709,8 +724,8 @@ void adjustMaxThreshold(ImagePlus imp, ImageProcessor ip, int cvalue) {

void reset(ImagePlus imp, ImageProcessor ip) {
//IJ.log("reset1: "+noReset+" "+sixteenBitChanged+" "+mode);
if (sixteenBitChanged) {
sixteenBitChanged = false;
if (noResetChanged) {
noResetChanged = false;
if ((noReset&&mode!=OVER_UNDER) || ip.getBitDepth()==8)
return;
if (!noReset) {
Expand Down Expand Up @@ -955,6 +970,7 @@ public void close() {
Prefs.saveLocation(LOC_KEY, getLocation());
Prefs.set(MODE_KEY, mode);
Prefs.set(DARK_BACKGROUND, darkBackground.getState());
Prefs.set(NO_RESET, noResetCheckbox.getState());
Prefs.set(SIXTEEN_BIT, sixteenBitCheckbox.getState());
Prefs.set(RAW_VALUES, rawValues.getState());
synchronized(this) {
Expand Down
12 changes: 8 additions & 4 deletions release-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</head>
<body>

<li> <u>1.54g27 07 October 2023</u>
<li> <u>1.54g30 16 October 2023</u>
<ul>
<li> Thanks to Yuekan Jiao, replaced “Don’t reset range” with
“16-bit histogram” in the <i>Image&gt;Adjust&gt;Threshold</i> dialog
and added a '16-bit' option to the setAutoThreshold()
<li> Thanks to Yuekan Jiao, added a “16-bit histogram”
option to the <i>Image&gt;Adjust&gt;Threshold</i> dialog
and a '16-bit' option to the setAutoThreshold()
macro function and the ImagePlus.setAutoThreshold(String) method.
When this option is enabled, the full 16-bit histogram is used to
calculate the threshold of 16-bit images
Expand All @@ -31,6 +31,10 @@
are opened using Bio-Formats.
<li> Thanks to Fred Damen and Michael Schmid, the ImageProcessor.getSliceNumber()
method no longer requires a PlugInFilter to return the stack position.
<li> Thanks to Fred Damen, added the Dialog.getLocation(x,y) macro function. DOC
<li> Thanks to Fred Damen, the second argument of the
Dialog.addDirectory(label,defaultdir) function is no longer ignored when
the user clicks on the "Browse" button.
<li> Thanks to 'Phiir42', fixed bug with closed tables reopening after
a macro finishes.
<li> Thanks to 'Ender', fixed headless mode "Scale Bar" and "Show Info" bugs.
Expand Down

0 comments on commit 24983ae

Please sign in to comment.