JinghaoLu / MIN1PIPE

A MINiscope 1-photon-based Calcium Imaging Signal Extraction PIPEline.
GNU General Public License v3.0
56 stars 25 forks source link

Error due to NaN matrix during non-stable registration #66

Open yrleftbrain opened 2 years ago

yrleftbrain commented 2 years ago

Hi, I'm getting the following error on a few files:

Error using imregionalmax Expected input number 1, I, to be non-NaN. Error in imregionalmax (line 67) validateattributes(varargin{1}, {'numeric','logical'}, {'real','nonsparse','nonnan'},...

This occurs during motion correction, specifically during non-stable registration. I can't find the issue, and I was wondering if you had some insight that may help. The matrix is of NaNs, and I'm not sure how this is being created. Thanks so much.

JinghaoLu commented 2 years ago

Hi the nested error messages are not relevant. I guess the issue might be related to some random dead pixels in the FOV. I would suggest: 1. Make sure the frames are correctly read. MIN1PIPE currently can only fast read some data formats and other compressed formats can lead to errors. 2. You can try loading the variable "reg" from "_reg.mat" before doing the motion correction, or variable "frame_all" form "_frame_all.mat", and compute the max to see if there are any dead pixels of extremely high value (you will see bright yellow pixels if there are any). In general, MIN1PIPE should be able to handle corner dead pixels, but if there is such pixel and you want a quick fix, I suggest you manually crop the rows and/or the columns before running MIN1PIPE. 3. If that is not the case, I suggest you go to line 99 of "nonstable_section.m", set a break point, and first check variable "maskc". It can be that maskc is off the target and captures too small a region. Let me know if any of the cases happen and then we can proceed. Thanks!

yrleftbrain commented 2 years ago

Thanks for the quick reply. I don't see any obvious 'dead pixels' when I plot the max. I also thought that remove_dp fixes all dead pixels? Am I assuming incorrectly? Alternatively, could it be due to dropped frames? How does min1pipe handle dropped frames?

Thanks again for the help.

JinghaoLu commented 2 years ago

@yrleftbrain As I said, remove_dp can remove dead pixels but no guarantee on all occasions (no single algorithm can do that). There is no impact of dropping frames. I also suggested other options so please try out all of them first.

yrleftbrain commented 2 years ago

Thanks. When I check maskc with a file that typically throws the error, it is a 630x630 (size of image) matrix of zeros.

JinghaoLu commented 2 years ago

@yrleftbrain Yes so that's the problem. Usually this comes from some dead pixel in the FOV that dominate the mask computation. The corner/edge dead pixels should be handled well, but a random dead pixel in the center (for example) of FOV might be causing this. And again the reason why that is not handled well is there is no reason to assume the intensities of the center pixels (good pixels can also be of very high intensity values). So this time please check again carefully the maximum projection: if overall FOV looks pretty dim, then it indicates some dead pixels somewhere in the FOV. You can find the max pixel location and then zoom into that area.

yrleftbrain commented 2 years ago

Thanks a lot for helping me find the issue. I ended up writing up a script to deal with dead pixels that weren't fixed by remove_dp. It works wonderfully now. Thanks again.