diff --git a/CellReg/align_images.m b/CellReg/align_images.m index 872f6a7..8c81955 100644 --- a/CellReg/align_images.m +++ b/CellReg/align_images.m @@ -16,9 +16,10 @@ % 8. alignment_type - 'Translations' or 'Translations and Rotations' % 9. sufficient_correlation_centroids % correlation between the centroid locations % 10. sufficient_correlation_footprints % correlation between the spatial footprints -% 11. varargin -% 11{1}. use_parallel_processing - 'true' for parallel processing -% 11{2}. maximal rotation - if 'Translations and Rotations' is used +% 11. use_parallel_processing - 'true' for parallel processing +% 12. varargin +% 12{1}. maximal rotation/transformation_smoothness - if 'Translations and +% Rotations'/'Non-rigid' is used % Outputs: % 1. spatial_footprints_corrected @@ -71,11 +72,12 @@ % Aligning the images and cells: display_progress_bar('Terminating previous progress bars',true) if strcmp(alignment_type,'Non-rigid') % Non-rigid alignment: + transformation_smoothness=varargin{1}; for n=1:number_of_sessions-1 disp(['Performing non-rigid transformation for session #' num2str(registration_order(n)) ':']) reference_footprints_projections_corrected=footprints_projections_corrected{reference_session_index}; temp_footprints_projections_corrected=footprints_projections_corrected{registration_order(n)}; - [displacement_field,temp_footprints_projections_non_rigid_corrected]=imregdemons(temp_footprints_projections_corrected,reference_footprints_projections_corrected); + [displacement_field,temp_footprints_projections_non_rigid_corrected]=imregdemons(temp_footprints_projections_corrected,reference_footprints_projections_corrected,'AccumulatedFieldSmoothing',transformation_smoothness); footprints_projections_corrected{registration_order(n)}=temp_footprints_projections_non_rigid_corrected; this_session_footprints_unaligned=spatial_footprints_corrected{registration_order(n)}; this_session_footprints_aligned=zeros(size(this_session_footprints_unaligned)); diff --git a/CellReg/demo.m b/CellReg/demo.m index bd8c52f..44409c8 100644 --- a/CellReg/demo.m +++ b/CellReg/demo.m @@ -69,6 +69,7 @@ alignment_type='Translations and Rotations'; % either 'Translations', 'Translations and Rotations' or 'Non-rigid' use_parallel_processing=true; % either true or false maximal_rotation=30; % in degrees - only relevant if 'Translations and Rotations' is used +FOV_smoothing=2; % levels of non-rigid FOV transformation smoothness (range 0.5-3) reference_session_index=1; % Preparing the data for alignment: @@ -86,6 +87,9 @@ if strcmp(alignment_type,'Translations and Rotations') [spatial_footprints_corrected,centroid_locations_corrected,footprints_projections_corrected,centroid_projections_corrected,maximal_cross_correlation,alignment_translations,overlapping_FOV]=... align_images(adjusted_spatial_footprints,centroid_locations,adjusted_footprints_projections,centroid_projections,adjusted_FOV,microns_per_pixel,reference_session_index,alignment_type,sufficient_correlation_centroids,sufficient_correlation_footprints,use_parallel_processing,maximal_rotation); +elseif strcmp(alignment_type,'Non-rigid') + [spatial_footprints_corrected,centroid_locations_corrected,footprints_projections_corrected,centroid_projections_corrected,maximal_cross_correlation,alignment_translations,overlapping_FOV]=... + align_images(adjusted_spatial_footprints,centroid_locations,adjusted_footprints_projections,centroid_projections,adjusted_FOV,microns_per_pixel,reference_session_index,alignment_type,sufficient_correlation_centroids,sufficient_correlation_footprints,use_parallel_processing,FOV_smoothing); else [spatial_footprints_corrected,centroid_locations_corrected,footprints_projections_corrected,centroid_projections_corrected,maximal_cross_correlation,alignment_translations,overlapping_FOV]=... align_images(adjusted_spatial_footprints,centroid_locations,adjusted_footprints_projections,centroid_projections,adjusted_FOV,microns_per_pixel,reference_session_index,alignment_type,sufficient_correlation_centroids,sufficient_correlation_footprints,use_parallel_processing); diff --git a/Docs/User Manual.docx b/Docs/User Manual.docx index d692c08..59abc6d 100644 Binary files a/Docs/User Manual.docx and b/Docs/User Manual.docx differ diff --git a/GUI/CellReg.fig b/GUI/CellReg.fig index 5dc377f..22a09db 100644 Binary files a/GUI/CellReg.fig and b/GUI/CellReg.fig differ diff --git a/GUI/CellReg.m b/GUI/CellReg.m index 8ce2579..2fecd1d 100644 --- a/GUI/CellReg.m +++ b/GUI/CellReg.m @@ -56,7 +56,7 @@ % Edit the above text to modify the response to help CellReg -% Last Modified by GUIDE v2.5 19-Mar-2018 10:18:35 +% Last Modified by GUIDE v2.5 19-Mar-2018 16:23:43 % reset figure properties to default: if verLessThan('matlab','8.4') @@ -173,6 +173,8 @@ function CellReg_OpeningFcn(hObject,~, handles, varargin) set(handles.reference_session_index,'string','1') set(handles.maximal_rotation','string','30') set(handles.maximal_rotation','enable','on') +set(handles.transformation_smoothness,'string','2') +set(handles.transformation_smoothness,'enable','off') set(handles.distance_threshold,'enable','off') set(handles.correlation_threshold,'enable','on') set(handles.decision_thresh,'enable','on') @@ -663,6 +665,14 @@ function transform_sessions_Callback(hObject,~, handles) if strcmp(alignment_type,'Translations and Rotations') maximal_rotation=str2num(get(handles.maximal_rotation,'string')); end +if strcmp(alignment_type,'Non-rigid') + transformation_smoothness=str2num(get(handles.transformation_smoothness,'string')); + if transformation_smoothness>3 || transformation_smoothness<0.5 + errordlg('FOV smoothing parameter should be between 0.5-3') + error('FOV smoothing parameter should be between 0.5-3') + end +end + reference_session_index=str2num(get(handles.reference_session_index,'string')); reference_valid=1; if isempty(reference_session_index) || reference_session_index<1 || reference_session_index>number_of_sessions @@ -693,6 +703,9 @@ function transform_sessions_Callback(hObject,~, handles) if strcmp(alignment_type,'Translations and Rotations') [spatial_footprints_corrected,centroid_locations_corrected,footprints_projections_corrected,centroid_projections_corrected,maximal_cross_correlation,alignment_translations,overlapping_FOV]=... align_images(adjusted_spatial_footprints,centroid_locations,adjusted_footprints_projections,centroid_projections,adjusted_FOV,microns_per_pixel,reference_session_index,alignment_type,sufficient_correlation_centroids,sufficient_correlation_footprints,use_parallel_processing,maximal_rotation); +elseif strcmp(alignment_type,'Non-rigid') + [spatial_footprints_corrected,centroid_locations_corrected,footprints_projections_corrected,centroid_projections_corrected,maximal_cross_correlation,alignment_translations,overlapping_FOV]=... + align_images(adjusted_spatial_footprints,centroid_locations,adjusted_footprints_projections,centroid_projections,adjusted_FOV,microns_per_pixel,reference_session_index,alignment_type,sufficient_correlation_centroids,sufficient_correlation_footprints,use_parallel_processing,transformation_smoothness); else [spatial_footprints_corrected,centroid_locations_corrected,footprints_projections_corrected,centroid_projections_corrected,maximal_cross_correlation,alignment_translations,overlapping_FOV]=... align_images(adjusted_spatial_footprints,centroid_locations,adjusted_footprints_projections,centroid_projections,adjusted_FOV,microns_per_pixel,reference_session_index,alignment_type,sufficient_correlation_centroids,sufficient_correlation_footprints,use_parallel_processing); @@ -1321,6 +1334,8 @@ function reset_Callback(hObject,~, handles) set(handles.reference_session_index,'string','1') set(handles.maximal_rotation','string','30') set(handles.maximal_rotation','enable','on') +set(handles.transformation_smoothness,'string','2') +set(handles.transformation_smoothness,'enable','off') set(handles.distance_threshold,'enable','off') set(handles.correlation_threshold,'enable','on') set(handles.simple_distance_threshold,'enable','off') @@ -2172,8 +2187,10 @@ function non_rigid_Callback(hObject, eventdata, handles) if get(handles.non_rigid,'Value')==1 set(handles.maximal_rotation,'enable','off') + set(handles.transformation_smoothness,'enable','on') else set(handles.maximal_rotation,'enable','on') + set(handles.transformation_smoothness,'enable','off') set(handles.maximal_rotation,'string','30') end @@ -2192,6 +2209,7 @@ function two_photon_Callback(hObject, eventdata, handles) set(handles.centroid_distances_2,'value',1) set(handles.maximal_rotation,'enable','off') set(handles.model_maximal_distance,'string',num2str(15)) + set(handles.transformation_smoothness,'enable','on') end % --- Executes on button press in one_photon. @@ -2207,5 +2225,34 @@ function one_photon_Callback(hObject, eventdata, handles) set(handles.spatial_correlations,'value',1) set(handles.spatial_correlations_2,'value',1) set(handles.maximal_rotation,'enable','on') - set(handles.model_maximal_distance,'string',num2str(12)) + set(handles.transformation_smoothness,'enable','off') + set(handles.model_maximal_distance,'string',num2str(12)) +end + + +function transformation_smoothness_Callback(hObject, eventdata, handles) +% hObject handle to transformation_smoothness (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: get(hObject,'String') returns contents of transformation_smoothness as text +% str2double(get(hObject,'String')) returns contents of transformation_smoothness as a double + +transformation_smoothness=str2num(get(handles.transformation_smoothness,'string')); +if transformation_smoothness>3 || transformation_smoothness<0.5 + errordlg('FOV smoothing parameter should be between 0.5-3') + error('FOV smoothing parameter should be between 0.5-3') +end + + +% --- Executes during object creation, after setting all properties. +function transformation_smoothness_CreateFcn(hObject, eventdata, handles) +% hObject handle to transformation_smoothness (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: edit controls usually have a white background on Windows. +% See ISPC and COMPUTER. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); end