diff --git a/code/wrappers/+nansen/+wrapper/+flowreg/@Processor/Processor.m b/code/wrappers/+nansen/+wrapper/+flowreg/@Processor/Processor.m index d85904b55..6434f5e52 100644 --- a/code/wrappers/+nansen/+wrapper/+flowreg/@Processor/Processor.m +++ b/code/wrappers/+nansen/+wrapper/+flowreg/@Processor/Processor.m @@ -178,9 +178,12 @@ function updateCorrectionStats(obj, IND) meanDivergence = get_mean_divergence(W); meanTranslation = get_mean_translation(W); - % Compute quantities - xOffset = squeeze(mean(mean(W(:,:,2,:), 1), 2)); %Todo: Is 2nd x-offsets? - yOffset = squeeze(mean(mean(W(:,:,1,:), 1), 2)); %Todo: Is 1st y-offsets? + % Compute quantities. The displacement field of flowreg holds + % the displacement in x in its first channel and the + % displacement in y in its second, which is the order that + % imwarp takes a displacement field in. + xOffset = squeeze(mean(mean(W(:,:,1,:), 1), 2)); + yOffset = squeeze(mean(mean(W(:,:,2,:), 1), 2)); rmsmov = sqrt(mean( W(:).^2) ); % Add results to struct @@ -375,7 +378,12 @@ function onInitialization(obj) end function shifts = addShifts(shifts, offset) - % Add rigid shifts to struct of normcorre nonrigid shifts. + % Add a rigid offset to the displacement fields of flowreg. + % + % The offset is [dx, dy], as it comes from correctDrift, and + % the field holds the displacement in x in its first channel + % and the displacement in y in its second, so the two are in + % the same order. for k = 1:numel(shifts) shifts{k}(:, :, 1, :) = shifts{k}(:, :, 1, :) + offset(1); shifts{k}(:, :, 2, :) = shifts{k}(:, :, 2, :) + offset(2); diff --git a/code/wrappers/+nansen/+wrapper/+normcorre/@Processor/Processor.m b/code/wrappers/+nansen/+wrapper/+normcorre/@Processor/Processor.m index d6d442042..9e3b5d288 100644 --- a/code/wrappers/+nansen/+wrapper/+normcorre/@Processor/Processor.m +++ b/code/wrappers/+nansen/+wrapper/+normcorre/@Processor/Processor.m @@ -286,12 +286,17 @@ function onCompletion(obj) methods (Static) function ncShifts = addShifts(ncShifts, offset) - % Add rigid shifts to struct of normcorre nonrigid shifts. + % Add a rigid offset to a struct of normcorre shifts. + % + % The offset is [dx, dy], as it comes from correctDrift, while + % normcorre follows the MATLAB array convention and holds the + % shift in y in the first plane of its shifts and the shift in + % x in the second, so the two are in opposite order. for k = 1:numel(ncShifts) - ncShifts(k).shifts(:,:,:,1) = ncShifts(k).shifts(:,:,:,1) + offset(1); - ncShifts(k).shifts(:,:,:,2) = ncShifts(k).shifts(:,:,:,2) + offset(2); - ncShifts(k).shifts_up(:,:,:,1) = ncShifts(k).shifts_up(:,:,:,1) + offset(1); - ncShifts(k).shifts_up(:,:,:,2) = ncShifts(k).shifts_up(:,:,:,2) + offset(2); + ncShifts(k).shifts(:,:,:,1) = ncShifts(k).shifts(:,:,:,1) + offset(2); + ncShifts(k).shifts(:,:,:,2) = ncShifts(k).shifts(:,:,:,2) + offset(1); + ncShifts(k).shifts_up(:,:,:,1) = ncShifts(k).shifts_up(:,:,:,1) + offset(2); + ncShifts(k).shifts_up(:,:,:,2) = ncShifts(k).shifts_up(:,:,:,2) + offset(1); end end end