Révision 10
bin/image2geometry/MGX_CurvatureMapSegmentation.py (revision 10) | ||
---|---|---|
12 | 12 |
|
13 | 13 |
# directory with detected sepal contours |
14 | 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 | 15 |
|
17 | 16 |
|
18 | 17 |
################### Parameters ########### |
bin/image2geometry/orient_sepals.sh (revision 10) | ||
---|---|---|
8 | 8 |
|
9 | 9 |
indir=$1 |
10 | 10 |
filetype=$2 |
11 |
imagetype=$3 |
|
11 | 12 |
|
12 | 13 |
outdir=$indir'_oriented-sepals' |
13 | 14 |
|
... | ... | |
26 | 27 |
echo $file >> $logfile |
27 | 28 |
echo $file $outdir |
28 | 29 |
echo '--------------------------' >> $logfile |
29 |
orient_sepal.py $file $outdir |
|
30 |
if test $imagetype=="grey" |
|
31 |
then |
|
32 |
echo 'orienting grey image '$file |
|
33 |
orient_sepal.py $file $outdir $imagetype |
|
34 |
else |
|
35 |
echo 'orienting segmented image '$file |
|
36 |
orient_sepal.py $file $outdir |
|
37 |
fi |
|
30 | 38 |
echo '--------------------------' >> $logfile |
31 | 39 |
done |
32 | 40 |
|
bin/image2geometry/bib_sepals.py (revision 10) | ||
---|---|---|
456 | 456 |
plt.gca().imshow(np.transpose(matrix), interpolation='none') |
457 | 457 |
fig.savefig(filename) |
458 | 458 |
return |
459 |
|
|
460 |
|
|
461 |
|
|
462 |
def register_objects(img_flo, img_ref, preregisterd=True, ph=6, pl=2, es=5, fs=3, save_files=True, iterations=2): |
|
463 |
# -- "Specify paths to image files" -- |
|
464 |
# ------------------------------------------------ |
|
465 |
sequence_name = "register_" |
|
466 |
file_times = [1, 2] |
|
467 |
filenames = [sequence_name + str(t).zfill(2) for t in file_times] |
|
468 |
list_images = [img_flo, img_ref] |
|
469 |
|
|
470 |
images = {} |
|
471 |
for i in [0,1]: |
|
472 |
images[filenames[i]] = list_images[i] |
|
473 |
|
|
474 |
rigid_images = {} |
|
475 |
rigid_transformations = {} |
|
476 |
affine_images = {} |
|
477 |
affine_transformations = {} |
|
478 |
registered_images = {} |
|
479 |
non_linear_transformations = {} |
|
480 |
[reference_filename, floating_filename, reference_time, floating_time] = [ filenames[0], filenames[1], file_times[0], file_times[1]] |
|
481 |
#for reference_filename, floating_filename, reference_time, floating_time, in zip(filenames[1:],filenames[:-1],file_times[1:],file_times[:-1]): |
|
482 |
print("================================") |
|
483 |
print("Registering ", floating_time, " on ", reference_time) |
|
484 |
print("================================") |
|
485 |
|
|
486 |
################################################### |
|
487 |
# Output structure |
|
488 |
################################################### |
|
489 |
|
|
490 |
namestring = "_ph"+str(ph)+"_pl"+str(pl)+"_es"+str(es)+"_fs"+str(fs) |
|
491 |
|
|
492 |
output_dirname = dirname + '/' + sequence_name + "_" + str(floating_time).zfill(2) + "_on_" + str(reference_time).zfill(2) + "" + namestring |
|
493 |
if not os.path.exists(output_dirname): |
|
494 |
os.makedirs(output_dirname) |
|
495 |
|
|
496 |
reference_img = images[reference_filename] |
|
497 |
floating_img = images[floating_filename] |
|
498 |
|
|
499 |
#################################################################### |
|
500 |
|
|
501 |
# Registration of the floating images on ref |
|
502 |
# ----------------------------------------------------- |
|
503 |
|
|
504 |
if (not preregistered) : |
|
505 |
# A. Find optimised rigid transformations |
|
506 |
rigid_img, rigid_trsf = find_rigid_transfo2(reference_img, floating_img) |
|
507 |
rigid_images[floating_filename] = rigid_img |
|
508 |
rigid_transformations[floating_filename] = rigid_trsf |
|
509 |
|
|
510 |
if save_files: |
|
511 |
# rigid-registered images |
|
512 |
rigid_filename = output_dirname + '/' + floating_filename + "_rigid_on_" + str(reference_time).zfill(2) + ".inr.gz" |
|
513 |
imsave(rigid_filename, rigid_img) |
|
514 |
|
|
515 |
# optimised (with block-matching) rigid transformations |
|
516 |
rigid_trsf_filename = output_dirname + '/tr_' + floating_filename + '_rigid.txt' |
|
517 |
tfsave(rigid_trsf_filename, rigid_trsf) |
|
518 |
|
|
519 |
# B. Find optimised affine transformations (initialised by the rigid tfs computed above) |
|
520 |
affine_img, affine_trsf = find_affine_transfo(reference_img, floating_img, init_trsf=rigid_trsf) |
|
521 |
affine_images[floating_filename] = affine_img |
|
522 |
affine_transformations[floating_filename] = affine_trsf |
|
523 |
|
|
524 |
if save_files: |
|
525 |
# affine-registered images |
|
526 |
affine_filename = output_dirname + '/' + floating_filename + "_affine_on_" + str(reference_time).zfill(2) + ".inr.gz" |
|
527 |
imsave(affine_filename, affine_img) |
|
528 |
|
|
529 |
# optimised (with block-matching) affine transformations |
|
530 |
affine_trsf_filename = output_dirname + '/tr_' + floating_filename + '_affine.txt' |
|
531 |
tfsave(affine_filename, affine_trsf) |
|
532 |
floating_img0=affine_img |
|
533 |
else : |
|
534 |
floating_img0=floating_img |
|
535 |
# C. Find nonlinear transformations which register the affine-transformed images |
|
536 |
#registered_img, nl_trsf = find_nl_transfo(reference_img, affine_img, ph=ph, pl=pl, es=es, fs=fs) |
|
537 |
for it in range(iterations): |
|
538 |
registered_img, nl_trsf = find_nl_transfo(reference_img, floating_img0, ph=ph, pl=pl, es=es, fs=fs) |
|
539 |
registered_images[floating_filename] = registered_img |
|
540 |
non_linear_transformations[floating_filename] = nl_trsf |
|
541 |
|
|
542 |
# paths to nonlinearly registered images |
|
543 |
registered_filename = output_dirname + '/' + floating_filename + "_registered_on_" + str(reference_time).zfill(2) + "_it"+str(it)+".inr.gz" |
|
544 |
imsave(registered_filename, registered_img) |
|
545 |
floating_img0=registered_img |
|
546 |
|
|
547 |
if save_files: |
|
548 |
# non-linear transformations |
|
549 |
nl_trsf_filename = output_dirname + '/' + floating_filename + "_it"+str(it)+"_vectorfield.inr.gz" |
|
550 |
save_trsf(nl_trsf, nl_trsf_filename, compress=True) |
|
551 |
return registered_img |
|
552 |
|
bin/image2geometry/gather_data.py (revision 10) | ||
---|---|---|
1 |
#!/usr/bin/env python |
|
2 |
|
|
3 |
# before lounching the executable activate the timagetk conda environement |
|
4 |
# conda activate florivar |
|
5 |
|
|
6 |
# general imports : |
|
7 |
from sys import argv |
|
8 |
import pandas as pd |
|
9 |
import os |
|
10 |
|
|
11 |
|
|
12 |
def read_areas(dirname): |
|
13 |
listfiles=os.listdir(dirname) |
|
14 |
listfiles=[i for i in listfiles if '-area.csv' in i] |
|
15 |
sepalname=[] |
|
16 |
area=[] |
|
17 |
for i in listfiles: |
|
18 |
name=i.split('-area.csv')[0] |
|
19 |
sepalname.append(name) |
|
20 |
df=pd.read_csv(dirname+i, delimiter=',')[:-2] |
|
21 |
A=max(df['Value']) |
|
22 |
area.append(A) |
|
23 |
data = {'Sepal': sepalname, 'Area': area} |
|
24 |
newdf=pd.DataFrame.from_dict(data) |
|
25 |
newdf=newdf.sort_values("Sepal", ascending=True, inplace=False) |
|
26 |
return newdf |
|
27 |
|
|
28 |
def read_measurements(fname): |
|
29 |
df=pd.read_csv(fname, delimiter=';') |
|
30 |
print("Reading file : ",fname) |
|
31 |
print("Number of entries at reading: ",df.shape) |
|
32 |
df['Sepal']=[name.split('_oriented')[0] for name in df['Sepal']] |
|
33 |
df=df.sort_values("Sepal", ascending=True, inplace=False) |
|
34 |
return df |
|
35 |
|
|
36 |
|
|
37 |
measures_filename = argv[1] |
|
38 |
areadir = argv[2]+'/' |
|
39 |
|
|
40 |
root=measures_filename.split('.csv')[0] |
|
41 |
outputfile=root+"_full.csv" |
|
42 |
|
|
43 |
|
|
44 |
df=read_measurements(measures_filename) |
|
45 |
newdf=read_areas(areadir) |
|
46 |
# |
|
47 |
df = pd.merge(df, newdf, left_on="Sepal", right_on="Sepal") |
|
48 |
# |
|
49 |
df['CurvedSF']=df['CurvedWidth']/df['CurvedLength'] |
|
50 |
df['FlatSF']=df['FlatWidth']/df['FlatLength'] |
|
51 |
# |
|
52 |
df['Thickness']=df['volume']/df['Area'] |
|
53 |
# |
|
54 |
df['GaussK']=1./df['LR']/df['TR'] |
|
55 |
df['CentralGaussK']=1./df['LR423']/df['TR423'] |
|
56 |
df.to_csv(outputfile, index=False, sep=";") |
|
57 |
print("Number of entries : ",df.shape) |
|
58 |
labels=list(df.columns[1:]) |
|
59 |
print('Columns written:',list(df.columns)) |
|
60 |
print('Sepals:',list(df['Sepal'])) |
|
61 |
print('Measurements written in file:',outputfile) |
|
62 |
|
|
63 |
|
bin/image2geometry/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 |
|
bin/image2geometry/measure_sepal.py (revision 10) | ||
---|---|---|
38 | 38 |
outputdir=outdir+"/sections/" |
39 | 39 |
projectiondir=outdir+"/projections" |
40 | 40 |
|
41 |
|
|
41 | 42 |
print(argv) |
42 | 43 |
|
43 | 44 |
imname = filename.split('/')[-1] |
... | ... | |
47 | 48 |
#projected2Dimage_hight=outdir+"/hight_"+imnameroot+"2D.png" |
48 | 49 |
|
49 | 50 |
os.system("mkdir -p "+outputdir) |
51 |
os.system("mkdir -p "+symdir) |
|
50 | 52 |
|
51 | 53 |
outname = outputfile.split('/')[-1] |
52 | 54 |
outroot = outname.split('.')[0] |
... | ... | |
58 | 60 |
voxelsize = sepale.voxelsize |
59 | 61 |
print("voxelsize=",voxelsize) |
60 | 62 |
s = sepale.shape |
63 |
imtype=sepale.dtype |
|
61 | 64 |
print("shape=",s) |
62 | 65 |
|
63 | 66 |
print("Computing the volume and volumic asymmetry...") |
... | ... | |
79 | 82 |
|
80 | 83 |
vol=vol*voxelsize[0]*voxelsize[1]*voxelsize[2] |
81 | 84 |
|
85 |
|
|
86 |
|
|
82 | 87 |
print("Projecting on 2D...") |
83 | 88 |
|
84 | 89 |
def project2D(im3): |
Formats disponibles : Unified diff