Skip to content

Commit

Permalink
added control of transformation smoothness to non-rigid alignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheintuch committed Mar 19, 2018
1 parent 385c02e commit 9d12e00
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
10 changes: 6 additions & 4 deletions CellReg/align_images.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions CellReg/demo.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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);
Expand Down
Binary file modified Docs/User Manual.docx
Binary file not shown.
Binary file modified GUI/CellReg.fig
Binary file not shown.
51 changes: 49 additions & 2 deletions GUI/CellReg.m
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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

Expand All @@ -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.
Expand All @@ -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

0 comments on commit 9d12e00

Please sign in to comment.