def create_new_tst_project(cls): # Instantiate 'shell' shell = HeadlessShell( ) # Create a blank project file and load it. newProjectFilePath = cls.PROJECT_FILE newProjectFile = ProjectManager.createBlankProjectFile(newProjectFilePath, PixelClassificationWorkflow, []) newProjectFile.close() shell.openProjectFile(newProjectFilePath) workflow = shell.workflow # Add a file from ilastik.applets.dataSelection.opDataSelection import DatasetInfo info = DatasetInfo() info.filePath = cls.SAMPLE_DATA opDataSelection = workflow.dataSelectionApplet.topLevelOperator opDataSelection.DatasetGroup.resize(1) opDataSelection.DatasetGroup[0][0].setValue(info) # Set some features ScalesList = [0.3, 0.7, 1, 1.6, 3.5, 5.0, 10.0] FeatureIds = [ 'GaussianSmoothing', 'LaplacianOfGaussian', 'StructureTensorEigenvalues', 'HessianOfGaussianEigenvalues', 'GaussianGradientMagnitude', 'DifferenceOfGaussians' ] opFeatures = workflow.featureSelectionApplet.topLevelOperator opFeatures.Scales.setValue( ScalesList ) opFeatures.FeatureIds.setValue( FeatureIds ) # sigma: 0.3 0.7 1.0 1.6 3.5 5.0 10.0 selections = numpy.array( [[True, False, False, False, False, False, False], [True, False, False, False, False, False, False], [True, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False]] ) opFeatures.SelectionMatrix.setValue(selections) # Add some labels directly to the operator opPixelClass = workflow.pcApplet.topLevelOperator opPixelClass.LabelNames.setValue(['Label 1', 'Label 2']) slicing1 = sl[0:1,0:10,0:10,0:1,0:1] labels1 = 1 * numpy.ones(slicing2shape(slicing1), dtype=numpy.uint8) opPixelClass.LabelInputs[0][slicing1] = labels1 slicing2 = sl[0:1,0:10,10:20,0:1,0:1] labels2 = 2 * numpy.ones(slicing2shape(slicing2), dtype=numpy.uint8) opPixelClass.LabelInputs[0][slicing2] = labels2 # Save and close shell.projectManager.saveProject() del shell
def create_new_tst_project(cls): # Instantiate 'shell' shell = HeadlessShell() # Create a blank project file and load it. newProjectFilePath = cls.PROJECT_FILE newProjectFile = ProjectManager.createBlankProjectFile( newProjectFilePath, PixelClassificationWorkflow, []) newProjectFile.close() shell.openProjectFile(newProjectFilePath) workflow = shell.workflow # Add a file from ilastik.applets.dataSelection.opDataSelection import DatasetInfo info = DatasetInfo() info.filePath = cls.SAMPLE_DATA opDataSelection = workflow.dataSelectionApplet.topLevelOperator opDataSelection.DatasetGroup.resize(1) opDataSelection.DatasetGroup[0][0].setValue(info) # Set some features ScalesList = [0.3, 0.7, 1, 1.6, 3.5, 5.0, 10.0] FeatureIds = [ 'GaussianSmoothing', 'LaplacianOfGaussian', 'StructureTensorEigenvalues', 'HessianOfGaussianEigenvalues', 'GaussianGradientMagnitude', 'DifferenceOfGaussians' ] opFeatures = workflow.featureSelectionApplet.topLevelOperator opFeatures.Scales.setValue(ScalesList) opFeatures.FeatureIds.setValue(FeatureIds) # sigma: 0.3 0.7 1.0 1.6 3.5 5.0 10.0 selections = numpy.array( [[True, False, False, False, False, False, False], [True, False, False, False, False, False, False], [True, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False]]) opFeatures.SelectionMatrix.setValue(selections) # Add some labels directly to the operator opPixelClass = workflow.pcApplet.topLevelOperator slicing1 = sl[0:1, 0:10, 0:10, 0:1, 0:1] labels1 = 1 * numpy.ones(slicing2shape(slicing1), dtype=numpy.uint8) opPixelClass.LabelInputs[0][slicing1] = labels1 slicing2 = sl[0:1, 0:10, 10:20, 0:1, 0:1] labels2 = 2 * numpy.ones(slicing2shape(slicing2), dtype=numpy.uint8) opPixelClass.LabelInputs[0][slicing2] = labels2 # Save and close shell.projectManager.saveProject() del shell
def create_new_project(cls, project_file_path, dataset_path): # Instantiate 'shell' shell = HeadlessShell() # Create a blank project file and load it. newProjectFile = ProjectManager.createBlankProjectFile(project_file_path, PixelClassificationWorkflow, []) newProjectFile.close() shell.openProjectFile(project_file_path) workflow = shell.workflow # Add a file from ilastik.applets.dataSelection.opDataSelection import FilesystemDatasetInfo info = FilesystemDatasetInfo(filePath=dataset_path) opDataSelection = workflow.dataSelectionApplet.topLevelOperator opDataSelection.DatasetGroup.resize(1) opDataSelection.DatasetGroup[0][0].setValue(info) # Set some features ScalesList = [0.3, 0.7, 1, 1.6, 3.5, 5.0, 10.0] FeatureIds = [ "GaussianSmoothing", "LaplacianOfGaussian", "StructureTensorEigenvalues", "HessianOfGaussianEigenvalues", "GaussianGradientMagnitude", "DifferenceOfGaussians", ] opFeatures = workflow.featureSelectionApplet.topLevelOperator opFeatures.Scales.setValue(ScalesList) opFeatures.FeatureIds.setValue(FeatureIds) # sigma: 0.3 0.7 1.0 1.6 3.5 5.0 10.0 selections = numpy.array( [ [True, False, False, False, False, False, False], [True, False, False, False, False, False, False], [True, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], ] ) opFeatures.SelectionMatrix.setValue(selections) # Add some labels directly to the operator opPixelClass = workflow.pcApplet.topLevelOperator opPixelClass.LabelNames.setValue(["Label 1", "Label 2"]) slicing1 = sl[0:1, 0:10, 0:10, 0:1, 0:1] labels1 = 1 * numpy.ones(slicing2shape(slicing1), dtype=numpy.uint8) opPixelClass.LabelInputs[0][slicing1] = labels1 slicing2 = sl[0:1, 0:10, 10:20, 0:1, 0:1] labels2 = 2 * numpy.ones(slicing2shape(slicing2), dtype=numpy.uint8) opPixelClass.LabelInputs[0][slicing2] = labels2 # Train the classifier opPixelClass.FreezePredictions.setValue(False) _ = opPixelClass.Classifier.value # Save and close shell.projectManager.saveProject() del shell