Skip to content

Commit

Permalink
2019.07.22 (1.52q30; IJ.getValue)
Browse files Browse the repository at this point in the history
  • Loading branch information
rasband committed Jul 22, 2019
1 parent aa8eb7b commit 5d859c1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 37 deletions.
39 changes: 39 additions & 0 deletions ij/IJ.java
Expand Up @@ -571,6 +571,45 @@ public static void deleteRows(int row1, int row2) {
Overlay.updateTableOverlay(imp, row1, row2, tableSize);
rt.show("Results");
}

/** Returns a measurement result, where 'measurement' is "Area",
* "Mean", "StdDev", "Mode", "Min", "Max", "X", "Y", "XM", "YM",
* "Perim.", "BX", "BY", "Width", "Height", "Major", "Minor", "Angle",
* "Circ.", "Feret", "IntDen", "Median", "Skew", "Kurt", "%Area",
* "RawIntDen", "Ch", "Slice", "Frame", "FeretX", "FeretY",
* "FeretAngle", "MinFeret", "AR", "Round", "Solidity", "MinThr"
* or "MaxThr". Add " raw" to the argument to disable calibration,
* for example IJ.getValue("Mean raw"). Add " limit" to enable
* the "limit to threshold" option.
*/
public static double getValue(ImagePlus imp, String measurement) {
String options = "";
int index = measurement.indexOf(" ");
if (index>0) {
if (index<measurement.length()-1)
options = measurement.substring(index+1, measurement.length());
measurement = measurement.substring(0, index);
}
int measurements = Measurements.ALL_STATS + Measurements.SLICE;
if (options.contains("limit"))
measurements += Measurements.LIMIT;
Calibration cal = null;
if (options.contains("raw")) {
cal = imp.getCalibration();
imp.setCalibration(null);
}
ImageStatistics stats = imp.getStatistics(measurements);
ResultsTable rt = new ResultsTable();
Analyzer analyzer = new Analyzer(imp, measurements, rt);
analyzer.saveResults(stats, imp.getRoi());
double value = Double.NaN;
try {
value = rt.getValue(measurement, 0);
} catch (Exception e) {};
if (cal!=null)
imp.setCalibration(cal);
return value;
}

/** Returns a reference to the "Results" window TextPanel.
Opens the "Results" window if it is currently not open.
Expand Down
2 changes: 1 addition & 1 deletion ij/ImageJ.java
Expand Up @@ -78,7 +78,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.52q";
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
35 changes: 3 additions & 32 deletions ij/macro/Functions.java
Expand Up @@ -2376,6 +2376,7 @@ void makeSelection() {
double singleVal = getNextArg();
arr = new double[]{singleVal};//only 1 box
} else {
interp.putTokenBack();
arr = getNextArray();//>= 2 boxes
}
nBoxes = arr.length;
Expand Down Expand Up @@ -4902,48 +4903,18 @@ else if (key.equals("font.size")) {
} else if (key.equals("done")) {
return interp.done?1:0;
} else if (key.startsWith("Length")) {
return getMeasurementValue(key);
return IJ.getValue(getImage(), key);
} else {
String[] headings = ResultsTable.getDefaultHeadings();
for (int i=0; i<headings.length; i++) {
if (key.startsWith(headings[i]))
return getMeasurementValue(key);
return IJ.getValue(getImage(), key);
}
interp.error("Invalid key");
return 0.0;
}
}

double getMeasurementValue(String measurement) {
String options = "";
int index = measurement.indexOf(" ");
if (index>0) {
if (index<measurement.length()-1)
options = measurement.substring(index+1, measurement.length());
measurement = measurement.substring(0, index);
}
ImagePlus imp = getImage();
int measurements = ALL_STATS + SLICE;
if (options.contains("limit"))
measurements += LIMIT;
Calibration cal = null;
if (options.contains("raw")) {
cal = imp.getCalibration();
imp.setCalibration(null);
}
ImageStatistics stats = imp.getStatistics(measurements);
ResultsTable rt = new ResultsTable();
Analyzer analyzer = new Analyzer(imp, measurements, rt);
analyzer.saveResults(stats, imp.getRoi());
double value = Double.NaN;
try {
value = rt.getValue(measurement, 0);
} catch (Exception e) {};
if (cal!=null)
imp.setCalibration(cal);
return value;
}

double getColorValue(Color color) {
ImagePlus imp = WindowManager.getCurrentImage();
if (imp==null || imp.getBitDepth()==24)
Expand Down
3 changes: 0 additions & 3 deletions ij/measure/ResultsTable.java
Expand Up @@ -1131,17 +1131,14 @@ public static ResultsTable open(String path) throws IOException {
return rt;
}
rt.showRowNumbers(path.contains("Results"));
//System.out.println("lines.length: "+lines.length);
for (int i=firstRow; i<lines.length; i++) {
rt.incrementCounter();
String[] items = lines[i].split(cellSeparator);
//System.out.println("items.length: "+items.length+" |"+lines[i]+"| "+lines[i].length());
for (int j=firstColumn; j<headings.length; j++) {
if (j==labelsIndex&&labels)
rt.addLabel(headings[labelsIndex], items[labelsIndex]);
else {
double value = j<items.length?Tools.parseDouble(items[j]):Double.NaN;
//System.out.println(i+" "+j+" "+value+" "+(items[j]!=null?items[j]+" "+items[j].length():"null"));
if (Double.isNaN(value)) {
String item = j<items.length?items[j]:"";
if (commasReplaced) {
Expand Down
4 changes: 3 additions & 1 deletion release-notes.html
Expand Up @@ -5,7 +5,7 @@
</head>
<body>

<li> <u>1.52q27 20 July 2019</u>
<li> <u>1.52q30 22 July 2019</u>
<ul>
<li> Thanks to Michael Schmid, added the "Non-blocking filter dialogs"
option to <i>Edit&gt;Options&gt;Misc</i>. The Convolve,
Expand All @@ -28,6 +28,8 @@
plot window commands also now use labels.
<li> Thanks to Jerome Mutterer, added the getValue("Length")
macro function.
<li> Added the IJ.getValue(imp,measurement) method, where
'measurement' is "Area", "Mean", "StdDev", etc.
<li> Thanks to Stein Rorvik, fixed a bug that caused
<i>File&gt;Import&gt;Image Sequence</i> to not
correctly handle RGB48 images when "Use virtual stack"
Expand Down

0 comments on commit 5d859c1

Please sign in to comment.