diff --git a/Notebooks/notebook.ipynb b/Notebooks/notebook.ipynb index 40f36e5..4ca9d80 100644 --- a/Notebooks/notebook.ipynb +++ b/Notebooks/notebook.ipynb @@ -57,7 +57,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "scrolled": false }, @@ -67,10 +67,54 @@ "output_type": "stream", "text": [ "Path to the folder of the movie(s) (in tiff format only) : \n", - " C:\\Users\\gros\\Desktop\\DATA\\20230207_fgf\\test\n", - "You have 1 movie(s), which is (are) :\n", + " C:\\Users\\gros\\Desktop\\DATA\\20221103_livedetection\\new_registration_062023\n", + "You have 1 movie(s), which is (are) : \n", + " gastr_SR_long_L1_Sum\n", + "Correct ? (1 for yes, 0 for no) \n", + " 1\n", + "\n", + "The dimensions of gastr_SR_long_L1_Sum are (200, 36, 2, 512, 512) . \n", + "\n", + "What is the order of the dimensions (for example TZCYX or XYZT) ? T stands for Time, C for channels if your image has multiple channels, Z for depth (or number or plans) and XY is your field of view. \n", + " TZCXY\n", + "\n", + "So gastr_SR_long_L1_Sum has 2 channels, 200 timepoints, the depth in z is 36 pixels and the XY plane measures 512 x 512 pixels.\n", + "Correct ? (1 for yes, 0 for no) \n", + " 1\n", + "Name of channel n°1 : \n", + " sulfo\n", + "Name of channel n°2 : \n", + " h2b\n", + "\n", + "Among the channels['sulfo', 'h2b'], you need a reference channel to compute the registration. A good option is generally a marker that is expressed ubiquitously\n", + "\n", + "Name of the reference channel : \n", + " h2b\n", + "\n", + "To register properly, you need to specify the voxel size of your input image. This can be found in Fiji, Image>Show Info. \n", + "Voxel size of your original image (XYZ successively) :\n", + " \n", + "X :0.62\n", + "Y :0.62\n", + "Z :2\n", + "Initial voxel size = [0.62, 0.62, 2.0]\n", + " \n", + "You can choose to have another voxel size on the registered image , for example to have an isotropic output image (voxel size [1,1,1]), Or you can also choose to keep the same voxel size. \n", + "Do you want to change the voxel size of your movies ? (1 for yes, 0 for no) : \n", + " 1\n", + "\n", + "Voxel size of your image after transformation (XYZ): \n", " \n", - "2\n" + "X :1\n", + "Y :1\n", + "Z :1\n", + "\n", + "Voxel size after transformation = [1.0, 1.0, 1.0]\n", + "\n", + "You can choose to apply different transformation types depending on your data : ['rigid2D', 'rigid3D', 'translation2D', 'translation3D']\n", + "\n", + "Which one do you want to use ? (please enter the name of the transformation only, no other character) \n", + " rigid3D\n" ] } ], @@ -87,7 +131,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -98,58 +142,65 @@ "Starting experiment\n", "The registration will run with the following arguments:\n", "\n", - "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- File format -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n", - "path_to_data : C:\\Users\\gros\\Desktop\\DATA\\20230207_fgf\\test/2_sulfo/stackseq/\n", + "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- File format ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n", + "path_to_data : C:\\Users\\gros\\Desktop\\DATA\\20221103_livedetection\\new_registration_062023/gastr_SR_long_L1_Sum_h2b/stackseq/\n", "file_name : movie_t{t:03d}.tif\n", - "trsf_folder : C:\\Users\\gros\\Desktop\\DATA\\20230207_fgf\\test/2_sulfo/trsf/\n", - "output_format : C:\\Users\\gros\\Desktop\\DATA\\20230207_fgf\\test/2_sulfo/output/\n", + "trsf_folder : C:\\Users\\gros\\Desktop\\DATA\\20221103_livedetection\\new_registration_062023/gastr_SR_long_L1_Sum_h2b/trsf/\n", + "output_format : C:\\Users\\gros\\Desktop\\DATA\\20221103_livedetection\\new_registration_062023/gastr_SR_long_L1_Sum_h2b/output/\n", "check_TP : 0\n", "\n", - "----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Time series properties -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n", - "voxel_size : 0.620000x0.620000x1.000000\n", + "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Time series properties ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n", + "voxel_size : 0.620000x0.620000x2.000000\n", "first : 0\n", - "last : 101\n", + "last : 199\n", "\n", - "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Registration ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n", + "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Registration --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n", "compute_trsf : 1\n", - "ref_TP : 51\n", - "trsf_type : translation2D\n", + "ref_TP : 100\n", + "trsf_type : rigid3D\n", "padding : 1\n", "lowess : 0\n", "trsf_interpolation : 0\n", "recompute : 1\n", "apply_trsf : 1\n", - "projection_path : C:\\Users\\gros\\Desktop\\DATA\\20230207_fgf\\test/2_sulfo/proj_output/\\\n", + "projection_path : C:\\Users\\gros\\Desktop\\DATA\\20221103_livedetection\\new_registration_062023/gastr_SR_long_L1_Sum_h2b/proj_output/\\\n", "image_interpolation : linear\n", "\n", - "0h:0min:30s\n", - "{'XResolution': 0.62, 'YResolution': 0.62, 'spacing': 1.0}\n", - "{'XResolution': 1.0, 'YResolution': 1.0, 'spacing': 1.0}\n", - "{'XResolution': 1.0, 'YResolution': 1.0, 'spacing': 1.0}\n", - "{'XResolution': 1.0, 'YResolution': 1.0, 'spacing': 1.0}\n", + "0h:1min:1s\n", + "{'XResolution': 0.62, 'YResolution': 0.62, 'spacing': 2.0}\n", + "Failure of {'path_to_data': 'C:\\\\Users\\\\gros\\\\Desktop\\\\DATA\\\\20221103_livedetection\\\\new_registration_062023/gastr_SR_long_L1_Sum_h2b/stackseq/', 'file_name': 'movie_t{t:03d}.tif', 'trsf_folder': 'C:\\\\Users\\\\gros\\\\Desktop\\\\DATA\\\\20221103_livedetection\\\\new_registration_062023/gastr_SR_long_L1_Sum_h2b/trsf/', 'output_format': 'C:\\\\Users\\\\gros\\\\Desktop\\\\DATA\\\\20221103_livedetection\\\\new_registration_062023/gastr_SR_long_L1_Sum_h2b/output/', 'projection_path': 'C:\\\\Users\\\\gros\\\\Desktop\\\\DATA\\\\20221103_livedetection\\\\new_registration_062023/gastr_SR_long_L1_Sum_h2b/proj_output/', 'check_TP': 0, 'voxel_size': [0.62, 0.62, 2.0], 'voxel_size_out': [1.0, 1.0, 1.0], 'first': 0, 'last': 199, 'not_to_do': [], 'compute_trsf': 1, 'ref_TP': 100, 'trsf_type': 'rigid3D', 'padding': 1, 'recompute': 1, 'apply_trsf': 1, 'out_bdv': '', 'plot_trsf': 0}\n", + "The requested file do not exist: C:\\Users\\gros\\Desktop\\DATA\\20221103_livedetection\\new_registration_062023/gastr_SR_long_L1_Sum_h2b/output/movie_t159.tif\n", "\n", "Starting experiment\n", "The registration will run with the following arguments:\n", "\n", - "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- File format --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n", - "path_to_data : C:\\Users\\gros\\Desktop\\DATA\\20230207_fgf\\test/2_h2B/stackseq/\n", + "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ File format ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n", + "path_to_data : C:\\Users\\gros\\Desktop\\DATA\\20221103_livedetection\\new_registration_062023/gastr_SR_long_L1_Sum_sulfo/stackseq/\n", "file_name : movie_t{t:03d}.tif\n", - "trsf_folder : C:\\Users\\gros\\Desktop\\DATA\\20230207_fgf\\test/2_sulfo/trsf/\n", - "output_format : C:\\Users\\gros\\Desktop\\DATA\\20230207_fgf\\test/2_h2B/output/\n", + "trsf_folder : C:\\Users\\gros\\Desktop\\DATA\\20221103_livedetection\\new_registration_062023/gastr_SR_long_L1_Sum_h2b/trsf/\n", + "output_format : C:\\Users\\gros\\Desktop\\DATA\\20221103_livedetection\\new_registration_062023/gastr_SR_long_L1_Sum_sulfo/output/\n", "check_TP : 0\n", "\n", - "-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Time series properties --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n", - "voxel_size : 0.620000x0.620000x1.000000\n", + "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Time series properties ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n", + "voxel_size : 0.620000x0.620000x2.000000\n", "first : 0\n", - "last : 101\n", + "last : 199\n", "\n", - "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Registration -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n", + "------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Registration -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n", "compute_trsf : 0\n", "apply_trsf : 1\n", - "projection_path : C:\\Users\\gros\\Desktop\\DATA\\20230207_fgf\\test/2_h2B/proj_output/\\\n", + "projection_path : C:\\Users\\gros\\Desktop\\DATA\\20221103_livedetection\\new_registration_062023/gastr_SR_long_L1_Sum_sulfo/proj_output/\\\n", "image_interpolation : linear\n", "\n" ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Failure of {'path_to_data': 'C:\\\\Users\\\\gros\\\\Desktop\\\\DATA\\\\20221103_livedetection\\\\new_registration_062023/gastr_SR_long_L1_Sum_sulfo/stackseq/', 'file_name': 'movie_t{t:03d}.tif', 'trsf_folder': 'C:\\\\Users\\\\gros\\\\Desktop\\\\DATA\\\\20221103_livedetection\\\\new_registration_062023/gastr_SR_long_L1_Sum_h2b/trsf/', 'output_format': 'C:\\\\Users\\\\gros\\\\Desktop\\\\DATA\\\\20221103_livedetection\\\\new_registration_062023/gastr_SR_long_L1_Sum_sulfo/output/', 'projection_path': 'C:\\\\Users\\\\gros\\\\Desktop\\\\DATA\\\\20221103_livedetection\\\\new_registration_062023/gastr_SR_long_L1_Sum_sulfo/proj_output/', 'check_TP': 0, 'voxel_size': [0.62, 0.62, 2.0], 'voxel_size_out': [1.0, 1.0, 1.0], 'first': 0, 'last': 199, 'not_to_do': [], 'compute_trsf': 0, 'ref_TP': 100, 'trsf_type': 'rigid3D', 'padding': 1, 'recompute': 1, 'apply_trsf': 1, 'out_bdv': '', 'plot_trsf': 0}\n", + "The requested file do not exist: C:\\Users\\gros\\Desktop\\DATA\\20221103_livedetection\\new_registration_062023/gastr_SR_long_L1_Sum_sulfo/output/movie_t013.tif\n" + ] } ], "source": [ diff --git a/User-manual/installation/installation_manual.pdf b/User-manual/installation/installation_manual.pdf new file mode 100644 index 0000000..5e03ce2 Binary files /dev/null and b/User-manual/installation/installation_manual.pdf differ diff --git a/src/registrationtools/_tests/test_spatial_forvalentin.py b/src/registrationtools/_tests/test_spatial_forvalentin.py new file mode 100644 index 0000000..5db5b91 --- /dev/null +++ b/src/registrationtools/_tests/test_spatial_forvalentin.py @@ -0,0 +1,93 @@ +#updated and clarified 22/03/23 for valentin +#windows version works on registration-env + +import tifffile +import numpy as np +import json +import os +from pathlib import Path +import registrationtools +from glob import glob + +##PARAMETERS +path_to_bin = "C:/Users/gros/Anaconda3/envs/registration-test_env/Library/bin/" #needs forward slashes everywhere plus one at the end of the path +main_folder = rf"C:\Users\gros\Desktop\DATA\Registration\pulse" +folder_output = rf"C:/Users/gros/Desktop/DATA/Registration/Valentin_output/" +path_to_json = rf'C:/Users/gros/Desktop/CODES/Alice_Registration/json_files/spatial.json' #where the json file is going to be saved (just for safety checks) +ch_ref = "dapi" +### give below the list of the channels that are going to be registered, with the first one being the reference channel +channels = ['dapi'] +channels_float=channels.copy() +channels_float.remove(ch_ref) +input_voxel = [0.62, 0.62, 1] +output_voxel = [1, 1, 1] #voxel size of the output images, XYZ +init_trsfs= [["flip", "Y", "flip", "Z", "trans", "Z", -10]]#,"rot","Y",-20]]#careful : translation is positive if the fisrt position is on top of the second position +axis = 0 +print(registrationtools) +#number of the samples registered + +register_spatial = True +check_napari = True + +def register(path_data:str,path_to_bin:str,name:str,channel:str,input_voxel:tuple=[1,1,1], + output_voxel:tuple=[1,1,1],compute_trsf:int=1) : + data = { + "path_to_bin": path_to_bin, + "path_to_data": rf"{path_data}/stacks_bychannel/", + "ref_im": rf"{name}_bot_{channel}.tif", + "flo_ims": [rf"{name}_top_{channel}.tif" + ], + "compute_trsf": compute_trsf + , + "init_trsfs":init_trsfs, + "trsf_paths": [rf"{path_data}/trsf/"], + "trsf_types": ["rigid3D"], + "ref_voxel": input_voxel, + "flo_voxels": [ input_voxel], + "out_voxel":output_voxel, + "test_init": 0, + "apply_trsf": 1, + "out_pattern": rf"{path_data}/registered", + "begin" : 1, + "end":1, + "bbox_out": 0, + "registration_depth":1, + } + + # #saves the json file + json_string=json.dumps(data) + with open(path_to_json,'w') as outfile : + outfile.write(json_string) + + tr = registrationtools.SpatialRegistration(data) + tr.run_trsf() + + +list_folder_day = [f.path for f in os.scandir(main_folder) if f.is_dir()] +for folder_day in list_folder_day : + print('Registering day',folder_day) + list_folder_experiment = [rf'C:\Users\gros\Desktop\DATA\Registration\pulse\20230101\test_seuils'] ##to select one experiment + for folder_experiment in list_folder_experiment : + name_experiment = os.path.basename(folder_experiment) + print('Name of the experiment :',name_experiment) + + # list_gastruloids=['g'+str(i+1) for i in range(len(list_bottom))] + list_gastruloids = ['g1'] + for ind_g,name_g in enumerate(list_gastruloids) : + print('gastruloid',name_g) + + folder_gastruloid = rf'{folder_experiment}/{name_g}/' + subfolder_output = rf'{folder_output}/{name_experiment}_{name_g}/' + + if register_spatial : + #registering the reference channel + register(path_data=folder_gastruloid,path_to_bin=path_to_bin,name=name_g,channel=ch_ref,input_voxel=input_voxel, + output_voxel=output_voxel,compute_trsf=1) + + for channel in channels_float : #loop to register every channels in the list one by one + print(channel) + compute_transf = 0 + #We just apply the previous transformation for a "secondary" channel with the same transformations, compute_transform=0. + register(path_data=folder_gastruloid,path_to_bin=path_to_bin,name=name_g,channel=channel,input_voxel=input_voxel, + output_voxel=output_voxel,compute_trsf=0) + diff --git a/src/registrationtools/spatial_registration.py b/src/registrationtools/spatial_registration.py index dd98f4b..6370cd9 100644 --- a/src/registrationtools/spatial_registration.py +++ b/src/registrationtools/spatial_registration.py @@ -142,6 +142,8 @@ def __init__(self, file_name: str): self.flo_im_sizes = None self.copy_ref = False self.bbox_out = False + self.low_th = None + self.high_th = None self.__dict__.update(param_dict) self.ref_voxel = tuple(self.ref_voxel) @@ -500,6 +502,12 @@ def compute_trsfs(self, p: trsf_parameters): init_trsf_command = "" i = 0 if not p.test_init: + if p.low_th is not None and 0 < p.low_th: + th = " -ref-lt {lt:f} -flo-lt {lt:f} -no-norma ".format( + lt=p.low_th + ) + else: + th = "" for i, trsf_type in enumerate(p.trsf_types[:-1]): if i != 0: init_trsf_command = " -init-trsf {:s}".format( @@ -522,7 +530,8 @@ def compute_trsfs(self, p: trsf_parameters): + init_trsf_command + " -res-trsf " + res_trsf - + " -composition-with-initial", + + " -composition-with-initial" + +th, shell=True, ) trsf_type = p.trsf_types[-1] @@ -553,11 +562,12 @@ def compute_trsfs(self, p: trsf_parameters): + res_trsf + # ' -res-voxel-trsf ' + res_voxel_trsf + \ # ' -res ' + flo_out +\ - " -composition-with-initial", + #" -composition-with-initial" + th, shell=True, ) call( - p.path_to_bin + "invTrsf %s %s" % (res_trsf, res_inv_trsf), + p.path_to_bin + "invTrsf %s %s" % (res_trsf, res_inv_trsf) +th, shell=True, ) @@ -652,6 +662,7 @@ def apply_trsf(self, p, t=None): + A0_trsf, shell=True, ) + elif p.copy_ref: copyfile(p.ref_A.format(t=t), p.ref_out.format(t=t)) else: