flatironinstitute / NoRMCorre

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

Possible bug with tiff files. #2

Closed ehennestad closed 7 years ago

ehennestad commented 7 years ago

I am running the following code: `name = '/Users/eivinhen/Desktop/imreg_test_reg.tif'; Y = name; iminfo = imfinfo(Y);

options_nonrigid = NoRMCorreSetParms('d1',iminfo(1).Height,'d2',iminfo(1).Width,'grid_size',[64,64],'mot_uf',4,'bin_width',50,'max_shift',25,'max_dev',20); [M2,shifts2,template2] = normcorre_batch(Y,options_nonrigid);`

And it produces an error: `Subscripted assignment dimension mismatch.

Error in cell2mat_ov (line 23) X(xx_s(i):xx_f(i),yy_s(j):yy_f(j),zz_s(k):zz_f(k)) = ...

Error in normcorre_batch (line 306) Mf{ii} = cell2mat_ov(M_fin,xx_us,xx_uf,yy_us,yy_uf,zz_us,zz_uf,overlap_post,sizY)

Error in demo (line 46) [M2,shifts2,template2] = normcorre_batch(Y,options_nonrigid);`

ehennestad commented 7 years ago

If I instead run the following lines (loading the tiff into a mat array), it works fine.

`name = '/Users/eivinhen/Desktop/imreg_test_reg.tif'; Y = loadtiff(name); Y = double(Y);
T = size(Y,ndims(Y));

options_nonrigid = NoRMCorreSetParms('d1',size(Y,1),'d2',size(Y,2),'grid_size',[64,64],'mot_uf',4,'bin_width',50,'max_shift',25,'max_dev',20,'us_fac',50); [M2,shifts2,template2] = normcorre_batch(Y,options_nonrigid);`

ehennestad commented 7 years ago

I have also been trying this out on another computer.

There I can pass a path to a tiff-stack to normcorre_batch and it runs fine, but the results are very bad, especially for the 50 first frames. If I instead load the tiff stack into an array and pass the array to normcorre_batch, the correction works very well.

Let me know if you need more details on this.

Best regards, Eivind

epnev commented 7 years ago

@ehennestad Does your data include negative values? normcorre_batch falsely uses the bigread2 to read the first batch of the data (by default 50 frames) and bigread2 assumes the data takes non-negative values.

epnev commented 7 years ago

I modified normcorre_batch to deal with possible negative values in the first frames. Let me know if that resolves your issue

ehennestad commented 7 years ago

That solves the problem! You were right, bigread2 was the culprit, although not because of negative values. My tiffs are padded with zeros on the edges, and that caused some strange effects when loading them using bigread2. Thanks again!