# Amira-Script-Object V3.0 # NO DEPRECATION WARNING # Constructor is called when scro is instantiated $this proc constructor {} { # Threshold port "$this" newPortRangeSlider threshold "$this" threshold setLabel "Threshold" "$this" threshold setTooltip "Threshold defining the background used for segmentation" "$this" threshold setValues 0 255 # Number of objects port "$this" newPortIntSlider numberOfObjects "$this" numberOfObjects setLabel "Number of Objects" "$this" numberOfObjects setTooltip "Defines the Number of Objects that have the biggest volume" "$this" numberOfObjects setMinMax 0 100 "$this" numberOfObjects setValue 1 # Port to hide intermediate objects "$this" newPortToggleList hideObjectOption 1 "$this" hideObjectOption setLabel "Object Visibility" "$this" hideObjectOption setLabel 0 "Hide Intermediate Objects" "$this" hideObjectOption setValue 0 1 # Action button "$this" newPortButtonList action 1 "$this" action setLabel 0 "Apply" "$this" action setCmd 0 {$this computeDoIt} # List of all the objects created by "$this" "$this" setVar objectInstances {} } # Destructor is called when scro is removed $this proc destructor {} { "$this" deleteObjects } # Remove created objects $this proc deleteObjects {} { # Clean up foreach obj ["$this" getVar objectInstances] { remove "$obj" } "$this" setVar objectInstances {} } # Append new object $this proc appendObject {myObject} { "$this" setVar objectInstances [concat ["$this" getVar objectInstances] "\{$myObject\}"] } # Processing... $this proc computeDoIt {} { # Viewer should clean during processing viewer redraw # Check if input data is defined set data [$this data source] if {$data == ""} {return} # Clean up before creating anything "$this" deleteObjects # List of all the objects created by "$this" "$this" setVar baseIconPositionX [expr "[lindex [$this getIconPosition] 0] + 30"] "$this" setVar baseIconPositionY [expr "[lindex [$this getIconPosition] 1] + 50"] # Thresholding to detect the pores set InteractiveThresholdingObj [create HxInteractiveThreshold] "$InteractiveThresholdingObj" setIconPosition [expr ["$this" getVar baseIconPositionX] + 0] [expr ["$this" getVar baseIconPositionY] + 0] "$InteractiveThresholdingObj" fire "$InteractiveThresholdingObj" setViewerMask 0 # --> Interconnect source "$InteractiveThresholdingObj" data connect [$this data source] "$InteractiveThresholdingObj" fire # --> Interconnect threshold "$InteractiveThresholdingObj" threshold connect "$this" threshold "$InteractiveThresholdingObj" fire "$InteractiveThresholdingObj" doIt snap 0 1 "$InteractiveThresholdingObj" fire "$InteractiveThresholdingObj" setViewerMask 65534 ["$InteractiveThresholdingObj" getResult] setIconPosition [expr ["$this" getVar baseIconPositionX] - 260 + 88] [expr ["$this" getVar baseIconPositionY] + 20] ["$InteractiveThresholdingObj" getResult] fire "$this" appendObject "$InteractiveThresholdingObj" "$this" appendObject ["$InteractiveThresholdingObj" getResult] if { ["$this" hideObjectOption getValue 0] == 1} { "$InteractiveThresholdingObj" fire "$InteractiveThresholdingObj" hideIcon } # Create distance map set ChamferDistanceMapObj [create distxxx] "$ChamferDistanceMapObj" setIconPosition [expr ["$this" getVar baseIconPositionX] + 0] [expr ["$this" getVar baseIconPositionY] + 20] "$ChamferDistanceMapObj" fire "$ChamferDistanceMapObj" doIt snap 0 1 "$ChamferDistanceMapObj" inputImage connect ["$InteractiveThresholdingObj" getResult] "$ChamferDistanceMapObj" faceDistance setValue 0 1 "$ChamferDistanceMapObj" edgeDistance setValue 0 1.414 "$ChamferDistanceMapObj" cornerDistance setValue 0 1.73 "$ChamferDistanceMapObj" fire ["$ChamferDistanceMapObj" getResult] setIconPosition [expr ["$this" getVar baseIconPositionX] - 260 + 18] [expr ["$this" getVar baseIconPositionY] + 40] ["$ChamferDistanceMapObj" getResult] fire "$this" appendObject "$ChamferDistanceMapObj" "$this" appendObject ["$ChamferDistanceMapObj" getResult] if { ["$this" hideObjectOption getValue 0] == 1} { "$ChamferDistanceMapObj" hideIcon } # Get all the local maxima set HMaximaObj [create merge_maxima] "$HMaximaObj" setIconPosition [expr ["$this" getVar baseIconPositionX] + 0] [expr ["$this" getVar baseIconPositionY] + 40] "$HMaximaObj" fire "$HMaximaObj" inputImage connect ["$ChamferDistanceMapObj" getResult] "$HMaximaObj" doIt snap 0 1 "$HMaximaObj" fire ["$HMaximaObj" getResult] setIconPosition [expr ["$this" getVar baseIconPositionX] - 260 + 98] [expr ["$this" getVar baseIconPositionY] + 60] ["$HMaximaObj" getResult] fire "$this" appendObject "$HMaximaObj" "$this" appendObject ["$HMaximaObj" getResult] if { ["$this" hideObjectOption getValue 0] == 1} { "$HMaximaObj" hideIcon } # Make a label per local maxima set LabelingObj [create label] "$LabelingObj" setIconPosition [expr ["$this" getVar baseIconPositionX] + 0] [expr ["$this" getVar baseIconPositionY] + 60] "$LabelingObj" fire "$LabelingObj" doIt snap 0 1 "$LabelingObj" inputImage connect ["$HMaximaObj" getResult] "$LabelingObj" fire ["$LabelingObj" getResult] setIconPosition [expr ["$this" getVar baseIconPositionX] - 260 + 106] [expr ["$this" getVar baseIconPositionY] + 80] ["$LabelingObj" getResult] fire "$this" appendObject "$LabelingObj" "$this" appendObject ["$LabelingObj" getResult] if { ["$this" hideObjectOption getValue 0] == 1} { "$LabelingObj" hideIcon ["$HMaximaObj" getResult] hideIcon } # Get the inverse of the distance map set NotObj [create logical_not] "$NotObj" setIconPosition [expr ["$this" getVar baseIconPositionX] + 0] [expr ["$this" getVar baseIconPositionY] + 80] "$NotObj" fire "$NotObj" doIt snap 0 1 "$NotObj" inputImage connect ["$ChamferDistanceMapObj" getResult] "$NotObj" applyTransformToResult 1 "$NotObj" fire ["$NotObj" getResult] setIconPosition [expr ["$this" getVar baseIconPositionX] - 260 + 124] [expr ["$this" getVar baseIconPositionY] + 100] ["$NotObj" getResult] fire "$this" appendObject "$NotObj" "$this" appendObject ["$NotObj" getResult] if { ["$this" hideObjectOption getValue 0] == 1} { "$NotObj" hideIcon } # Apply the watershed algorithm using the inverse of the distance map and a set of local maxima labels set MarkerBasedWatershedObj [create fastwatershed] "$MarkerBasedWatershedObj" setIconPosition [expr ["$this" getVar baseIconPositionX] + 0] [expr ["$this" getVar baseIconPositionY] + 100] "$MarkerBasedWatershedObj" fire "$MarkerBasedWatershedObj" doIt snap 0 1 "$MarkerBasedWatershedObj" inputGrayscaleImage connect ["$NotObj" getResult] "$MarkerBasedWatershedObj" inputLabelImage connect ["$LabelingObj" getResult] "$MarkerBasedWatershedObj" fire ["$MarkerBasedWatershedObj" getResult] setIconPosition [expr ["$this" getVar baseIconPositionX] - 260 + 92] [expr ["$this" getVar baseIconPositionY] + 120] ["$MarkerBasedWatershedObj" getResult] fire "$this" appendObject "$MarkerBasedWatershedObj" "$this" appendObject ["$MarkerBasedWatershedObj" getResult] if { ["$this" hideObjectOption getValue 0] == 1} { "$MarkerBasedWatershedObj" hideIcon ["$LabelingObj" getResult] hideIcon ["$NotObj" getResult] hideIcon } # Compose the pores thresholding with the watershed result set AndNotImageObj [create logical_subimage] "$AndNotImageObj" setIconPosition [expr ["$this" getVar baseIconPositionX] + 0] [expr ["$this" getVar baseIconPositionY] + 120] "$AndNotImageObj" fire "$AndNotImageObj" doIt snap 0 1 "$AndNotImageObj" inputImage1 connect ["$InteractiveThresholdingObj" getResult] "$AndNotImageObj" inputImage2 connect ["$MarkerBasedWatershedObj" getResult] "$AndNotImageObj" fire ["$AndNotImageObj" getResult] setIconPosition [expr ["$this" getVar baseIconPositionX] - 260 + 66] [expr ["$this" getVar baseIconPositionY] + 140] ["$AndNotImageObj" getResult] fire "$this" appendObject "$AndNotImageObj" "$this" appendObject ["$AndNotImageObj" getResult] if { ["$this" hideObjectOption getValue 0] == 1} { "$AndNotImageObj" hideIcon ["$InteractiveThresholdingObj" getResult] hideIcon ["$MarkerBasedWatershedObj" getResult] hideIcon } # Get individual labels from the composition of the pores thresholding and the watershed result set LabelingObj2 [create label] "$LabelingObj2" setIconPosition [expr ["$this" getVar baseIconPositionX] + 0] [expr ["$this" getVar baseIconPositionY] + 140] "$LabelingObj2" fire "$LabelingObj2" interpretation setValue 0 "$LabelingObj2" outputLocation setIndex 0 0 "$LabelingObj2" neighborhood setValue 2 "$LabelingObj2" doIt snap 0 1 "$LabelingObj2" inputImage connect ["$AndNotImageObj" getResult] "$LabelingObj2" applyTransformToResult 1 "$LabelingObj2" fire ["$LabelingObj2" getResult] setIconPosition [expr ["$this" getVar baseIconPositionX] - 260 + 96] [expr ["$this" getVar baseIconPositionY] + 160] ["$LabelingObj2" getResult] fire "$this" appendObject "$LabelingObj2" "$this" appendObject ["$LabelingObj2" getResult] if { ["$this" hideObjectOption getValue 0] == 1} { "$LabelingObj2" hideIcon ["$AndNotImageObj" getResult] hideIcon } # Filter the previous labels according to their volume (keep the biggest ones only) set FilterByMeasure [create measurefilter] "$FilterByMeasure" setIconPosition [expr ["$this" getVar baseIconPositionX] + 0] [expr ["$this" getVar baseIconPositionY] + 160] "$FilterByMeasure" fire # --> Interconnect threshold "$FilterByMeasure" numberOfPatterns connect "$this" numberOfObjects "$FilterByMeasure" fire "$FilterByMeasure" doIt snap 0 1 "$FilterByMeasure" inputImage connect ["$LabelingObj2" getResult] "$FilterByMeasure" inputIntensityImage connect ["$ChamferDistanceMapObj" getResult] "$FilterByMeasure" measure setValue Volume "$FilterByMeasure" fire ["$FilterByMeasure" getResult] setIconPosition [expr ["$this" getVar baseIconPositionX] - 260 + 60] [expr ["$this" getVar baseIconPositionY] + 180] ["$FilterByMeasure" getResult] fire "$this" appendObject "$FilterByMeasure" "$this" appendObject ["$FilterByMeasure" getResult] if { ["$this" hideObjectOption getValue 0] == 1} { "$FilterByMeasure" hideIcon ["$ChamferDistanceMapObj" getResult] hideIcon ["$LabelingObj2" getResult] hideIcon } # Create surfaces from the filtered labels using the previous measure set GenerateSurfaceObj [create HxGMC] "$GenerateSurfaceObj" setIconPosition [expr ["$this" getVar baseIconPositionX] + 0] [expr ["$this" getVar baseIconPositionY] + 180] "$GenerateSurfaceObj" fire "$GenerateSurfaceObj" data connect ["$FilterByMeasure" getResult] "$GenerateSurfaceObj" fire "$GenerateSurfaceObj" border setValue 0 0 "$GenerateSurfaceObj" action snap 0 1 "$GenerateSurfaceObj" fire "$this" appendObject "$GenerateSurfaceObj" "$this" appendObject ["$GenerateSurfaceObj" getResult] if { ["$this" hideObjectOption getValue 0] == 1} { "$GenerateSurfaceObj" hideIcon ["$FilterByMeasure" getResult] hideIcon ["$GenerateSurfaceObj" getResult] setIconPosition [expr ["$this" getVar baseIconPositionX] - 260 + 126] [expr ["$this" getVar baseIconPositionY] + 0] ["$GenerateSurfaceObj" getResult] fire } else { ["$GenerateSurfaceObj" getResult] setIconPosition [expr ["$this" getVar baseIconPositionX] - 260 + 126] [expr ["$this" getVar baseIconPositionY] + 200] ["$GenerateSurfaceObj" getResult] fire } # Display the surfaces set SurfaceView [create HxDisplaySurface] "$SurfaceView" setIconPosition [expr ["$this" getVar baseIconPositionX] + 0] [lindex [["$GenerateSurfaceObj" getResult] getIconPosition] 1] "$SurfaceView" data connect ["$GenerateSurfaceObj" getResult] "$SurfaceView" fire "$SurfaceView" Patch setMinMax 0 120 "$SurfaceView" Patch setSubMinMax 0 120 "$SurfaceView" BoundaryId setIndex 0 -1 "$SurfaceView" materials setIndex 0 1 "$SurfaceView" drawStyle setNormalBinding 1 "$SurfaceView" fire # "$SurfaceView" selectTriangles zab HIJMONNKMNANIDDAAMAGNAEPMKAAIMNEPNLHGBAACEBDNEDDPEFAGIFKPKJOJEKLBFJPPMCDFHABAAAAAAMALOGEOKOPDKFLPANBDJACAAJPNHKKCOONDBPGCMHKAPAAAAAAAAIANLEIDCOFLJPHJNEHPPAFAAAAIAHDOEHBPOFNFBAPLLIMMOALAALOMJFGBNAPOKKGFLFLAAPIGBEHHFHOJENCFPAAAAAADHNGMHJOPGNOMMDEJLJJAAAAAAAAOAIPCFONOFKNMHAKELNHLGII # "$SurfaceView" fire "$SurfaceView" setShadowStyle 0 "$this" appendObject "$SurfaceView" viewer 0 viewAll viewer 0 setAutoRedraw 1 viewer 0 redraw }