This example loads a PNG microscopy image from disk, from which gray-scale scalar values are created.
Then, the PersistenceDiagram is computed and thresholds are applied base on persistence to maintain only the most persistent features. This results in a simplified persistence diagram (top right; non-simplified persistence diagram shown in gray).
The simplified persistence diagram is then used as a constraint for the TopologicalSimplification of the input scalar data.
This simplified data is then used as the input of the computation of the MorseSmaleComplex. Its ascending manifolds, separatrices and critical points are shown in the bottom views (with scalar value mapped to height in the bottom right view). The separatrices are also shown, as overlay over the original scalar data, in the top left view.
In this example, the MorseSmaleComplex segments the input microscopy data into biological cells.
#!/usr/bin/env pythonfromparaview.simpleimport*# create a new 'PNG Series Reader'tributepng=PNGSeriesReader(FileNames=["tribute.png"])# create a new 'Calculator'calculator1=Calculator(Input=tributepng)calculator1.ResultArrayName="originalData"calculator1.Function="-sqrt(PNGImage_X*PNGImage_X+PNGImage_Y*PNGImage_Y)"# create a new 'TTK PersistenceDiagram'tTKPersistenceDiagram1=TTKPersistenceDiagram(Input=calculator1)tTKPersistenceDiagram1.ScalarField=["POINTS","originalData"]# create a new 'Threshold'threshold1=Threshold(Input=tTKPersistenceDiagram1)threshold1.Scalars=["CELLS","PairIdentifier"]threshold1.ThresholdMethod="Between"threshold1.LowerThreshold=-0.1threshold1.UpperThreshold=999999999# create a new 'Threshold'minimumPairs=Threshold(Input=threshold1)minimumPairs.Scalars=["CELLS","PairType"]minimumPairs.ThresholdMethod="Between"minimumPairs.LowerThreshold=-1.0minimumPairs.UpperThreshold=0.0# create a new 'Calculator'calculator6=Calculator(Input=minimumPairs)calculator6.AttributeType="Cell Data"calculator6.ResultArrayName="Death"calculator6.Function="Birth+Persistence"# create a new 'Threshold'deathThreshold=Threshold(Input=calculator6)deathThreshold.Scalars=["CELLS","Death"]deathThreshold.LowerThreshold=-297.0deathThreshold.UpperThreshold=-257.391# create a new 'Threshold'maximumPairs=Threshold(Input=threshold1)maximumPairs.Scalars=["POINTS","CriticalType"]maximumPairs.LowerThreshold=3.0maximumPairs.UpperThreshold=3.0maximumPairs.AllScalars=0# create a new 'Append Datasets'appendDatasets1=AppendDatasets(Input=[deathThreshold,maximumPairs])# create a new 'Threshold'persistenceThreshold=Threshold(Input=appendDatasets1)persistenceThreshold.Scalars=["CELLS","Persistence"]persistenceThreshold.ThresholdMethod="Between"persistenceThreshold.LowerThreshold=8.5persistenceThreshold.UpperThreshold=999999999# create a new 'TTK TopologicalSimplification'tTKTopologicalSimplification1=TTKTopologicalSimplification(Domain=calculator1,Constraints=persistenceThreshold)tTKTopologicalSimplification1.ScalarField=["POINTS","originalData"]# create a new 'Calculator'calculator7=Calculator(Input=tTKTopologicalSimplification1)calculator7.ResultArrayName="originalData"calculator7.Function="-originalData"# create a new 'Calculator'calculator8=Calculator(Input=calculator7)calculator8.ResultArrayName="originalData_Order"calculator8.Function="-originalData_Order"# create a new 'TTK MorseSmaleComplex'tTKMorseSmaleComplex2=TTKMorseSmaleComplex(Input=calculator8)tTKMorseSmaleComplex2.ScalarField=["POINTS","originalData_Order"]# create a new 'TTK IdentifierRandomizer'tTKIdentifierRandomizer2=TTKIdentifierRandomizer(Input=OutputPort(tTKMorseSmaleComplex2,3))tTKIdentifierRandomizer2.ScalarField=["POINTS","AscendingManifold"]# save the outputSaveData("tribute_segmentation.vti",tTKIdentifierRandomizer2)
To run the above Python script, go to your ttk-data directory and enter the following command: