flatironinstitute / NoRMCorre

Matlab routines for online non-rigid motion correction of calcium imaging data
GNU General Public License v2.0
144 stars 89 forks source link

Unknown error #9

Closed ehennestad closed 7 years ago

ehennestad commented 7 years ago

Hi,
I started to encounter an error (see below) lately, and I wonder if you have any ideas why it might happen.

I am aligning an array of 5000 images, and this is the options I am using:

                Y1 = double(tmp_imArray);
                options_nonrigid = NoRMCorreSetParms('d1',size(Y1,1),'d2',size(Y1,2),...
                                       'grid_size',[64, 64],'mot_uf',4,'bin_width',43,...
                                       'max_shift',15,'max_dev',30,'us_fac',50);

                [tmp_imArray, ~, ~] = normcorre_batch(Y1, options_nonrigid);

This is the error:

Error using remove_boundaries (line 30)
Index exceeds matrix dimensions.

Error in shift_reconstruct (line 48)
    I = remove_boundaries(I,shifts,method,add_value);

Error in normcorre_batch>(parfor body) (line 332)
                                    M_fin{i,j,k} =
                                    shift_reconstruct(I_temp,shifts_up(i,j,k,:),diff_up(i,j,k),us_fac,Nr{i,j,k},Nc{i,j,k},Np{i,j,k},options.boundary,add_value);

Error in normcorre_batch (line 262)
        parfor ii = 1:lY
epnev commented 7 years ago

My guess is that you have shifts that are too large to be contained within the patches. With grid_size 64, upsampling factor 4, and shifts allowed up to 45, this could potentially happen. You could turn the parfor into a for and track the values of the shifts for the patch where things break down.

Alternatively, you can try setting options.shifts_method = 'cubic' which would apply an imwarp transform. Let me know how it goes

ehennestad commented 7 years ago

Hi,

Thank you:) I tried with different combinations of grid size and shifts, and it seems like the combination of small grid size and large shifts causes the error.

epnev commented 7 years ago

great, glad to hear that!