Statistiques
| Révision :

root / bin / image2geometry / curvature_map_segmentation.py @ 6

Historique | Voir | Annoter | Télécharger (3,49 ko)

1
import os
2

    
3
'''
4
Input:
5
 - directory with detected sepal contour stacks .tif
6
 
7
Output:
8
 - segmented meshes (up and down surfaces treated as cells)
9
 - csv file / sepale containing : up and down surface areas
10

11
'''
12

    
13
# directory with detected sepal contours
14
filedata1="/home/akiss/RDP/Projects/Sepals/RNA-Seq_Final/06.ContourDetection/JL_22C/mgx-contours"
15
filedata1="/home/akiss/RDP/Projects/Sepals/RNA-Seq_Final/06.ContourDetection/test"
16

    
17

    
18
################### Parameters ###########
19

    
20
# cubesize for mesh creation
21
cubesize=str(15)
22

    
23
# size of neighbourhood for the segmented curvature map
24
curv_neighb=str(100)
25

    
26
# segmentation
27
signal_ratio=str(3) # minimal border / cell signal ratio (if less, cells are fused)
28
# - cell
29
cell_blur_radius=str(100)
30
seed_radius=str(150)
31
# - border
32
border_distance=str(100)
33
border_blur_radius=str(100)
34

    
35
#########################################
36

    
37
filedata=filedata1+'/'
38
meshresult=filedata1+'-MGX-mesh'+cubesize+'/'
39
curvaturecsvresult=filedata1+'-MGX-curvature-csv/'
40
arearesult=filedata1+'-MGX-area/'
41
segresult=filedata1+'-MGX-seg/'
42

    
43

    
44
os.system("mkdir "+meshresult)
45
os.system("mkdir "+curvaturecsvresult)
46
os.system("mkdir "+arearesult)
47
os.system("mkdir "+segresult)
48

    
49

    
50
listfiles=os.listdir(filedata)
51
listfiles=[ i for i in listfiles if '.tif' in i]
52

    
53

    
54
Process.Stack__System__Clear_Work_Stack('0')
55
Process.Stack__System__Clear_Main_Stack('0')
56
Process.Stack__System__Clear_Main_Stack('1')
57
Process.Stack__System__Clear_Work_Stack('1')
58
for i in listfiles:        
59
        Process.Stack__System__Set_Current_Stack('Main', '0')
60
        Process.Stack__System__Open(filedata+i, 'Main', '0')
61
        # --- creating surface mesh
62
        Process.Mesh__Creation__Marching_Cubes_Surface(cubesize, '5000')
63
        Process.Mesh__Structure__Smooth_Mesh('1', 'No')
64
        Process.Mesh__Structure__Smooth_Mesh('1', 'No')
65
        Process.Mesh__Structure__Smooth_Mesh('1', 'No')
66
        Process.Mesh__Structure__Smooth_Mesh('1', 'No')
67
        # --- computing maximal curvature
68
        csvname=i[:-4]+'-carte-courbure-Maximal'+curv_neighb+'.csv'
69
        Process.Mesh__Signal__Project_Mesh_Curvature(curvaturecsvresult+csvname, 'Maximal', curv_neighb, 'Yes', '-50.0', '50.0', '85')
70
        meshname=i[:-4]+'-mesh.mgxm'
71
        Process.Mesh__System__Save(meshresult+meshname, 'no', '0')
72
        Process.Stack__System__Clear_Work_Stack('0')
73
        Process.Stack__System__Clear_Main_Stack('0')
74
        Process.Stack__System__Clear_Main_Stack('1')
75
        Process.Stack__System__Clear_Work_Stack('1')
76
        # --- watershed segmentation of the maximal curvature map
77
        Process.Mesh__Segmentation__Auto_Segmentation('Yes', 'No', cell_blur_radius, seed_radius, border_blur_radius, '100.0', border_distance, signal_ratio)
78
        segname=i[:-4]+'-seg.mgxm'
79
        Process.Mesh__System__Save(segresult+segname, 'no', '0')
80
        # --- computing the area of the faces
81
        csvname=i[:-4]+'-area.csv'
82
        Process.Mesh__Heat_Map__Heat_Map_Classic('Area', 'Geometry', arearesult+csvname, 'Geometry', 'No', '0', '65535', 'Yes', 'No', 'None', 'No', 'Decreasing', 'Ratio', '0.001', '1')
83
        # --- computing teh perimeter
84
        #csvname=i[:-4]+'-perimeter.csv'
85
        #Process.Mesh__Heat_Map__Heat_Map('/Geometry/Perimeter', 'No', 'No', '', 'No', '', '', 'Yes', 'Yes')
86
        # --- computing gaussian curvature
87
        #Process.Mesh__Signal__Project_Mesh_Curvature('', 'Gaussian', '100', 'Yes', '-50.0', '50.0', '85')
88
        """print("Please put two seeds on the two sides of the sepal :-) ... ")
89
        a=input("")
90
        Process.Mesh__Segmentation__Watershed_Segmentation('50000')
91
        csvname=i[:-4]+'-area.csv'
92
        Process.Mesh__Heat_Map__Heat_Map_Classic('Area', 'Geometry', csvresult+csvname, 'Geometry', 'No', '0', '65535', 'Yes', 'No', 'None', 'No', 'Decreasing', 'Ratio', '0.001', '1')
93
        """