root / bin / image2geometry / MGX_CurvatureMapSegmentation.py @ 14
Historique | Voir | Annoter | Télécharger (3,41 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 |
|
16 |
|
17 |
################### Parameters ###########
|
18 |
|
19 |
# cubesize for mesh creation
|
20 |
cubesize=str(15) |
21 |
|
22 |
# size of neighbourhood for the segmented curvature map
|
23 |
curv_neighb=str(100) |
24 |
|
25 |
# segmentation
|
26 |
signal_ratio=str(3) # minimal border / cell signal ratio (if less, cells are fused) |
27 |
# - cell
|
28 |
cell_blur_radius=str(100) |
29 |
seed_radius=str(150) |
30 |
# - border
|
31 |
border_distance=str(100) |
32 |
border_blur_radius=str(100) |
33 |
|
34 |
#########################################
|
35 |
|
36 |
filedata=filedata1+'/'
|
37 |
meshresult=filedata1+'-MGX-mesh'+cubesize+'/' |
38 |
curvaturecsvresult=filedata1+'-MGX-curvature-csv/'
|
39 |
arearesult=filedata1+'-MGX-area/'
|
40 |
segresult=filedata1+'-MGX-seg/'
|
41 |
|
42 |
|
43 |
os.system("mkdir "+meshresult)
|
44 |
os.system("mkdir "+curvaturecsvresult)
|
45 |
os.system("mkdir "+arearesult)
|
46 |
os.system("mkdir "+segresult)
|
47 |
|
48 |
|
49 |
listfiles=os.listdir(filedata) |
50 |
listfiles=[ i for i in listfiles if '.tif' in i] |
51 |
|
52 |
|
53 |
Process.Stack__System__Clear_Work_Stack('0')
|
54 |
Process.Stack__System__Clear_Main_Stack('0')
|
55 |
Process.Stack__System__Clear_Main_Stack('1')
|
56 |
Process.Stack__System__Clear_Work_Stack('1')
|
57 |
for i in listfiles: |
58 |
Process.Stack__System__Set_Current_Stack('Main', '0') |
59 |
Process.Stack__System__Open(filedata+i, 'Main', '0') |
60 |
# --- creating surface mesh
|
61 |
Process.Mesh__Creation__Marching_Cubes_Surface(cubesize, '5000')
|
62 |
Process.Mesh__Structure__Smooth_Mesh('1', 'No') |
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 |
# --- computing maximal curvature
|
67 |
csvname=i[:-4]+'-carte-courbure-Maximal'+curv_neighb+'.csv' |
68 |
Process.Mesh__Signal__Project_Mesh_Curvature(curvaturecsvresult+csvname, 'Maximal', curv_neighb, 'Yes', '-50.0', '50.0', '85') |
69 |
meshname=i[:-4]+'-mesh.mgxm' |
70 |
Process.Mesh__System__Save(meshresult+meshname, 'no', '0') |
71 |
Process.Stack__System__Clear_Work_Stack('0')
|
72 |
Process.Stack__System__Clear_Main_Stack('0')
|
73 |
Process.Stack__System__Clear_Main_Stack('1')
|
74 |
Process.Stack__System__Clear_Work_Stack('1')
|
75 |
# --- watershed segmentation of the maximal curvature map
|
76 |
Process.Mesh__Segmentation__Auto_Segmentation('Yes', 'No', cell_blur_radius, seed_radius, border_blur_radius, '100.0', border_distance, signal_ratio) |
77 |
segname=i[:-4]+'-seg.mgxm' |
78 |
Process.Mesh__System__Save(segresult+segname, 'no', '0') |
79 |
# --- computing the area of the faces
|
80 |
csvname=i[:-4]+'-area.csv' |
81 |
Process.Mesh__Heat_Map__Heat_Map_Classic('Area', 'Geometry', arearesult+csvname, 'Geometry', 'No', '0', '65535', 'Yes', 'No', 'None', 'No', 'Decreasing', 'Ratio', '0.001', '1') |
82 |
# --- computing teh perimeter
|
83 |
#csvname=i[:-4]+'-perimeter.csv'
|
84 |
#Process.Mesh__Heat_Map__Heat_Map('/Geometry/Perimeter', 'No', 'No', '', 'No', '', '', 'Yes', 'Yes')
|
85 |
# --- computing gaussian curvature
|
86 |
#Process.Mesh__Signal__Project_Mesh_Curvature('', 'Gaussian', '100', 'Yes', '-50.0', '50.0', '85')
|
87 |
"""print("Please put two seeds on the two sides of the sepal :-) ... ")
|
88 |
a=input("")
|
89 |
Process.Mesh__Segmentation__Watershed_Segmentation('50000')
|
90 |
csvname=i[:-4]+'-area.csv'
|
91 |
Process.Mesh__Heat_Map__Heat_Map_Classic('Area', 'Geometry', csvresult+csvname, 'Geometry', 'No', '0', '65535', 'Yes', 'No', 'None', 'No', 'Decreasing', 'Ratio', '0.001', '1')
|
92 |
"""
|