phflot / flow_registration

Flow-Registration toolbox for 2P motion compensation
https://www.snnu.uni-saarland.de/flow-registration/
21 stars 2 forks source link

Larger buffer size seems to cause issue #6

Closed milesOIST closed 2 years ago

milesOIST commented 2 years ago

Using larger buffer produces error. I was compensating a 3000 frame video, but used my stanrdard settings for 20000 frame vid. Solved by removing the line 'buffer_size', 24 or reducing buffer_size to 16. Suggestion: If buffer size will cause errors later in the program, catching this at the start, rather than after running for some time, would be better.

Error:

Finished batch 25, 1 batches left.
Index exceeds the number of array elements. Index must not exceed 0.

Error in mat2gray (line 38)
if limits(2)==limits(1)   % Constant Image

Error in compensate_recording>get_eval (line 145)
        c1 = mat2gray(imgaussfilt3_multichannel(mat2gray(buffer), options));

Error in compensate_recording (line 107)
            = get_eval(options, buffer, c_ref, c_ref_raw, w_init, weight);

Error in test_real_world (line 120)
compensate_recording(options);

Here I was using these options:

options = OF_options(...
    'input_file', input_file, ...
    'output_path', output_folder, ... 
    'output_format', 'HDF5', ...
    'alpha', 1, ... % smoothness parameter
    'sigma', [1, 1, 0.1; ...  % gauss kernel size channel 1
              1, 1, 0.1], ... % gauss kernel size channel 2
    'levels', 40, ... % solver levels
    'eta', 0.75, ... % pyramid stepsize
    'iterations', 50, ... % outer iterations (the larger the better the result, but slower)
    'bin_size', 5, ... % binning over 5 frames from the 30 hz data=
    'buffer_size', 24, ... % size of blocks for the parallel evaluation (larger takes more memory)
    'reference_frames', baseline_reference ...
    );
phflot commented 2 years ago

I am going to look into it, it seems to be a more of problem with the final segment than larger buffer sizes. Do you have a short recording, e.g. 300 frames, that can reproduce the behaviour?

milesOIST commented 2 years ago

Weird, had no problems with 300 frame vid. I then tried again on another computer, just in case, and found the same error with 3000 frames and 24 buffer

phflot commented 2 years ago

Could you tell me what filetype your input file is? A Tiff with bin_size 5 and buffer_size 24 works for me with 3000 frames

milesOIST commented 2 years ago

This file was 3000 frames of HDF5 format, converted from a larger MDF file using

vid = get_video_file_reader("filename.MDF", 50);
vid = vid.read_frames(10000:13000);
input_file = "outfilename.HDF5");
writer = get_video_file_writer(input_file, 'HDF5');
writer.write_frames(vid);
phflot commented 2 years ago

I have found the bug, it is a problem with boundary handling after binning. Currently, the toolbox needs at least ceil(bin_size / 2) frames for the last binned frame. What behaviour would help you the most or what would you normally do for binning, should we discard the last few frames or average over however many frames are left?

milesOIST commented 2 years ago

That makes sense. For me, averaging over the last frames would be better as it is easier to align to the behaviour.

From: Philipp Flotho @.> Date: Friday, 13May, 2022 1:00 To: phflot/flow_registration @.> Cc: Miles Desforges @.>, Author @.> Subject: Re: [phflot/flow_registration] Larger buffer size seems to cause issue (Issue #6)

I have found the bug, it is a problem with boundary handling after binning. Currently, the toolbox needs at least ceil(bin_size / 2) frames for the last binned frame. What behaviour would help you the most or what would you normally do for binning, should we discard the last few frames or average over however many frames are left?

— Reply to this email directly, view it on GitHubhttps://github.com/phflot/flow_registration/issues/6#issuecomment-1125168427, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIHOLZNVOZIWVKLOXY2PBULVJUTJDANCNFSM5VTYB5VA. You are receiving this because you authored the thread.Message ID: @.***>

phflot commented 2 years ago

The bug is fixed with the latest commit, could you let me know if the behaviour is not as expected?