Index: bin/image2geometry/bib_sepals.py
===================================================================
--- bin/image2geometry/bib_sepals.py	(revision 9)
+++ bin/image2geometry/bib_sepals.py	(revision 10)
@@ -456,3 +456,97 @@
 	plt.gca().imshow(np.transpose(matrix), interpolation='none')
 	fig.savefig(filename)
 	return
+
+
+
+def register_objects(img_flo, img_ref, preregisterd=True, ph=6, pl=2, es=5, fs=3, save_files=True, iterations=2):
+	# -- "Specify paths to image files" --
+	# ------------------------------------------------
+	sequence_name = "register_"
+	file_times = [1, 2]
+	filenames = [sequence_name + str(t).zfill(2)  for t in file_times]
+	list_images = [img_flo, img_ref]
+
+	images = {}
+	for i in [0,1]:
+		images[filenames[i]] = list_images[i]
+
+	rigid_images = {}
+	rigid_transformations = {}
+	affine_images = {}
+	affine_transformations = {}
+	registered_images = {}
+	non_linear_transformations = {}
+	[reference_filename, floating_filename, reference_time, floating_time] = [ filenames[0], filenames[1], file_times[0], file_times[1]]
+	#for reference_filename, floating_filename, reference_time, floating_time, in zip(filenames[1:],filenames[:-1],file_times[1:],file_times[:-1]):
+	print("================================")
+	print("Registering ", floating_time, " on ", reference_time)
+	print("================================")
+
+	###################################################
+	# Output structure
+	###################################################
+
+	namestring = "_ph"+str(ph)+"_pl"+str(pl)+"_es"+str(es)+"_fs"+str(fs)
+
+	output_dirname = dirname + '/' + sequence_name + "_" + str(floating_time).zfill(2) + "_on_" + str(reference_time).zfill(2) + "" + namestring
+	if not os.path.exists(output_dirname):
+		os.makedirs(output_dirname)
+
+	reference_img = images[reference_filename]
+	floating_img = images[floating_filename]
+
+	####################################################################
+
+	# Registration of the floating images on ref
+	# -----------------------------------------------------
+	
+	if (not preregistered) :
+		# A. Find optimised rigid transformations
+		rigid_img, rigid_trsf = find_rigid_transfo2(reference_img, floating_img)
+		rigid_images[floating_filename] = rigid_img
+		rigid_transformations[floating_filename] = rigid_trsf
+		
+		if save_files:
+			# rigid-registered images
+			rigid_filename = output_dirname + '/' + floating_filename + "_rigid_on_" + str(reference_time).zfill(2) + ".inr.gz"
+			imsave(rigid_filename, rigid_img)
+
+			# optimised (with block-matching) rigid transformations
+			rigid_trsf_filename = output_dirname + '/tr_' + floating_filename + '_rigid.txt'
+			tfsave(rigid_trsf_filename, rigid_trsf)
+
+		# B. Find optimised affine transformations (initialised by the rigid tfs computed above)
+		affine_img, affine_trsf = find_affine_transfo(reference_img, floating_img, init_trsf=rigid_trsf)
+		affine_images[floating_filename] = affine_img
+		affine_transformations[floating_filename] = affine_trsf
+
+		if save_files:
+			# affine-registered images
+			affine_filename = output_dirname + '/' + floating_filename + "_affine_on_" + str(reference_time).zfill(2) + ".inr.gz"
+			imsave(affine_filename, affine_img)
+
+			# optimised (with block-matching) affine transformations
+			affine_trsf_filename = output_dirname + '/tr_' + floating_filename + '_affine.txt'
+			tfsave(affine_filename, affine_trsf)
+		floating_img0=affine_img
+	else :
+		floating_img0=floating_img
+	# C. Find nonlinear transformations which register the affine-transformed images
+	#registered_img, nl_trsf = find_nl_transfo(reference_img, affine_img, ph=ph, pl=pl, es=es, fs=fs)
+	for it in range(iterations):
+		registered_img, nl_trsf = find_nl_transfo(reference_img, floating_img0, ph=ph, pl=pl, es=es, fs=fs)
+		registered_images[floating_filename] = registered_img
+		non_linear_transformations[floating_filename] = nl_trsf
+
+		# paths to nonlinearly registered images
+		registered_filename = output_dirname + '/' + floating_filename + "_registered_on_" + str(reference_time).zfill(2) + "_it"+str(it)+".inr.gz"
+		imsave(registered_filename, registered_img)
+		floating_img0=registered_img
+
+		if save_files:
+			# non-linear transformations
+			nl_trsf_filename = output_dirname + '/' + floating_filename + "_it"+str(it)+"_vectorfield.inr.gz"
+			save_trsf(nl_trsf, nl_trsf_filename, compress=True)
+	return registered_img
+
Index: bin/image2geometry/gather_data.py
===================================================================
--- bin/image2geometry/gather_data.py	(revision 0)
+++ bin/image2geometry/gather_data.py	(revision 10)
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+
+# before lounching the executable activate the timagetk conda environement
+# conda activate florivar
+
+# general imports :
+from sys import argv
+import pandas as pd
+import os
+
+
+def read_areas(dirname):
+    listfiles=os.listdir(dirname)
+    listfiles=[i for i in listfiles if '-area.csv' in i]
+    sepalname=[]
+    area=[]
+    for i in listfiles:
+        name=i.split('-area.csv')[0]
+        sepalname.append(name)
+        df=pd.read_csv(dirname+i, delimiter=',')[:-2]
+        A=max(df['Value'])
+        area.append(A)
+    data = {'Sepal': sepalname, 'Area': area}
+    newdf=pd.DataFrame.from_dict(data)    
+    newdf=newdf.sort_values("Sepal", ascending=True, inplace=False)
+    return newdf
+
+def read_measurements(fname):
+    df=pd.read_csv(fname, delimiter=';')
+    print("Reading file : ",fname)
+    print("Number of entries at reading: ",df.shape)
+    df['Sepal']=[name.split('_oriented')[0] for name in df['Sepal']]
+    df=df.sort_values("Sepal", ascending=True, inplace=False)
+    return df
+
+
+measures_filename = argv[1]
+areadir = argv[2]+'/'
+
+root=measures_filename.split('.csv')[0]
+outputfile=root+"_full.csv"
+
+
+df=read_measurements(measures_filename)
+newdf=read_areas(areadir)
+#
+df = pd.merge(df, newdf, left_on="Sepal", right_on="Sepal")
+#
+df['CurvedSF']=df['CurvedWidth']/df['CurvedLength']
+df['FlatSF']=df['FlatWidth']/df['FlatLength']
+#
+df['Thickness']=df['volume']/df['Area']
+#
+df['GaussK']=1./df['LR']/df['TR']
+df['CentralGaussK']=1./df['LR423']/df['TR423']
+df.to_csv(outputfile, index=False, sep=";")
+print("Number of entries : ",df.shape)
+labels=list(df.columns[1:])
+print('Columns written:',list(df.columns))
+print('Sepals:',list(df['Sepal']))
+print('Measurements written in file:',outputfile)
+
+
Index: bin/image2geometry/orient_sepal.py
===================================================================
--- bin/image2geometry/orient_sepal.py	(revision 9)
+++ bin/image2geometry/orient_sepal.py	(revision 10)
@@ -20,8 +20,8 @@
 from scipy.ndimage.morphology import binary_closing, binary_opening
 
 from titk_tools.io import imread, imsave, tfread, SpatialImage
-from titk_tools.registration import isotropic_resampling_seg
-from titk_tools.registration import apply_transfo_on_seg1
+from titk_tools.registration import isotropic_resampling_seg, isotropic_resampling
+from titk_tools.registration import apply_transfo_on_seg1, apply_transfo_on_image
 
 from bib_sepals import *
 
@@ -30,7 +30,15 @@
 filename = argv[1]
 outputdir=argv[2]+'/'
 
+segmented=True
+
+if len(argv)>3:
+	imagetype=argv[3]
+	if imagetype=='grey':
+		segmented=False
+
 print(argv)
+print('segmented=',segmented)
 
 imname = filename.split('/')[-1]
 imnameroot = imname.split('.')[0]
@@ -38,14 +46,15 @@
 outfilename = outputdir+imnameroot+'_oriented.inr.gz'
 
 # read the image
-sepale=imread(filename)
+img=imread(filename)
 # resample isotropically
 print("----------------------")
 print("isotropic resampling of : filename=", filename)
 print("----------------------")
-voxelsize = sepale.voxelsize
+voxelsize = img.voxelsize
 print("voxelsize=",voxelsize)
-s = sepale.shape
+s = img.shape
+imgtype=img.dtype
 print("shape=",s)
 
 radius=int(voxelsize[2]/voxelsize[0])
@@ -53,8 +62,12 @@
 #isovs=voxelsize[0]
 print("new voxelsize=",isovs)
 
-sepale=SpatialImage(sepale>0, dtype='uint8', voxelsize=voxelsize, origin=[0, 0, 0])
-sepale=isotropic_resampling_seg(sepale,isovs)
+sepale=SpatialImage(img>0, dtype='uint8', voxelsize=voxelsize, origin=[0, 0, 0])
+if segmented:
+	sepale=isotropic_resampling_seg(sepale,isovs)
+else:
+	img=isotropic_resampling(img,isovs)
+	sepale=isotropic_resampling_seg(sepale,isovs)
 
 s = sepale.shape
 voxelsize = sepale.voxelsize
@@ -68,6 +81,8 @@
 s_addy=int((np.sqrt(s[0]*s[1]*2)-np.sqrt(s[0]*s[1]))/2)
 s_addz=int(s[2]*0.20)
 sepale=add_side_slices(sepale, 0, 0, s_addy, s_addy, s_addz, s_addz)
+if not segmented :
+	img=add_side_slices(img, 0, 0, s_addy, s_addy, s_addz, s_addz)
 
 '''
 # smooth it with opening
@@ -83,10 +98,12 @@
 '''
 
 # put the center of mass in the center of the image
-sepale_centered=center_on_cm(sepale, volumic=False)
+sepale_centered=center_on_cm(sepale, volumic=True)
+if not segmented:
+	img=center_on_cm(img, volumic=True)
 
 # compute principal directions
-pv_flo=principal_directions(sepale_centered, volumic=False)
+pv_flo=principal_directions(sepale_centered, volumic=True)
 print(pv_flo)
 
 # sepals originally are oriented with top in more-or less "up" direction on the images
@@ -120,13 +137,20 @@
 os.system("rm "+trsf_file)
 
 # apply transformation
-oriented=apply_transfo_on_seg1(trsf, sepale_centered)
+if segmented :
+	oriented=apply_transfo_on_seg1(trsf, sepale_centered)
+else :
+	oriented=apply_transfo_on_image(trsf, img)
 
 # smooth the transformed image
 #sepale = binary_closing(oriented, structure=struct_el, iterations=radius)
 
 # and save the oriented sepal
 sepale_filename = outputdir+imnameroot+'_oriented.inr.gz'
-sepale=SpatialImage(oriented*255, dtype='uint8', voxelsize=voxelsize, origin=[0, 0, 0])
+if segmented :
+	sepale=SpatialImage(oriented*255, dtype='uint8', voxelsize=voxelsize, origin=[0, 0, 0])
+else:
+	sepale=SpatialImage(oriented, dtype=imgtype, voxelsize=voxelsize, origin=[0, 0, 0])
+
 imsave(sepale_filename, sepale)
 
Index: bin/image2geometry/measure_sepal.py
===================================================================
--- bin/image2geometry/measure_sepal.py	(revision 9)
+++ bin/image2geometry/measure_sepal.py	(revision 10)
@@ -38,6 +38,7 @@
 outputdir=outdir+"/sections/"
 projectiondir=outdir+"/projections"
 
+
 print(argv)
 
 imname = filename.split('/')[-1]
@@ -47,6 +48,7 @@
 #projected2Dimage_hight=outdir+"/hight_"+imnameroot+"2D.png"
 
 os.system("mkdir -p "+outputdir)
+os.system("mkdir -p "+symdir)
 
 outname = outputfile.split('/')[-1]
 outroot = outname.split('.')[0]
@@ -58,6 +60,7 @@
 voxelsize = sepale.voxelsize
 print("voxelsize=",voxelsize)
 s = sepale.shape
+imtype=sepale.dtype
 print("shape=",s)
 
 print("Computing the volume and volumic asymmetry...")
@@ -79,6 +82,8 @@
 
 vol=vol*voxelsize[0]*voxelsize[1]*voxelsize[2]
 
+
+
 print("Projecting on 2D...")
 
 def project2D(im3):
Index: bin/image2geometry/MGX_CurvatureMapSegmentation.py
===================================================================
--- bin/image2geometry/MGX_CurvatureMapSegmentation.py	(revision 9)
+++ bin/image2geometry/MGX_CurvatureMapSegmentation.py	(revision 10)
@@ -12,7 +12,6 @@
 
 # directory with detected sepal contours
 filedata1="/home/akiss/RDP/Projects/Sepals/RNA-Seq_Final/06.ContourDetection/JL_22C/mgx-contours"
-filedata1="/home/akiss/RDP/Projects/Sepals/RNA-Seq_Final/06.ContourDetection/test"
 
 
 ################### Parameters ###########
Index: bin/image2geometry/orient_sepals.sh
===================================================================
--- bin/image2geometry/orient_sepals.sh	(revision 9)
+++ bin/image2geometry/orient_sepals.sh	(revision 10)
@@ -8,6 +8,7 @@
 
 indir=$1
 filetype=$2
+imagetype=$3
 
 outdir=$indir'_oriented-sepals'
 
@@ -26,7 +27,14 @@
 	echo $file  >> $logfile
 	echo $file $outdir
 	echo '--------------------------' >> $logfile
-	orient_sepal.py $file $outdir
+	if test $imagetype=="grey"
+	then
+		echo 'orienting grey image '$file
+		orient_sepal.py $file $outdir $imagetype
+	else
+		echo 'orienting segmented image '$file
+		orient_sepal.py $file $outdir
+	fi
 	echo '--------------------------' >> $logfile
 done
 
