public class BatchReader extends Object
A BatchReader object reads a CSV file whose first column is expected to contain pathnames pointing to image files. If the pathnames are not absolute, they are supposed to be relative to the directory containing the CSV file itself.
Typical usage is as follows:
BatchReader reader = new BatchReader("filename.csv"); while ( reader.next() ) { ImagePlus image = reader.getImage(); String[] fields = reader.getRow(); // Work with the image and the associated fields... image.close() }
Blank lines and lines starting with a '#' are ignored. The first line of the CSV file is treated as a header line.
Constructor and Description |
---|
BatchReader(File file)
Creates a new reader.
|
BatchReader(File file,
boolean noHeaders)
Creates a new reader.
|
BatchReader(String filename)
Creates a new reader.
|
BatchReader(String filename,
boolean noHeaders)
Creates a new reader.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes any opened images.
|
void |
fillResultsTable(ij.measure.ResultsTable rt)
Update a ResultsTable with the contents of the current row.
|
String |
getCell(int index)
Gets the contents of a specific cell within the current row.
|
String |
getCell(String name)
Gets the contents of a specific cell within the current row.
|
String |
getCell(String[] names)
Gets the contents of a specific cell within the current row.
|
String |
getCell(String[] names,
String fallback)
Gets the contents of a specific cell within the current row.
|
String |
getCSVRow()
Gets the current row as a single string containing comma-separated values.
|
String |
getCSVRow(char separator)
Gets the current row as a single string, with values separated by the
specified character.
|
String[] |
getHeaders()
Gets the headers as found in the CSV file.
|
ij.ImagePlus |
getImage()
Gets the current image.
|
String[] |
getRow()
Gets a copy of the current row.
|
boolean |
hasImage()
Indicates if there’s an image ready to be processed.
|
boolean |
next()
Moves to the next available image.
|
void |
readCSV()
Reads the entire CSV file.
|
void |
setCaseSensitive(boolean caseSensitive)
Sets the case-sensitivity option.
|
public BatchReader(String filename, boolean noHeaders)
filename
- pathname to the file to readnoHeaders
- if true, the first non-comment line will not be treated as a
header linepublic BatchReader(String filename)
filename
- pathname to the file to readpublic BatchReader(File file)
file
- the file object to read frompublic BatchReader(File file, boolean noHeaders)
file
- the file object to read fromnoHeaders
- if true, the first non-comment line will not be treated as a
header linepublic void setCaseSensitive(boolean caseSensitive)
getCell(String)
method and its overloaded variants will match header
names in a case-sensitive way. The default is false.caseSensitive
- true to match header names case-sensitively.public boolean next()
getImage()
method.public boolean hasImage()
public ij.ImagePlus getImage()
public String[] getRow()
public String getCell(int index)
index
- a 0-based column indexpublic String getCell(String[] names, String fallback)
names
- an array of accepted column namesfallback
- the default value to return if the cell is not foundpublic String getCell(String[] names)
names
- an array of accepted column namespublic String getCell(String name)
name
- the column name, as indicated in the header rowpublic String getCSVRow(char separator)
separator
- the column separator characterpublic String getCSVRow()
public String[] getHeaders() throws IOException
IOException
public void fillResultsTable(ij.measure.ResultsTable rt)
rt
- the ResultsTable object to update.public void close()
Note that this only closes images that have not been reached yet by any call to next(). Closing previous images is the responsibility of the caller.
public void readCSV() throws IOException
next()
or getHeaders()
methods if needed.IOException
- if any I/O error occurs while attempting to read the fileCopyright © 2021. All rights reserved.