Пример #1
0
def training_Classifier():

    input_im = IJ.openImage(
        "/home/aik19/Achintha/Sintering analysis/Scripts/Sintering_Analysis_The_New_Approach/training_sample_1.tif"
    )
    labels = IJ.openImage(
        "/home/aik19/Achintha/Sintering analysis/Scripts/Sintering_Analysis_The_New_Approach/Filtered_training_Sample.labels.tif"
    )
    # for all slices in input2, add white pixels as labels for class 2 and
    #black pixels as labels for class 1
    segmentator = WekaSegmentation(input_im)
    segmentator.addBinaryData(input_im, labels, "class 2", "class 1")
    segmentator.trainClassifier()
    testImage = IJ.openImage(
        "/home/aik19/Achintha/Sintering analysis/Scripts/Sintering_Analysis_The_New_Approach/74122_micro_test_3.tif"
    )
    result = segmentator.applyClassifier(testImage)
    result.show()
Пример #2
0
del channels

# create empty feature stack
features = FeatureStack(stack.getWidth(), stack.getHeight(), False)

# set my features to the feature stack
features.setStack(stack)
# put my feature stack into the array
featuresArray.set(features, 0)
featuresArray.setEnabledFeatures(features.getEnabledFeatures())

mp = MultilayerPerceptron()
hidden_layers = "%i,%i,%i" % (20, 14, 8)
mp.setHiddenLayers(hidden_layers)
mp.setLearningRate(0.7)
mp.setDecay(True)
mp.setTrainingTime(200)
mp.setMomentum(0.3)

wekaSegmentation = WekaSegmentation(image)
wekaSegmentation.setFeatureStackArray(featuresArray)
wekaSegmentation.setClassifier(mp)

wekaSegmentation.addExample(0, posroi, 1)
wekaSegmentation.addExample(1, negroi, 1)
wekaSegmentation.trainClassifier()
wekaSegmentation.saveClassifier(folder + "\\vessel-classifier_big.model")
output = wekaSegmentation.applyClassifier(image, featuresArray, 0, True)

output.show()