Closed akatav closed 4 years ago
@akatav Yes, you should be able to do it. There are two questions though:
apply_shifts
or perhaps correct each separately, then see which makes more sense and apply to the rest etc..@epnev thank you so much. I shall answer your questions to the best of my ability. 1.We'd like to correct motion artifacts in every image - because the brain slice is raster scanned by the microscope.So,there might be motion artifacts due to breathing,head motion in every row of the frame. I did notice that NoRMCorre includes some code to handle bidirectional scanning. Are these kinds of motion artifacts removed in NoRMCorre - if no, it will be very helpful if you can let me know how this can be handled.
options_rigid = NoRMCorreSetParms('d1',MC_rigid.dims(1),'d2',MC_rigid.dims(2),'grid_size',[8,8],'bin_width',10,'shifts_method','FFT','max_shift',25,'us_fac',50,'output_type','tiff','init_batch',44,'tiff_filename','motion_corrected_downsized.tiff', 'plot_flag',true,'nFrames',22);
But, this seems to take a lot of time. Could you advise how to set these params (Esp, grid size, overlap, bin width) depending on my dataset.As i mentioned, there are no neurons, only dendrites and synapses in the images.
correct_bidir
which is by default set to True. It will be the same for all planes.d3
argument equal to dims(3)
(44 in your case) and similarly have a grid_size
with length equal to 3. Regarding parameter setting I would recommend taking a look at the wiki and especially this entry. For example I would choose grid_size = [512, 512, 44]
in your case, see whether it gives good results and adjust accordingly. I would turn off the plotting flag (it's useless in 3D) and probably try setting the shifts method to cubic
as it is in general faster than FFT
. Also saving the file in tiff will take a lot of time. You can try saving it in H5/HDF5 format or simply don't pass this argument and have the corrected file loaded in memory (if it's not too large to fit).@epnev thank you. Is there an example of setting d3 for 2-photon images.I tried to set d3=44 but received the following error:
Registering the first 1 frames just to obtain a good template....Matrix dimensions must agree. Error in dftregistration_min_max_3d>FTpad3d (line 307) cenout_cen = centerout - center;
Error in dftregistration_min_max_3d (line 133) buf_pad = FTpad3d(buf_prod,[2nr,2nc,2*np]);
Error in normcorre (line 153) [~,Greg] = dftregistration_min_max_3d(fftTemp,fftn(Y_temp(:,:,:,t)),us_fac,-max_shift,max_shift,options.phase_flag);
Error in MotionCorrection/motionCorrectSerial (line 59) [obj.M,obj.shifts,obj.template,obj.options,obj.col_shift] = normcorre(obj.file,obj.options);
Error in demo_mc_class (line 25) MC_nonrigid.motionCorrectSerial(options_nonrigid);
One question i have is: My movies show images of parts of dendrites through a stack (like, peering through bottom up or top down, through a glass column filled with roots). The msCam.avi example (demo_1p.m has a FOV that is unchanging but shaky). I thought that the granule.tif is more suited to my case and hence did not set d3 (as in demo_mc_class.m). Is that example similar to the dataset i have? Thank you very much!
The code assumes that the file you pass in (or index to) is a 4D array with dimensions X x Y x Z x T. From your error log I suspect that you pass only a single volume X x Y x Z and the code gives an error because there is no template to register against, and not enough volume frames to compute a template. You can either:
@epnev thanks.I should've known that.So, I did pass a 4d array (1024 by 1024 by 44 by 4) with parameters as advised in the wiki (they are: options_nonrigid = NoRMCorreSetParms('output_type','h5','shifts_method','cubic', 'plot_flag',false,'nFrames',44,'use_parallel',true, 'd1',MC_nonrigid.dims(1),'d2',MC_nonrigid.dims(2),'d3',44,'grid_size', [512, 512],'overlap_pre', [32,32], 'mot_uf', [4,4], 'max_shift', [100,100], 'max_dev',[8,8]); I tried max_shift [20,20], [200,200] also but the images do not seem any different than the original images, unfortunately.
I also used grid_size=[512,512,44] but i got an error: Output argument "varargout{3}" (and maybe others) not assigned during call to "meshgridvectors".
Error in interp3 (line 110) [X, Y, Z] = meshgridvectors(V);
Error in normcorre (line 435) for dm = 1:3; shifts_up(:,:,:,dm) = interp3(shifts_temp(:,:,:,dm),Xq,Yq,Zq,'makima'); end
Error in MotionCorrection/motionCorrectSerial (line 60) [obj.M,obj.shifts,obj.template,obj.options,obj.col_shift] = normcorre(obj.file,obj.options);
Error in demo_mc_class (line 25) MC_nonrigid.motionCorrectSerial(options_nonrigid);
I have some concerns/questions.I really appreciate your guidance in this issue. 1.Would it help to apply some sort of filtering or deconvolution or noise reduction prior to motion correction ? 2.Or, should i apply rigid motion correction on the images and then apply non-rigid motion correction on the rigid MC images ? 3.What is the minimum preprocessing required by NoRMCorre ? For ex, does NormCorre expect that z-drift correction in a 3d stack of images be done already ?
grid_size', [512, 512],'overlap_pre', [32,32], 'mot_uf', [4,4], 'max_shift', [100,100], 'max_dev',[8,8]
As I mentioned earlier, since you're doing 3D motion correction, these parameters should also be vectors of length 3. Once you fix this you can proceed as in the 2p demos for the 2D case.
As for the pixel size, you can use to adjust the max_shift
parameter. In your case 100pixels* 0.082microns/pixel
gives 8.2microns
maximum allowed shift which is reasonable.
@epnev thanks,i did try like mentioned (parameters of length 3) but the motion corrected file is not visibly any different :(
[EDIT] - Sorry, so, i was not doing the rigid motion correction first. I did the rigid motion correction and the images look so much better, thanks. i'd however like to follow it up with non rigid mc and also try other images that have lot of motion artifacts,
I am looking to adopt NoRMCorre for a 4 channel dataset consisting of 3d stacks of images obtained along the axial plane of mice brain.So, the Field of View along z changes (thickness of brain slice=1 micron). Can i use NoRMCorre to correct motion artifacts in each image and correct alignment issues in every multichannel 3d stack ? The dataset is 1024*1024 and z=44. We are imaging dendrites and looking to reconstruct the 3d view of dendrites from the 2d slices. There are no neurons. Is NoRMCorre useful for my case? Attached is a sample 3d stack of one of the channels.