Révision 10 bin/image2geometry/orient_sepal.py

orient_sepal.py (revision 10)
20 20
from scipy.ndimage.morphology import binary_closing, binary_opening
21 21

  
22 22
from titk_tools.io import imread, imsave, tfread, SpatialImage
23
from titk_tools.registration import isotropic_resampling_seg
24
from titk_tools.registration import apply_transfo_on_seg1
23
from titk_tools.registration import isotropic_resampling_seg, isotropic_resampling
24
from titk_tools.registration import apply_transfo_on_seg1, apply_transfo_on_image
25 25

  
26 26
from bib_sepals import *
27 27

  
......
30 30
filename = argv[1]
31 31
outputdir=argv[2]+'/'
32 32

  
33
segmented=True
34

  
35
if len(argv)>3:
36
	imagetype=argv[3]
37
	if imagetype=='grey':
38
		segmented=False
39

  
33 40
print(argv)
41
print('segmented=',segmented)
34 42

  
35 43
imname = filename.split('/')[-1]
36 44
imnameroot = imname.split('.')[0]
......
38 46
outfilename = outputdir+imnameroot+'_oriented.inr.gz'
39 47

  
40 48
# read the image
41
sepale=imread(filename)
49
img=imread(filename)
42 50
# resample isotropically
43 51
print("----------------------")
44 52
print("isotropic resampling of : filename=", filename)
45 53
print("----------------------")
46
voxelsize = sepale.voxelsize
54
voxelsize = img.voxelsize
47 55
print("voxelsize=",voxelsize)
48
s = sepale.shape
56
s = img.shape
57
imgtype=img.dtype
49 58
print("shape=",s)
50 59

  
51 60
radius=int(voxelsize[2]/voxelsize[0])
......
53 62
#isovs=voxelsize[0]
54 63
print("new voxelsize=",isovs)
55 64

  
56
sepale=SpatialImage(sepale>0, dtype='uint8', voxelsize=voxelsize, origin=[0, 0, 0])
57
sepale=isotropic_resampling_seg(sepale,isovs)
65
sepale=SpatialImage(img>0, dtype='uint8', voxelsize=voxelsize, origin=[0, 0, 0])
66
if segmented:
67
	sepale=isotropic_resampling_seg(sepale,isovs)
68
else:
69
	img=isotropic_resampling(img,isovs)
70
	sepale=isotropic_resampling_seg(sepale,isovs)
58 71

  
59 72
s = sepale.shape
60 73
voxelsize = sepale.voxelsize
......
68 81
s_addy=int((np.sqrt(s[0]*s[1]*2)-np.sqrt(s[0]*s[1]))/2)
69 82
s_addz=int(s[2]*0.20)
70 83
sepale=add_side_slices(sepale, 0, 0, s_addy, s_addy, s_addz, s_addz)
84
if not segmented :
85
	img=add_side_slices(img, 0, 0, s_addy, s_addy, s_addz, s_addz)
71 86

  
72 87
'''
73 88
# smooth it with opening
......
83 98
'''
84 99

  
85 100
# put the center of mass in the center of the image
86
sepale_centered=center_on_cm(sepale, volumic=False)
101
sepale_centered=center_on_cm(sepale, volumic=True)
102
if not segmented:
103
	img=center_on_cm(img, volumic=True)
87 104

  
88 105
# compute principal directions
89
pv_flo=principal_directions(sepale_centered, volumic=False)
106
pv_flo=principal_directions(sepale_centered, volumic=True)
90 107
print(pv_flo)
91 108

  
92 109
# sepals originally are oriented with top in more-or less "up" direction on the images
......
120 137
os.system("rm "+trsf_file)
121 138

  
122 139
# apply transformation
123
oriented=apply_transfo_on_seg1(trsf, sepale_centered)
140
if segmented :
141
	oriented=apply_transfo_on_seg1(trsf, sepale_centered)
142
else :
143
	oriented=apply_transfo_on_image(trsf, img)
124 144

  
125 145
# smooth the transformed image
126 146
#sepale = binary_closing(oriented, structure=struct_el, iterations=radius)
127 147

  
128 148
# and save the oriented sepal
129 149
sepale_filename = outputdir+imnameroot+'_oriented.inr.gz'
130
sepale=SpatialImage(oriented*255, dtype='uint8', voxelsize=voxelsize, origin=[0, 0, 0])
150
if segmented :
151
	sepale=SpatialImage(oriented*255, dtype='uint8', voxelsize=voxelsize, origin=[0, 0, 0])
152
else:
153
	sepale=SpatialImage(oriented, dtype=imgtype, voxelsize=voxelsize, origin=[0, 0, 0])
154

  
131 155
imsave(sepale_filename, sepale)
132 156

  

Formats disponibles : Unified diff