- java.lang.Object
-
- ij.measure.ResultsTable
-
- All Implemented Interfaces:
Cloneable
public class ResultsTable extends Object implements Cloneable
This is a table for storing measurement results and strings as columns of values. Call the static ResultsTable.getResultsTable() method to get a reference to the ResultsTable used by the Analyze/Measure command.- See Also:
Analyzer.getResultsTable()
-
-
Field Summary
Fields Modifier and Type Field Description static intANGLEstatic intAREAstatic intAREA_FRACTIONstatic intASPECT_RATIOstatic shortAUTO_FORMATstatic intCHANNELstatic intCIRCULARITYstatic intCOLUMN_IN_USEstatic intCOLUMN_NOT_FOUNDstatic intFERETstatic intFERET_ANGLEstatic intFERET_Xstatic intFERET_Ystatic intFRAMEstatic intINTEGRATED_DENSITYbooleanisResultsTablestatic intKURTOSISstatic intLAST_HEADINGstatic intMAJORstatic intMAXstatic intMAX_COLUMNSObsolete; use getLastColumn().static intMAX_THRESHOLDstatic intMEANstatic intMEDIANstatic intMINstatic intMIN_FERETstatic intMIN_THRESHOLDstatic intMINORstatic intMODEstatic intPERIMETERstatic intRAW_INTEGRATED_DENSITYstatic intROI_HEIGHTstatic intROI_WIDTHstatic intROI_Xstatic intROI_Ystatic intROUNDNESSstatic intSKEWNESSstatic intSLICEstatic intSOLIDITYstatic intSTD_DEVstatic intTABLE_FULLstatic intX_CENTER_OF_MASSstatic intX_CENTROIDstatic intY_CENTER_OF_MASSstatic intY_CENTROID
-
Constructor Summary
Constructors Constructor Description ResultsTable()Constructs an empty ResultsTable with the counter=0, no columns and the precision set to 3 or the "Decimal places" value in Analyze/Set Measurements if that value is higher than 3.ResultsTable(Integer nRows)Constructs a ResultsTable with 'nRows' rows.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddColumns()Obsolete; the addValue() method automatically adds columns as needed.voidaddLabel(String label)Adds a label to the beginning of the current row.voidaddLabel(String columnHeading, String label)Deprecated.Replaced by setValue(String,int,String)voidaddResults()Adds the last row in this table to the Results window without updating it.voidaddRow()Adds a row to the table.voidaddValue(int column, double value)Adds a numeric value to the specified column, on the last table row.voidaddValue(String column, double value)Adds a numeric value to the specified column, on the last table row.voidaddValue(String column, String value)Adds a string value to the specified column, on the last table row.booleanapplyMacro(String macro)Applies a macro to each row of the table; the columns are assigned variable names as given by getHeadingsAsVaribleNames().Objectclone()Duplicates this ResultsTable.booleancolumnDeleted()booleancolumnExists(int column)Returns 'true' if the specified column exists and is not empty.booleancolumnExists(String column)Returns 'true' if the specified column exists and is not emptly.static ResultsTablecreateTableFromImage(ImageProcessor ip)Creates a ResultsTable from an image or image selection.static Stringd2s(double n, int decimalPlaces)This is a version of IJ.d2s() that uses scientific notation for small numbes that would otherwise display as zero.voiddeleteColumn(String column)Deletes the specified column.voiddeleteRow(int rowIndex)Deletes the specified row.voiddeleteRows(int index1, int index2)Deletes the specified rows.voiddisableRowLabels()Set the row label column to null if the column label is "Label".static ResultsTablegetActiveTable()Returns the active (front most) displayed ResultsTable.float[]getColumn(int column)Returns a copy of the given column as a float array, or null if the column is empty.double[]getColumn(String column)Returns a copy of the given column as a double array, or null if the column is not found.double[]getColumnAsDoubles(int column)Returns a copy of the given column as a double array, or null if the column is empty.String[]getColumnAsStrings(String column)Returns a copy of the given column as a String array, or null if the column is not found.Variable[]getColumnAsVariables(String column)Implements the Table.getColumn() macro function.StringgetColumnHeading(int column)Returns the heading of the specified column or null if the column is empty.StringgetColumnHeadings()Returns a tab or comma delimited string containing the column headings.intgetColumnIndex(String heading)Returns the index of the first column with the given heading.intgetCounter()Returns the current value of the measurement counter.static StringgetDefaultHeading(int index)static String[]getDefaultHeadings()Returns the default headings ("Area","Mean","StdDev", etc.).intgetFreeColumn(String heading)Sets the heading of the the first available column and returns that column's index.String[]getHeadings()Returns the column headings as an array of Strings.String[]getHeadingsAsVariableNames()Returns the column headings; headings not suitable as variable names are converted to valid variable names by replacing non-fitting characters with underscores and adding underscores.StringgetLabel(int row)Returns the label of the specified row.intgetLastColumn()Returns the index of the last used column, or -1 if no columns are used.static ResultsTablegetResultsTable()Returns the ResultsTable used by the Measure command.static ResultsTablegetResultsTable(String title)Returns the ResultsTable with the specified title, or null if it does not exist,static TextWindowgetResultsWindow()Obsolete.StringgetRowAsString(int row)Returns a tab or comma delimited string representing the given row, where 0<=row<=size()-1.StringgetStringValue(int column, int row)Returns the string value of the given column and row, where column must be less than or equal the value returned by getLastColumn() and row must be greater than or equal zero and less than the value returned by size().StringgetStringValue(String column, int row)Returns the string value of the given column and row, where row must be greater than or equal zero and less than the value returned by size().ImageProcessorgetTableAsImage()Returns the contents of this ResultsTable as a FloatProcessor.StringgetTitle()floatgetValue(int column, int row)Deprecated.replaced by getValueAsDoubledoublegetValue(String column, int row)Returns the value of the specified column and row, where column is the column heading and row is a number greater than or equal zero and less than value returned by size().doublegetValueAsDouble(int column, int row)Returns the value of the given column and row, where column must be less than or equal the value returned by getLastColumn() and row must be greater than or equal zero and less than the value returned by size().voidincrementCounter()Adds a row to the table.static ResultsTableopen(String path)Opens a tab or comma delimited text file and returns it as a ResultsTable.static ResultsTableopen2(String path)Opens a tab or comma delimited text file and returns it as a ResultsTable, without requiring a try/catch statement.voidrenameColumn(String oldName, String newName)Changes the name of a column.voidreset()booleansave(String path)Saves this ResultsTable as a tab or comma delimited text file.booleansaveAndRename(String path)voidsaveAs(String path)voidsaveColumnHeaders(boolean save)static booleanselectRow(Roi roi)Selects the row in the "Results" table assocuiated with the specified Roi.voidsetColumn(String column, Variable[] array)Implements the Table.setColumn() macro function.voidsetDecimalPlaces(int column, int digits)voidsetDefaultHeadings()Sets the headings used by the Measure command ("Area", "Mean", etc.).voidsetHeading(int column, String heading)Deprecated.Replaced by addValue(String,double) and setValue(String,int,double)voidsetIsResultsTable(boolean isResultsTable)voidsetLabel(String label, int row)Adds a label to the beginning of the specified row, or updates an existing lable, where 0<=rowvoidsetNaNEmptyCells(boolean NaNEmptyCells)Set 'true' to initially fill data arrays with NaNs instead of zeros.voidsetPrecision(int precision)Sets the decimal places (digits to the right of decimal point) that are used when this table is displayed.voidsetValue(int column, int row, double value)Sets the value of the given column and row, where where 0<=column<=(lastRow+1 and 0<=row<=size().voidsetValue(int column, int row, String value)Sets the string value of the given column and row, where where 0<=column<=(lastRow+1 and 0<=row<=size().voidsetValue(String column, int row, double value)Sets the value of the given column and row, where where 0<=row<size().voidsetValue(String column, int row, String value)Sets the string value of the given column and row, where where 0<=row<size().voidsetValues(String column, double[] values)Sets the values of the given column to the values in the array.voidshow(String windowTitle)Displays the contents of this ResultsTable in a window with the specified title, or updates an existing results window.voidshowRowIndexes(boolean showIndexes)booleanshowRowNumbers()voidshowRowNumbers(boolean showNumbers)intsize()Returns the size of this ResultsTable.voidsort(String column)Sorts this table on the specified column, with string support.StringtoString()voidupdate(int measurements, ImagePlus imp, Roi roi)voidupdateResults()Updates the Results window.
-
-
-
Field Detail
-
MAX_COLUMNS
public static final int MAX_COLUMNS
Obsolete; use getLastColumn().- See Also:
- Constant Field Values
-
COLUMN_NOT_FOUND
public static final int COLUMN_NOT_FOUND
- See Also:
- Constant Field Values
-
COLUMN_IN_USE
public static final int COLUMN_IN_USE
- See Also:
- Constant Field Values
-
TABLE_FULL
public static final int TABLE_FULL
- See Also:
- Constant Field Values
-
AUTO_FORMAT
public static final short AUTO_FORMAT
- See Also:
- Constant Field Values
-
AREA
public static final int AREA
- See Also:
- Constant Field Values
-
MEAN
public static final int MEAN
- See Also:
- Constant Field Values
-
STD_DEV
public static final int STD_DEV
- See Also:
- Constant Field Values
-
MODE
public static final int MODE
- See Also:
- Constant Field Values
-
MIN
public static final int MIN
- See Also:
- Constant Field Values
-
MAX
public static final int MAX
- See Also:
- Constant Field Values
-
X_CENTROID
public static final int X_CENTROID
- See Also:
- Constant Field Values
-
Y_CENTROID
public static final int Y_CENTROID
- See Also:
- Constant Field Values
-
X_CENTER_OF_MASS
public static final int X_CENTER_OF_MASS
- See Also:
- Constant Field Values
-
Y_CENTER_OF_MASS
public static final int Y_CENTER_OF_MASS
- See Also:
- Constant Field Values
-
PERIMETER
public static final int PERIMETER
- See Also:
- Constant Field Values
-
ROI_X
public static final int ROI_X
- See Also:
- Constant Field Values
-
ROI_Y
public static final int ROI_Y
- See Also:
- Constant Field Values
-
ROI_WIDTH
public static final int ROI_WIDTH
- See Also:
- Constant Field Values
-
ROI_HEIGHT
public static final int ROI_HEIGHT
- See Also:
- Constant Field Values
-
MAJOR
public static final int MAJOR
- See Also:
- Constant Field Values
-
MINOR
public static final int MINOR
- See Also:
- Constant Field Values
-
ANGLE
public static final int ANGLE
- See Also:
- Constant Field Values
-
CIRCULARITY
public static final int CIRCULARITY
- See Also:
- Constant Field Values
-
FERET
public static final int FERET
- See Also:
- Constant Field Values
-
INTEGRATED_DENSITY
public static final int INTEGRATED_DENSITY
- See Also:
- Constant Field Values
-
MEDIAN
public static final int MEDIAN
- See Also:
- Constant Field Values
-
SKEWNESS
public static final int SKEWNESS
- See Also:
- Constant Field Values
-
KURTOSIS
public static final int KURTOSIS
- See Also:
- Constant Field Values
-
AREA_FRACTION
public static final int AREA_FRACTION
- See Also:
- Constant Field Values
-
RAW_INTEGRATED_DENSITY
public static final int RAW_INTEGRATED_DENSITY
- See Also:
- Constant Field Values
-
CHANNEL
public static final int CHANNEL
- See Also:
- Constant Field Values
-
SLICE
public static final int SLICE
- See Also:
- Constant Field Values
-
FRAME
public static final int FRAME
- See Also:
- Constant Field Values
-
FERET_X
public static final int FERET_X
- See Also:
- Constant Field Values
-
FERET_Y
public static final int FERET_Y
- See Also:
- Constant Field Values
-
FERET_ANGLE
public static final int FERET_ANGLE
- See Also:
- Constant Field Values
-
MIN_FERET
public static final int MIN_FERET
- See Also:
- Constant Field Values
-
ASPECT_RATIO
public static final int ASPECT_RATIO
- See Also:
- Constant Field Values
-
ROUNDNESS
public static final int ROUNDNESS
- See Also:
- Constant Field Values
-
SOLIDITY
public static final int SOLIDITY
- See Also:
- Constant Field Values
-
MIN_THRESHOLD
public static final int MIN_THRESHOLD
- See Also:
- Constant Field Values
-
MAX_THRESHOLD
public static final int MAX_THRESHOLD
- See Also:
- Constant Field Values
-
LAST_HEADING
public static final int LAST_HEADING
- See Also:
- Constant Field Values
-
isResultsTable
public boolean isResultsTable
-
-
Constructor Detail
-
ResultsTable
public ResultsTable()
Constructs an empty ResultsTable with the counter=0, no columns and the precision set to 3 or the "Decimal places" value in Analyze/Set Measurements if that value is higher than 3.
-
ResultsTable
public ResultsTable(Integer nRows)
Constructs a ResultsTable with 'nRows' rows.
-
-
Method Detail
-
getResultsTable
public static ResultsTable getResultsTable()
Returns the ResultsTable used by the Measure command. This table must be displayed in the "Results" window.
-
getResultsTable
public static ResultsTable getResultsTable(String title)
Returns the ResultsTable with the specified title, or null if it does not exist,
-
getActiveTable
public static ResultsTable getActiveTable()
Returns the active (front most) displayed ResultsTable.
-
getResultsWindow
public static TextWindow getResultsWindow()
Obsolete.
-
addRow
public void addRow()
Adds a row to the table.
-
incrementCounter
public void incrementCounter()
Adds a row to the table.
-
addColumns
public void addColumns()
Obsolete; the addValue() method automatically adds columns as needed.- See Also:
addValue(String, double)
-
getCounter
public int getCounter()
Returns the current value of the measurement counter.
-
size
public int size()
Returns the size of this ResultsTable.
-
addValue
public void addValue(int column, double value)Adds a numeric value to the specified column, on the last table row. Use addRow() to add another row to the table.- See Also:
addRow(),addValue(String,double),addValue(String,String),size()
-
addValue
public void addValue(String column, double value)
Adds a numeric value to the specified column, on the last table row. If the column does not exist, it is created. Use addRow() to add another row to the table.JavaScript example:
rt = new ResultsTable(); for (n=0; n<=2*Math.PI; n+=0.1) { rt.addRow(); rt.addValue("n", n); rt.addValue("Sine(n)", Math.sin(n)); rt.addValue("Cos(n)", Math.cos(n)); } rt.show("Sine/Cosine Table");- See Also:
addRow(),addValue(String,String),size()
-
addValue
public void addValue(String column, String value)
Adds a string value to the specified column, on the last table row. If the column does not exist, it is created. Use addRow() to add another row to the table.- See Also:
addRow(),addValue(String,double),size()
-
addLabel
public void addLabel(String label)
Adds a label to the beginning of the current row.
-
addLabel
public void addLabel(String columnHeading, String label)
Deprecated.Replaced by setValue(String,int,String)
-
setLabel
public void setLabel(String label, int row)
Adds a label to the beginning of the specified row, or updates an existing lable, where 0<=rowshow() to update the window displaying the table.
-
disableRowLabels
public void disableRowLabels()
Set the row label column to null if the column label is "Label".
-
getColumn
public double[] getColumn(String column)
Returns a copy of the given column as a double array, or null if the column is not found.
-
getColumnAsStrings
public String[] getColumnAsStrings(String column)
Returns a copy of the given column as a String array, or null if the column is not found.
-
getColumn
public float[] getColumn(int column)
Returns a copy of the given column as a float array, or null if the column is empty.
-
getColumnAsDoubles
public double[] getColumnAsDoubles(int column)
Returns a copy of the given column as a double array, or null if the column is empty.
-
getTableAsImage
public ImageProcessor getTableAsImage()
Returns the contents of this ResultsTable as a FloatProcessor.
-
createTableFromImage
public static ResultsTable createTableFromImage(ImageProcessor ip)
Creates a ResultsTable from an image or image selection.
-
columnExists
public boolean columnExists(int column)
Returns 'true' if the specified column exists and is not empty.
-
getColumnIndex
public int getColumnIndex(String heading)
Returns the index of the first column with the given heading. heading. If not found, returns COLUMN_NOT_FOUND.
-
getFreeColumn
public int getFreeColumn(String heading)
Sets the heading of the the first available column and returns that column's index. Returns COLUMN_IN_USE if this is a duplicate heading.
-
getValueAsDouble
public double getValueAsDouble(int column, int row)Returns the value of the given column and row, where column must be less than or equal the value returned by getLastColumn() and row must be greater than or equal zero and less than the value returned by size().
-
getValue
public float getValue(int column, int row)Deprecated.replaced by getValueAsDouble
-
getValue
public double getValue(String column, int row)
Returns the value of the specified column and row, where column is the column heading and row is a number greater than or equal zero and less than value returned by size(). Throws an IllegalArgumentException if this ResultsTable does not have a column with the specified heading.
-
columnExists
public boolean columnExists(String column)
Returns 'true' if the specified column exists and is not emptly.
-
getStringValue
public String getStringValue(String column, int row)
Returns the string value of the given column and row, where row must be greater than or equal zero and less than the value returned by size().
-
getStringValue
public String getStringValue(int column, int row)
Returns the string value of the given column and row, where column must be less than or equal the value returned by getLastColumn() and row must be greater than or equal zero and less than the value returned by size().
-
getLabel
public String getLabel(int row)
Returns the label of the specified row. Returns null if the row does not have a label.
-
setValue
public void setValue(String column, int row, double value)
Sets the value of the given column and row, where where 0<=row<size(). If the specified column does not exist, it is created. When adding columns,show()must be called to update the window that displays the table.
-
setValue
public void setValue(int column, int row, double value)Sets the value of the given column and row, where where 0<=column<=(lastRow+1 and 0<=row<=size().
-
setValue
public void setValue(String column, int row, String value)
Sets the string value of the given column and row, where where 0<=row<size(). If the specified column does not exist, it is created. When adding columns,show()must be called to update the window that displays the table.
-
setValue
public void setValue(int column, int row, String value)Sets the string value of the given column and row, where where 0<=column<=(lastRow+1 and 0<=row<=size().
-
setValues
public void setValues(String column, double[] values)
Sets the values of the given column to the values in the array. If the specified column does not exist, it is created. When adding columns,show()must be called to update the window that displays the table. If the array is shorter than the column length, the remaining values of the column are left unchanged. If the array is longer, the table is extended. String values are unaffected, but only used if the numeric value at the given position is NaN.
-
getColumnHeadings
public String getColumnHeadings()
Returns a tab or comma delimited string containing the column headings.
-
getHeadings
public String[] getHeadings()
Returns the column headings as an array of Strings.
-
getColumnHeading
public String getColumnHeading(int column)
Returns the heading of the specified column or null if the column is empty.
-
getRowAsString
public String getRowAsString(int row)
Returns a tab or comma delimited string representing the given row, where 0<=row<=size()-1.
-
getColumnAsVariables
public Variable[] getColumnAsVariables(String column)
Implements the Table.getColumn() macro function.
-
setColumn
public void setColumn(String column, Variable[] array)
Implements the Table.setColumn() macro function.
-
setHeading
public void setHeading(int column, String heading)Deprecated.Replaced by addValue(String,double) and setValue(String,int,double)
-
setDefaultHeadings
public void setDefaultHeadings()
Sets the headings used by the Measure command ("Area", "Mean", etc.).
-
setPrecision
public void setPrecision(int precision)
Sets the decimal places (digits to the right of decimal point) that are used when this table is displayed.
-
setDecimalPlaces
public void setDecimalPlaces(int column, int digits)
-
setNaNEmptyCells
public void setNaNEmptyCells(boolean NaNEmptyCells)
Set 'true' to initially fill data arrays with NaNs instead of zeros.
-
showRowNumbers
public void showRowNumbers(boolean showNumbers)
-
showRowNumbers
public boolean showRowNumbers()
-
showRowIndexes
public void showRowIndexes(boolean showIndexes)
-
saveColumnHeaders
public void saveColumnHeaders(boolean save)
-
d2s
public static String d2s(double n, int decimalPlaces)
This is a version of IJ.d2s() that uses scientific notation for small numbes that would otherwise display as zero.
-
deleteRow
public void deleteRow(int rowIndex)
Deletes the specified row.
-
deleteRows
public void deleteRows(int index1, int index2)Deletes the specified rows.
-
deleteColumn
public void deleteColumn(String column)
Deletes the specified column.
-
renameColumn
public void renameColumn(String oldName, String newName)
Changes the name of a column.
-
reset
public void reset()
-
getLastColumn
public int getLastColumn()
Returns the index of the last used column, or -1 if no columns are used.
-
addResults
public void addResults()
Adds the last row in this table to the Results window without updating it.
-
updateResults
public void updateResults()
Updates the Results window.
-
show
public void show(String windowTitle)
Displays the contents of this ResultsTable in a window with the specified title, or updates an existing results window. Opens a new window if there is no open text window with this title. The title must be "Results" if this table was obtained using ResultsTable.getResultsTable() or Analyzer.getResultsTable .
-
open2
public static ResultsTable open2(String path)
Opens a tab or comma delimited text file and returns it as a ResultsTable, without requiring a try/catch statement. Displays a file open dialog if 'path' is empty or null.
-
open
public static ResultsTable open(String path) throws IOException
Opens a tab or comma delimited text file and returns it as a ResultsTable. Displays a file open dialog if 'path' is empty or null.- Throws:
IOException- See Also:
open2(String)
-
save
public boolean save(String path)
Saves this ResultsTable as a tab or comma delimited text file. The table is saved as a CSV (comma-separated values) file if 'path' ends with ".csv". Displays a file save dialog if 'path' is empty or null. Does nothing if the table is empty. Displays an error message and returns 'false' if there is an error.
-
saveAndRename
public boolean saveAndRename(String path)
-
saveAs
public void saveAs(String path) throws IOException
- Throws:
IOException
-
getDefaultHeadings
public static String[] getDefaultHeadings()
Returns the default headings ("Area","Mean","StdDev", etc.).
-
getDefaultHeading
public static String getDefaultHeading(int index)
-
applyMacro
public boolean applyMacro(String macro)
Applies a macro to each row of the table; the columns are assigned variable names as given by getHeadingsAsVaribleNames(). New variables starting with an uppercase letter create a new column with this name. The variable 'row' (the row index) is pre-defined. Except for the row label (if existing), currently only supports numeric values, no Strings.- Returns:
- false in case of a macro error
-
getHeadingsAsVariableNames
public String[] getHeadingsAsVariableNames()
Returns the column headings; headings not suitable as variable names are converted to valid variable names by replacing non-fitting characters with underscores and adding underscores. To make unique names, underscores+numbers are added as required.
-
getTitle
public String getTitle()
-
columnDeleted
public boolean columnDeleted()
-
selectRow
public static boolean selectRow(Roi roi)
Selects the row in the "Results" table assocuiated with the specified Roi. The row number is obtained from the roi name..
-
sort
public void sort(String column)
Sorts this table on the specified column, with string support. Author: 'mountain_man', 8 April 2019
-
setIsResultsTable
public void setIsResultsTable(boolean isResultsTable)
-
-