public class WekaSegmentation extends Object
Modifier and Type | Field and Description |
---|---|
static int |
MAX_NUM_CLASSES
maximum number of classes (labels) allowed
|
Constructor and Description |
---|
WekaSegmentation()
No-image constructor.
|
WekaSegmentation(boolean isProcessing3D)
Constructor for both 2D and 3D images.
|
WekaSegmentation(ij.ImagePlus trainingImage)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addBinaryData(ij.ImagePlus labelImage,
FeatureStack featureStack,
String className)
Add instances to a specific class from a label (binary) image.
|
boolean |
addBinaryData(ij.ImagePlus labelImage,
FeatureStack featureStack,
String className1,
String className2)
Add instances to two classes from a label (binary) image.
|
boolean |
addBinaryData(ij.ImagePlus inputImage,
ij.ImagePlus labelImage,
ij.ImagePlus filters,
String whiteClassName,
String blackClassName)
Add binary training data from input and label images.
|
boolean |
addBinaryData(ij.ImagePlus inputImage,
ij.ImagePlus labelImage,
String whiteClassName,
String blackClassName)
Add binary training data from input and label images.
|
boolean |
addBinaryData(ij.ImagePlus labelImage,
int n,
String whiteClassName,
String blackClassName)
Add label image as binary data
|
boolean |
addBinaryData(List<Point3f>[] classPoints,
FeatureStackArray fsa,
String whiteClassName,
String blackClassName)
Add instances to two classes from lists of coordinates.
|
boolean |
addCenterLinesBinaryData(ij.ImagePlus labelImage,
int n,
String whiteClassName,
String blackClassName)
Add center lines of label image as binary data
|
void |
addClass()
Add new segmentation class.
|
boolean |
addErodedBinaryData(ij.ImagePlus labelImage,
int n,
String whiteClassName,
String blackClassName)
Add eroded version of label image as binary data
|
void |
addExample(int classNum,
Roi roi,
int n)
Adds a ROI to the list of examples for a certain class
and slice.
|
boolean |
addLabeledData(ij.ImagePlus labelImage,
FeatureStack featureStack)
Add instances from a labeled image.
|
boolean |
addLabeledData(ij.ImagePlus inputImage,
ij.ImagePlus labelImage)
Add labeled training data from input and label images.
|
boolean |
addLabeledData(ij.ImagePlus inputImage,
ij.ImagePlus labelImage,
int[] classIndexToLabel,
int numSamples)
Add training data from input and labeled images.
|
boolean |
addLabeledData(ij.ImagePlus inputImage,
ij.ImagePlus labelImage,
String[] classNames,
int numSamples)
Add training data from input and labeled images.
|
boolean |
addLabeledData(ij.process.ImageProcessor labelImage,
FeatureStack featureStack,
int[] classIndexToLabel,
int numSamples)
Add instances reading the pixel classes from a label image.
|
boolean |
addLabeledData(ij.process.ImageProcessor labelImage,
FeatureStack featureStack,
String[] classNames,
int numSamples)
Add instances reading the pixel classes from a label image.
|
boolean |
addRandomBalancedBinaryData(ij.ImagePlus inputImage,
ij.ImagePlus labelImage,
ij.ImagePlus filters,
String whiteClassName,
String blackClassName,
int numSamples)
Add binary training data from input and label images in a
random and balanced way (same number of samples per class).
|
boolean |
addRandomBalancedBinaryData(ij.ImagePlus inputImage,
ij.ImagePlus labelImage,
String whiteClassName,
String blackClassName,
int numSamples)
Add binary training data from input and label images in a
random and balanced way (same number of samples per class).
|
boolean |
addRandomBalancedBinaryData(ij.ImagePlus inputImage,
ij.ImagePlus labelImage,
String whiteClassName,
String blackClassName,
int numSamples,
ij.ImagePlus mask)
Add binary training data from input and label images in a
random and balanced way (same number of samples per class).
|
boolean |
addRandomBalancedBinaryData(ij.ImagePlus inputImage,
ij.ImagePlus labelImage,
String whiteClassName,
String blackClassName,
int numSamples,
ij.ImagePlus mask,
ij.ImagePlus weights)
Add binary training data from input and label images in a
random and balanced way (same number of samples per class).
|
boolean |
addRandomBalancedBinaryData(ij.process.ImageProcessor labelImage,
FeatureStack featureStack,
String whiteClassName,
String blackClassName,
int numSamples)
Add instances to two classes from a label (binary) image in a random
and balanced way.
|
boolean |
addRandomBalancedBinaryData(ij.process.ImageProcessor labelImage,
ij.process.ImageProcessor mask,
FeatureStack featureStack,
String whiteClassName,
String blackClassName,
int numSamples)
Add instances to two classes from a label (binary) image in a random
and balanced way (with repetition).
|
boolean |
addRandomBalancedBinaryData(ij.process.ImageProcessor labelImage,
ij.process.ImageProcessor mask,
ij.process.ImageProcessor weights,
FeatureStack featureStack,
String whiteClassName,
String blackClassName,
int numSamples)
Add instances to two classes from a label (binary) image in a random
and balanced way (with repetition).
|
boolean |
addRandomBalancedBinaryData(List<Point3f>[] classPoints,
FeatureStackArray fsa,
ij.ImagePlus weights,
String whiteClassName,
String blackClassName,
int numSamples)
Add instances to two classes from lists of coordinates in a random
and balanced way.
|
boolean |
addRandomBalancedBinaryData(List<Point3f>[] classPoints,
FeatureStackArray fsa,
String whiteClassName,
String blackClassName,
int numSamples)
Add instances to two classes from lists of coordinates in a random
and balanced way.
|
boolean |
addRandomBalancedLabeledData(ij.ImagePlus inputImage,
ij.ImagePlus labelImage,
int numSamples)
Add training data from input and labeled images in a
random and balanced way (same number of samples per class).
|
boolean |
addRandomBalancedLabeledData(ij.ImagePlus inputImage,
ij.ImagePlus labelImage,
int[] classIndexToLabel,
int numSamples)
Add training data from input and labeled images in a
random and balanced way (same number of samples per class).
|
boolean |
addRandomBalancedLabeledData(ij.ImagePlus inputImage,
ij.ImagePlus labelImage,
String[] classNames,
int numSamples)
Add training data from input and labeled images in a
random and balanced way (same number of samples per class).
|
boolean |
addRandomBalancedLabeledData(ij.process.ImageProcessor labelImage,
FeatureStack featureStack,
int numSamples)
Add instances from a labeled image in a random and balanced way.
|
boolean |
addRandomBalancedLabeledData(ij.process.ImageProcessor labelImage,
FeatureStack featureStack,
String[] classNames,
int numSamples)
Add instances reading the pixel classes from a label image in a random
and balanced way.
|
boolean |
addRandomBalancedLabeledData(ij.process.ImageProcessor labelImage,
int[] classIndexToLabel,
FeatureStack featureStack,
int numSamples)
Add instances from a labeled image in a random and balanced way.
|
boolean |
addRandomData(ij.ImagePlus labelImage,
FeatureStack featureStack,
String whiteClassName,
int numSamples)
Add instances defined by a label (binary) image in a random
way.
|
boolean |
addRandomData(ij.ImagePlus inputImage,
ij.ImagePlus labelImage,
String whiteClassName,
int numSamples)
Add training data from input and a binary label image in a
random way.
|
boolean |
adjustSegmentationStateToData(Instances data)
Adjust current segmentation state (attributes and classes) to
loaded data
|
void |
applyClassifier(boolean classify)
Apply current classifier to current image.
|
ij.ImagePlus |
applyClassifier(FeatureStackArray fsa,
int numThreads,
boolean probabilityMaps)
Apply current classifier to a set of feature vectors (given in a feature
stack array).
|
ij.ImagePlus |
applyClassifier(ij.ImagePlus imp)
Apply current classifier to a given image.
|
ij.ImagePlus |
applyClassifier(ij.ImagePlus imp,
FeatureStackArray fsa,
int numThreads,
boolean probabilityMaps)
Apply current classifier to a given image with precomputed features.
|
ij.ImagePlus |
applyClassifier(ij.ImagePlus imp,
ij.ImagePlus filters,
int numThreads,
boolean probabilityMaps)
Apply current classifier to a given image with precomputed features.
|
ij.ImagePlus |
applyClassifier(ij.ImagePlus imp,
int[] origin,
int[] cropDims,
int numThreads,
boolean probabilityMaps)
Apply current classifier to a user-defined ROI of a given image.
|
ij.ImagePlus |
applyClassifier(ij.ImagePlus imp,
int[] tilesPerDim,
int numThreads,
boolean probabilityMaps)
Apply the current classifier to an image subdividing the
image in tiles for memory saving.
|
ij.ImagePlus |
applyClassifier(ij.ImagePlus imp,
int numThreads,
boolean probabilityMaps)
Apply current classifier to a given image.
|
ij.ImagePlus |
applyClassifier(Instances data,
int w,
int h,
int numThreads,
boolean probabilityMaps)
Apply current classifier to set of instances
|
void |
applyClassifier(int numThreads,
boolean classify)
Apply current classifier to current image.
|
ij.ImagePlus |
applyClassifierMT(ij.ImagePlus imp,
int numThreads,
boolean probabilityMaps)
Apply current classifier to a given image in a complete concurrent way.
|
void |
balanceTrainingData()
Balance number of instances per class (in the loaded training data)
|
static Instances |
balanceTrainingData(Instances data)
Balance number of instances per class
|
Callable<ArrayList<ij.ImagePlus>> |
classifyListOfImages(ArrayList<ij.ImagePlus> images,
Instances dataInfo,
AbstractClassifier classifier,
AtomicInteger counter,
boolean probabilityMaps)
Classify a list of images in a concurrent way
|
Callable<ij.ImagePlus> |
classifySlice(ij.ImagePlus slice,
Instances dataInfo,
AbstractClassifier classifier,
AtomicInteger counter,
boolean probabilityMaps)
Classify a slice in a concurrent way
|
static Callable<int[][]> |
confusionMatrixBinarySlice(ij.process.ImageProcessor proposal,
ij.process.ImageProcessor expectedLabels,
double threshold)
Calculate the confusion matrix of a slice (2 classes)
|
boolean |
containsColorFeatures(Instances data)
Check if a set of Weka instances has color attributes
(given by the presence of the attribute names "Hue",
"Saturation" or "Brightness").
|
boolean |
containsExclusive2DFeatures(Instances data)
Check if a set of Weka instances has 2D image attributes
(given by the presence of the attribute names from FeatureStack
which are not present in FeatureStack3D).
|
boolean |
containsExclusive3DFeatures(Instances data)
Check if a set of Weka instances has 3D image attributes
(given by the presence of the attribute names from FeatureStack3D
which are not present in FeatureStack).
|
String |
createHeaderName(boolean bool3d,
boolean boolRGB)
Create the name of the training header.
|
Callable<Instances> |
createInstances(ArrayList<String> classNames,
FeatureStack featureStack)
Create instances of a feature stack (to be submitted to an Executor Service)
|
Instances |
createTrainingInstances()
Create training instances out of the user markings
|
void |
deleteExample(int classNum,
int nSlice,
int index)
Remove an example list from a class and specific slice
|
boolean |
doClassBalance()
Get the boolean flag to enable/disable the class balance
|
boolean |
doHomogenizeClasses()
Deprecated.
use doClassBalance
|
void |
filterFeatureStackByList()
Filter feature stack based on the list of feature names to use
|
static void |
filterFeatureStackByList(ArrayList<String> featureNames,
FeatureStack featureStack)
Filter feature stack based on the list of feature names to use
|
ij.ImagePlus |
getClassifiedImage()
Get current classification result
|
AbstractClassifier |
getClassifier()
Returns the current classifier.
|
String |
getClassLabel(int classNum)
Get the label name of a class.
|
String[] |
getClassLabels()
Get the current class labels
|
static int[][] |
getConfusionMatrix(ij.ImagePlus proposal,
ij.ImagePlus expectedLabels,
double threshold)
Get confusion matrix (2 classes)
|
int[][] |
getConfusionMatrix(ij.ImagePlus proposedLabels,
ij.ImagePlus expectedLabels,
int whiteClassIndex,
int blackClassIndex)
Get confusion matrix (binary images)
|
boolean[] |
getEnabledFeatures()
Get the current enabled features
|
List<Roi> |
getExamples(int classNum,
int n)
Return the list of examples for a certain class.
|
FeatureStack |
getFeatureStack(int i)
Get current feature stack
|
FeatureStackArray |
getFeatureStackArray()
Get the current feature stack array
|
Instances |
getLoadedTrainingData()
Returns a the loaded training data or null, if no training data was
loaded.
|
int |
getMaxDepth()
Get maximum depth of the random forest
|
float |
getMaximumSigma()
Get the maximum sigma/radius to use in the features
|
int |
getMembranePatchSize()
Get the membrane patch size
|
int |
getMembraneThickness()
Get current expected membrane thickness
|
float |
getMinimumSigma()
Get the minimum sigma (radius) to use in the features
|
String |
getModelVersion()
Get the version of the plugin used for creating the model.
|
int |
getNumOfClasses()
Get the current number of classes.
|
int |
getNumOfTrees()
Get current number of trees (for random forest training)
|
int |
getNumRandomFeatures()
Get number of random features (random forest training)
|
int[][] |
getTestConfusionMatrix(ij.ImagePlus image,
ij.ImagePlus filters,
ij.ImagePlus expectedLabels,
int whiteClassIndex,
int blackClassIndex)
Get the confusion matrix for an input image and its expected labels
|
int[][] |
getTestConfusionMatrix(ij.ImagePlus image,
ij.ImagePlus expectedLabels,
int whiteClassIndex,
int blackClassIndex)
Get the confusion matrix for an input image and its expected labels
|
double |
getTestError(ij.ImagePlus image,
ij.ImagePlus labels,
ij.ImagePlus filters,
int whiteClassIndex,
int blackClassIndex,
boolean verbose)
Get test error of current classifier on a specific image and its binary labels
|
double |
getTestError(ij.ImagePlus image,
ij.ImagePlus labels,
int whiteClassIndex,
int blackClassIndex,
boolean verbose)
Get test error of current classifier on a specific image and its binary labels
|
Instances |
getTraceTrainingData()
Returns a the trace training data or null, if no examples have been
given.
|
Instances |
getTrainHeader()
Get the current training header
|
double |
getTrainingError(boolean verbose)
Get training error (from loaded data).
|
Instances |
getTrainingInstances()
Get loaded (or accumulated) training instances
|
void |
homogenizeTrainingData()
Deprecated.
use balanceTrainingData
|
static Instances |
homogenizeTrainingData(Instances data)
Deprecated.
use balanceTrainingData
|
boolean |
isProcessing3D()
Check the use of 3D or 2D features
|
boolean |
loadClassifier(InputStream classifierInputStream)
load a binary classifier from a stream
|
boolean |
loadClassifier(String filename)
Read header classifier from a .model file
|
boolean |
loadNewImage(ij.ImagePlus newImage)
Load a new image to segment (no GUI)
|
boolean |
loadTrainingData(String pathname)
Load training data
|
void |
mergeDataInPlace(Instances first,
Instances second)
Merge two datasets of Weka instances in place
|
Instances |
readDataFromARFF(String filename)
Read ARFF file
|
boolean |
saveClassifier(String filename)
Write current classifier into a file
|
boolean |
saveData(String pathname)
Save training data into a file (.arff)
|
void |
saveFeatureStack(int slice,
String dir,
String fileWithExt)
Save specific slice feature stack
|
boolean |
selectAttributes()
Select attributes of current data by BestFirst search.
|
static Instances |
selectAttributes(Instances data)
Select attributes using BestFirst search to reduce
the number of parameters per instance of a dataset
|
void |
setClassBalance(boolean balanceClasses)
Set flag to balance classes before training
|
void |
setClassifier(AbstractClassifier cls)
Set current classifier
|
void |
setClassLabel(int classNum,
String label)
Set the name of a class.
|
void |
setClassLabels(String[] classLabels)
Set the labels for each class
|
void |
setDoClassBalance(boolean balanceClasses)
Set the flag to balance the class distributions
|
void |
setDoHomogenizeClasses(boolean homogenizeClasses)
Deprecated.
use setDoClassBalance
|
void |
setEnabledFeatures(boolean[] newFeatures)
Set the new enabled features
|
boolean |
setFeatures(ArrayList<String> featureNames)
Set features to use during training
|
void |
setFeaturesDirty()
Forces the feature stack to be updated whenever it is needed next.
|
void |
setFeatureStackArray(FeatureStackArray fsa)
Assign an arbitrary filter stack array
|
void |
setHomogenizeClasses(boolean homogenizeClasses)
Deprecated.
use setClassBalance
|
void |
setLoadedClassNames(ArrayList<String> classNames)
Set the list of loaded class names
|
void |
setLoadedTrainingData(Instances data)
Set pre-loaded training data (not from the user traces)
|
void |
setMaximumSigma(float sigma)
Set the maximum sigma/radius to use in the features
|
void |
setMembranePatchSize(int patchSize)
Set the membrane patch size (it must be an odd number)
|
void |
setMembraneThickness(int thickness)
Set expected membrane thickness (this will be the width of
the center column of the membrane filter)
|
void |
setMinimumSigma(float sigma)
Set the minimum sigma (radius) to use in the features
|
void |
setNumOfClasses(int numOfClasses)
Set the current number of classes.
|
void |
setProjectFolder(String projectFolder)
Set the project folder
|
boolean |
setTrainHeader(Instances newHeader)
Set current training header, and attempt to adjust segmentation state to it.
|
void |
setTrainingImage(ij.ImagePlus imp)
Set the training image (single image or stack)
|
void |
setUpdateFeatures(boolean updateFeatures)
Set feature update flag
|
void |
setUseNeighbors(boolean useNeighbors)
Set the use of the neighbor features
|
void |
shutDownNow()
Shut down the executor service for training and feature creation
|
boolean |
trainClassifier()
Train classifier with the current instances
|
void |
udpateDataClassification(ij.ImagePlus labels,
String className1,
String className2)
Update the class attribute of "loadedTrainingData" from
the input binary labels.
|
boolean |
updateClassifier(int newNumTrees,
int newRandomFeatures,
int newMaxDepth)
Update fast random forest classifier with new values
|
static void |
updateDataClassification(Instances data,
ij.ImagePlus labels,
int classIndex1,
int classIndex2)
Update the class attribute of "data" from
the input binary labels.
|
static void |
updateDataClassification(Instances data,
ij.ImagePlus labels,
int classIndex1,
int classIndex2,
ArrayList<Point3f>[] mismatches)
Update the class attribute of "data" from
the input binary labels.
|
Instances |
updateWholeImageData()
Create the whole image data (instances) from the current image and feature stack.
|
void |
useAllFeatures()
Force segmentator to use all available features
|
boolean |
writeDataToARFF(Instances data,
String filename)
Write current instances into an ARFF file
|
public static final int MAX_NUM_CLASSES
public WekaSegmentation(ij.ImagePlus trainingImage)
trainingImage
- The image to be segmented/trainedpublic WekaSegmentation()
setTrainingImage()
. Another option is to use the
object to load a classifier and apply it to other images without
additional training.public WekaSegmentation(boolean isProcessing3D)
loadClassifier()
or by setting later a training image
(using setTrainingImage()
).isProcessing3D
- true to process images in 3D and false to do it in 2Dpublic void setTrainingImage(ij.ImagePlus imp)
imp
- training imagepublic void addExample(int classNum, Roi roi, int n)
classNum
- the number of the classroi
- the ROI containing the new examplen
- number of the current slicepublic void deleteExample(int classNum, int nSlice, int index)
classNum
- the number of the examples' classnSlice
- the slice numberindex
- the index of the example list to removepublic List<Roi> getExamples(int classNum, int n)
classNum
- the number of the examples' classn
- the slice numberpublic void setHomogenizeClasses(boolean homogenizeClasses)
homogenizeClasses
- true to resample the classes before trainingpublic void setClassBalance(boolean balanceClasses)
balanceClasses
- true to resample the classes before trainingpublic void setNumOfClasses(int numOfClasses)
addClass()
instead.numOfClasses
- the new number of classespublic int getNumOfClasses()
public void addClass()
public void setClassLabel(int classNum, String label)
classNum
- class indexlabel
- new name for the classpublic String getClassLabel(int classNum)
classNum
- class indexpublic boolean loadTrainingData(String pathname)
pathname
- complete path name of the training data file (.arff)public Instances getLoadedTrainingData()
public Instances getTraceTrainingData()
public ij.ImagePlus getClassifiedImage()
public Instances getTrainHeader()
public boolean loadClassifier(InputStream classifierInputStream)
classifierInputStream
- the input streampublic boolean loadClassifier(String filename)
filename
- complete path and file namepublic boolean containsColorFeatures(Instances data)
data
- set of Weka instancespublic boolean containsExclusive2DFeatures(Instances data)
data
- set of Weka instancespublic boolean containsExclusive3DFeatures(Instances data)
data
- set of Weka instancespublic AbstractClassifier getClassifier()
public boolean saveClassifier(String filename)
filename
- name (with complete path) of the destination filepublic boolean saveData(String pathname)
pathname
- complete path namepublic void setUseNeighbors(boolean useNeighbors)
useNeighbors
- flag to set the use of the neighbor featurespublic boolean addBinaryData(ij.ImagePlus labelImage, FeatureStack featureStack, String className)
labelImage
- binary imagefeatureStack
- corresponding feature stackclassName
- name of the class which receives the instancespublic boolean addBinaryData(ij.ImagePlus labelImage, FeatureStack featureStack, String className1, String className2)
labelImage
- binary imagefeatureStack
- corresponding feature stackclassName1
- name of the class which receives the white pixelsclassName2
- name of the class which receives the black pixelspublic boolean addLabeledData(ij.ImagePlus labelImage, FeatureStack featureStack)
labelImage
- labeled imagefeatureStack
- corresponding feature stackpublic boolean addRandomBalancedLabeledData(ij.process.ImageProcessor labelImage, FeatureStack featureStack, int numSamples)
labelImage
- labeled image (labels are positive integer or 0)featureStack
- corresponding feature stacknumSamples
- number of samples to add of each classpublic boolean addRandomBalancedLabeledData(ij.process.ImageProcessor labelImage, int[] classIndexToLabel, FeatureStack featureStack, int numSamples)
labelImage
- labeled imageclassIndexToLabel
- correspondences between class indices and label valuesfeatureStack
- corresponding feature stacknumSamples
- number of samples to add of each classpublic boolean addRandomBalancedBinaryData(ij.process.ImageProcessor labelImage, FeatureStack featureStack, String whiteClassName, String blackClassName, int numSamples)
labelImage
- binary imagefeatureStack
- corresponding feature stackwhiteClassName
- name of the class which receives the white pixelsblackClassName
- name of the class which receives the black pixelsnumSamples
- number of samples to add of each classpublic boolean addRandomBalancedLabeledData(ij.process.ImageProcessor labelImage, FeatureStack featureStack, String[] classNames, int numSamples)
labelImage
- label image with a different labeling per classfeatureStack
- corresponding feature stackclassNames
- array with the corresponding names of the classesnumSamples
- number of samples to add of each classpublic boolean addLabeledData(ij.process.ImageProcessor labelImage, FeatureStack featureStack, String[] classNames, int numSamples)
labelImage
- label image with a different labeling per classfeatureStack
- corresponding feature stackclassNames
- array with the corresponding names of the classesnumSamples
- total number of random samples to selectpublic boolean addLabeledData(ij.process.ImageProcessor labelImage, FeatureStack featureStack, int[] classIndexToLabel, int numSamples)
labelImage
- label image with a different labeling per classfeatureStack
- corresponding feature stackclassIndexToLabel
- array with the corresponding label values per classnumSamples
- total number of random samples to selectpublic boolean addRandomBalancedBinaryData(ij.process.ImageProcessor labelImage, ij.process.ImageProcessor mask, FeatureStack featureStack, String whiteClassName, String blackClassName, int numSamples)
labelImage
- binary imagemask
- binary mask image to prevent some pixel to be selected (null if all pixels are eligible)featureStack
- corresponding feature stackwhiteClassName
- name of the class which receives the white pixelsblackClassName
- name of the class which receives the black pixelsnumSamples
- number of samples to add of each classpublic boolean addRandomBalancedBinaryData(List<Point3f>[] classPoints, FeatureStackArray fsa, String whiteClassName, String blackClassName, int numSamples)
classPoints
- list of 3D coordinates to be used (x, y, slice)fsa
- feature stack arraywhiteClassName
- name of the class which receives the white pixelsblackClassName
- name of the class which receives the black pixelsnumSamples
- number of samples to add of each classpublic boolean addBinaryData(List<Point3f>[] classPoints, FeatureStackArray fsa, String whiteClassName, String blackClassName)
classPoints
- list of 3D coordinates to be used (x, y, slice)fsa
- feature stack arraywhiteClassName
- name of the class which receives the white pixelsblackClassName
- name of the class which receives the black pixelspublic boolean addRandomBalancedBinaryData(List<Point3f>[] classPoints, FeatureStackArray fsa, ij.ImagePlus weights, String whiteClassName, String blackClassName, int numSamples)
classPoints
- list of 3D coordinates to be used (x, y, slice)fsa
- feature stack arrayweights
- weight imagewhiteClassName
- name of the class which receives the white pixelsblackClassName
- name of the class which receives the black pixelsnumSamples
- number of samples to add of each classpublic boolean addRandomBalancedBinaryData(ij.process.ImageProcessor labelImage, ij.process.ImageProcessor mask, ij.process.ImageProcessor weights, FeatureStack featureStack, String whiteClassName, String blackClassName, int numSamples)
labelImage
- binary imagemask
- binary mask image to prevent some pixel to be selected (null if all pixels are eligible)weights
- weight imagefeatureStack
- corresponding feature stackwhiteClassName
- name of the class which receives the white pixelsblackClassName
- name of the class which receives the black pixelsnumSamples
- number of samples to add of each classpublic boolean addRandomData(ij.ImagePlus labelImage, FeatureStack featureStack, String whiteClassName, int numSamples)
labelImage
- binary imagefeatureStack
- corresponding feature stackwhiteClassName
- name of the class which receives the white pixelsnumSamples
- number of samples to add of each classpublic FeatureStack getFeatureStack(int i)
i
- number of feature stack slice (>=1)public FeatureStackArray getFeatureStackArray()
public Instances getTrainingInstances()
public void setClassifier(AbstractClassifier cls)
cls
- new classifierpublic boolean setTrainHeader(Instances newHeader)
newHeader
- the header to setpublic boolean loadNewImage(ij.ImagePlus newImage)
newImage
- new image to segmentpublic boolean addCenterLinesBinaryData(ij.ImagePlus labelImage, int n, String whiteClassName, String blackClassName)
labelImage
- binary label imagen
- feature stack array indexwhiteClassName
- class name for the white pixelsblackClassName
- class name for the black pixelspublic void filterFeatureStackByList()
public static void filterFeatureStackByList(ArrayList<String> featureNames, FeatureStack featureStack)
featureNames
- list of feature names to usefeatureStack
- feature stack to filterpublic boolean addBinaryData(ij.ImagePlus labelImage, int n, String whiteClassName, String blackClassName)
labelImage
- binary label imagen
- slice number (0 <= n < number of slices)whiteClassName
- class name for the white pixelsblackClassName
- class name for the black pixelspublic boolean addBinaryData(ij.ImagePlus inputImage, ij.ImagePlus labelImage, String whiteClassName, String blackClassName)
inputImage
- input grayscale imagelabelImage
- binary label imagewhiteClassName
- class name for the white pixelsblackClassName
- class name for the black pixelspublic boolean addLabeledData(ij.ImagePlus inputImage, ij.ImagePlus labelImage)
inputImage
- input grayscale imagelabelImage
- label image with pixel values corresponding to class indexespublic boolean addRandomBalancedBinaryData(ij.ImagePlus inputImage, ij.ImagePlus labelImage, String whiteClassName, String blackClassName, int numSamples)
inputImage
- input grayscale imagelabelImage
- binary label imagewhiteClassName
- class name for the white pixelsblackClassName
- class name for the black pixelsnumSamples
- number of samples to pick for each classpublic boolean addRandomBalancedLabeledData(ij.ImagePlus inputImage, ij.ImagePlus labelImage, int numSamples)
inputImage
- input grayscale imagelabelImage
- labeled image (labeled values are positive integer or 0)numSamples
- number of samples to pick for each classpublic boolean addRandomBalancedLabeledData(ij.ImagePlus inputImage, ij.ImagePlus labelImage, int[] classIndexToLabel, int numSamples)
inputImage
- input grayscale or RGB imagelabelImage
- labeled imageclassIndexToLabel
- correspondences between class indices and label valuesnumSamples
- number of samples to pick for each classpublic boolean addLabeledData(ij.ImagePlus inputImage, ij.ImagePlus labelImage, String[] classNames, int numSamples)
inputImage
- input grayscale imagelabelImage
- labeled image (labeled values are positive integer or 0)classNames
- array with the corresponding class namesnumSamples
- total number of random samples to pickpublic boolean addLabeledData(ij.ImagePlus inputImage, ij.ImagePlus labelImage, int[] classIndexToLabel, int numSamples)
inputImage
- input grayscale or RGB imagelabelImage
- labeled image (labeled values are positive integer or 0)classIndexToLabel
- correspondences between class indices and label valuesnumSamples
- total number of random samples to pickpublic boolean addRandomBalancedLabeledData(ij.ImagePlus inputImage, ij.ImagePlus labelImage, String[] classNames, int numSamples)
inputImage
- input grayscale imagelabelImage
- labeled image (labeled values are positive integer or 0)classNames
- array with the corresponding class namesnumSamples
- number of samples to pick for each classpublic boolean addRandomBalancedBinaryData(ij.ImagePlus inputImage, ij.ImagePlus labelImage, String whiteClassName, String blackClassName, int numSamples, ij.ImagePlus mask)
inputImage
- input grayscale imagelabelImage
- binary label imagewhiteClassName
- class name for the white pixelsblackClassName
- class name for the black pixelsnumSamples
- number of samples to pick for each classmask
- mask to prevent some pixel to be selected (null if all pixels are eligible)public boolean addRandomBalancedBinaryData(ij.ImagePlus inputImage, ij.ImagePlus labelImage, String whiteClassName, String blackClassName, int numSamples, ij.ImagePlus mask, ij.ImagePlus weights)
inputImage
- input grayscale imagelabelImage
- binary label imagewhiteClassName
- class name for the white pixelsblackClassName
- class name for the black pixelsnumSamples
- number of samples to pick for each classmask
- mask to prevent some pixel to be selected (null if all pixels are eligible)weights
- image containing the weight of each samplepublic boolean addRandomData(ij.ImagePlus inputImage, ij.ImagePlus labelImage, String whiteClassName, int numSamples)
inputImage
- input grayscale imagelabelImage
- binary label image (labels in white)whiteClassName
- class name for the white pixelsnumSamples
- number of samples to pick for each classpublic boolean addRandomBalancedBinaryData(ij.ImagePlus inputImage, ij.ImagePlus labelImage, ij.ImagePlus filters, String whiteClassName, String blackClassName, int numSamples)
inputImage
- input grayscale imagelabelImage
- binary label imagefilters
- stack of filters to create featureswhiteClassName
- class name for the white pixelsblackClassName
- class name for the black pixelsnumSamples
- number of samples to pick for each classpublic boolean addBinaryData(ij.ImagePlus inputImage, ij.ImagePlus labelImage, ij.ImagePlus filters, String whiteClassName, String blackClassName)
inputImage
- input grayscale imagelabelImage
- binary label imagefilters
- stack of filters to create featureswhiteClassName
- class name for the white pixelsblackClassName
- class name for the black pixelspublic boolean addErodedBinaryData(ij.ImagePlus labelImage, int n, String whiteClassName, String blackClassName)
labelImage
- binary label imagen
- feature stack array indexwhiteClassName
- class name for the white pixelsblackClassName
- class name for the black pixelspublic void setLoadedTrainingData(Instances data)
data
- new datapublic void useAllFeatures()
public void setProjectFolder(String projectFolder)
projectFolder
- complete path name for project folderpublic static Instances homogenizeTrainingData(Instances data)
data
- input set of instancespublic static Instances balanceTrainingData(Instances data)
data
- input set of instancespublic void homogenizeTrainingData()
public void balanceTrainingData()
public boolean selectAttributes()
public static Instances selectAttributes(Instances data)
data
- input set of instancespublic double getTrainingError(boolean verbose)
verbose
- option to display evaluation information in the log windowpublic double getTestError(ij.ImagePlus image, ij.ImagePlus labels, int whiteClassIndex, int blackClassIndex, boolean verbose)
image
- input imagelabels
- binary labelswhiteClassIndex
- index of the white classblackClassIndex
- index of the black classverbose
- option to display evaluation information in the log windowpublic int[][] getTestConfusionMatrix(ij.ImagePlus image, ij.ImagePlus expectedLabels, int whiteClassIndex, int blackClassIndex)
image
- input imageexpectedLabels
- binary labelswhiteClassIndex
- index of the white classblackClassIndex
- index of the black classpublic int[][] getConfusionMatrix(ij.ImagePlus proposedLabels, ij.ImagePlus expectedLabels, int whiteClassIndex, int blackClassIndex)
proposedLabels
- proposed binary labelsexpectedLabels
- original binary labelswhiteClassIndex
- index of white classblackClassIndex
- index of black classpublic static int[][] getConfusionMatrix(ij.ImagePlus proposal, ij.ImagePlus expectedLabels, double threshold)
proposal
- probability imageexpectedLabels
- original labelsthreshold
- binary threshold to be applied to proposalpublic static Callable<int[][]> confusionMatrixBinarySlice(ij.process.ImageProcessor proposal, ij.process.ImageProcessor expectedLabels, double threshold)
proposal
- probability image (single 2D slice)expectedLabels
- original binary labelsthreshold
- threshold to apply to proposalpublic int[][] getTestConfusionMatrix(ij.ImagePlus image, ij.ImagePlus filters, ij.ImagePlus expectedLabels, int whiteClassIndex, int blackClassIndex)
image
- input imagefilters
- stack of filters to apply to the original image in order to create the featuresexpectedLabels
- binary labelswhiteClassIndex
- index of the white classblackClassIndex
- index of the black classpublic double getTestError(ij.ImagePlus image, ij.ImagePlus labels, ij.ImagePlus filters, int whiteClassIndex, int blackClassIndex, boolean verbose)
image
- input imagelabels
- binary labelsfilters
- list of filters to create featureswhiteClassIndex
- index of the white classblackClassIndex
- index of the black classverbose
- option to display evaluation information in the log windowpublic void udpateDataClassification(ij.ImagePlus labels, String className1, String className2)
labels
- input binary labels (single image or stack)className1
- name of the white (different from 0) classclassName2
- name of the black (0) classpublic static void updateDataClassification(Instances data, ij.ImagePlus labels, int classIndex1, int classIndex2)
data
- input instanceslabels
- binary labelsclassIndex1
- index of the white (different from 0) classclassIndex2
- index of the black (0) classpublic static void updateDataClassification(Instances data, ij.ImagePlus labels, int classIndex1, int classIndex2, ArrayList<Point3f>[] mismatches)
data
- input instanceslabels
- binary labelsclassIndex1
- index of the white (different from 0) classclassIndex2
- index of the black (0) classmismatches
- public Instances readDataFromARFF(String filename)
filename
- ARFF file namepublic boolean writeDataToARFF(Instances data, String filename)
data
- set of instancesfilename
- ARFF file namepublic boolean adjustSegmentationStateToData(Instances data)
data
- loaded instancespublic String createHeaderName(boolean bool3d, boolean boolRGB)
bool3d
- true if training image is 3DboolRGB
- true if traning image is grayscalepublic Instances createTrainingInstances()
public Callable<Instances> createInstances(ArrayList<String> classNames, FeatureStack featureStack)
classNames
- names of the classes of datafeatureStack
- feature stack to create the instances frompublic boolean trainClassifier()
public ij.ImagePlus applyClassifier(ij.ImagePlus imp)
imp
- image (2D single image or stack)public ij.ImagePlus applyClassifier(ij.ImagePlus imp, int numThreads, boolean probabilityMaps)
imp
- image (2D single image or stack)numThreads
- The number of threads to use. Set to zero for
auto-detection (set by the user on the ImageJ preferences)probabilityMaps
- create probability maps for each class instead of
a classificationpublic ij.ImagePlus applyClassifierMT(ij.ImagePlus imp, int numThreads, boolean probabilityMaps)
imp
- image (2D single image or stack)numThreads
- The number of threads to use. Set to zero for
auto-detection.probabilityMaps
- create probability maps for each class instead of
a classificationpublic Callable<ij.ImagePlus> classifySlice(ij.ImagePlus slice, Instances dataInfo, AbstractClassifier classifier, AtomicInteger counter, boolean probabilityMaps)
slice
- image to classifydataInfo
- empty set of instances containing the data structure (attributes and classes)classifier
- classifier to usecounter
- counter used to display the progress in the tool barprobabilityMaps
- flag to calculate probabilities or binary resultspublic Callable<ArrayList<ij.ImagePlus>> classifyListOfImages(ArrayList<ij.ImagePlus> images, Instances dataInfo, AbstractClassifier classifier, AtomicInteger counter, boolean probabilityMaps)
images
- list of images to classifydataInfo
- empty set of instances containing the data structure (attributes and classes)classifier
- classifier to usecounter
- counter used to display the progress in the tool barprobabilityMaps
- flag to calculate probabilities or binary resultspublic ij.ImagePlus applyClassifier(ij.ImagePlus imp, ij.ImagePlus filters, int numThreads, boolean probabilityMaps)
imp
- image (2D single image or stack)filters
- stack of filters to apply to the original image in order to create the featuresnumThreads
- The number of threads to use. Set to zero for auto-detection.probabilityMaps
- create probability maps for each class instead of a classificationpublic ij.ImagePlus applyClassifier(ij.ImagePlus imp, FeatureStackArray fsa, int numThreads, boolean probabilityMaps)
imp
- image (2D single image or stack)fsa
- precomputed feature stack arraynumThreads
- The number of threads to use. Set to zero for auto-detection.probabilityMaps
- create probability maps for each class instead of a classificationpublic void applyClassifier(boolean classify)
classify
- flag to get labels or probability maps (false = labels)public void applyClassifier(int numThreads, boolean classify)
numThreads
- The number of threads to use. Set to zero for
auto-detection (defined by the user in the ImageJ options).classify
- flag to get labels or probability maps (false = labels)public ij.ImagePlus applyClassifier(ij.ImagePlus imp, int[] tilesPerDim, int numThreads, boolean probabilityMaps)
imp
- input image to be classifiedtilesPerDim
- number of tiles to be used on each dimension of the imagenumThreads
- number of threads to use per tile (0 for autodetection)probabilityMaps
- flag to get labels or probability maps (false = labels)public ij.ImagePlus applyClassifier(ij.ImagePlus imp, int[] origin, int[] cropDims, int numThreads, boolean probabilityMaps)
imp
- image to classify (2D or 3D)origin
- coordinates of the origin of the ROI (cropping box)cropDims
- dimensions of the ROI (cropping box)numThreads
- The number of threads to use. Set to zero for
auto-detection (set by the user on the ImageJ preferences)probabilityMaps
- create probability maps for each class instead of
a classificationpublic Instances updateWholeImageData()
public ij.ImagePlus applyClassifier(Instances data, int w, int h, int numThreads, boolean probabilityMaps)
data
- set of instancesw
- image widthh
- image heightnumThreads
- The number of threads to use. Set to zero for
auto-detection.probabilityMaps
- flag to indicate probability map (true) or segmentation output (false)public ij.ImagePlus applyClassifier(FeatureStackArray fsa, int numThreads, boolean probabilityMaps)
fsa
- feature stack arraynumThreads
- The number of threads to use. Set to zero for auto-detection.probabilityMaps
- probability flag. Tue: probability maps are calculated, false: binary classificationpublic boolean setFeatures(ArrayList<String> featureNames)
featureNames
- list of feature names to usepublic void setMembraneThickness(int thickness)
thickness
- expected membrane thickness (in pixels)public int getMembraneThickness()
public void setMembranePatchSize(int patchSize)
patchSize
- membrane patch sizepublic int getMembranePatchSize()
public void setMaximumSigma(float sigma)
sigma
- maximum sigma to use in the features filterspublic float getMaximumSigma()
public void setMinimumSigma(float sigma)
sigma
- minimum sigma (radius) to use in the features filterspublic float getMinimumSigma()
public int getNumOfTrees()
public int getNumRandomFeatures()
public int getMaxDepth()
public void setDoHomogenizeClasses(boolean homogenizeClasses)
homogenizeClasses
- boolean flag to enable/disable the class balancepublic boolean doHomogenizeClasses()
public void setDoClassBalance(boolean balanceClasses)
balanceClasses
- boolean flag to enable/disable the class balancepublic boolean doClassBalance()
public void setUpdateFeatures(boolean updateFeatures)
updateFeatures
- new feature update flagpublic void setFeaturesDirty()
public boolean updateClassifier(int newNumTrees, int newRandomFeatures, int newMaxDepth)
newNumTrees
- new number of treesnewRandomFeatures
- new number of random features per treenewMaxDepth
- new maximum depth per treepublic void setEnabledFeatures(boolean[] newFeatures)
newFeatures
- new enabled feature flagspublic boolean[] getEnabledFeatures()
public void mergeDataInPlace(Instances first, Instances second)
first
- first (and destination) datasetsecond
- second datasetpublic void shutDownNow()
public void setFeatureStackArray(FeatureStackArray fsa)
fsa
- new filter stack arraypublic void setLoadedClassNames(ArrayList<String> classNames)
classNames
- new list of class namespublic void saveFeatureStack(int slice, String dir, String fileWithExt)
slice
- slice numberdir
- directory to save the stack(s)fileWithExt
- file name with extension for the file(s)public void setClassLabels(String[] classLabels)
classLabels
- array containing all the class labelspublic String[] getClassLabels()
public boolean isProcessing3D()
public String getModelVersion()
Copyright © 2015–2021 Fiji. All rights reserved.