quantumjot / btrack

Bayesian multi-object tracking
https://btrack.readthedocs.io
MIT License
310 stars 50 forks source link

[BUG] configuration volume is None #396

Closed remyeltorro closed 3 months ago

remyeltorro commented 10 months ago

Hello,

I encountered a bug when migrating from bTrack 0.6.3 to 0.6.4 in the method tracker.to_napari(). Before, I could get away with not setting the tracker volume as setting it created some sort of bug, with for example:

 tracker.volume = ((0,volume[0]), (0,volume[1]), (-1e5, 1e5)) 

used to give weird ghost points in the trajectories (I suppose a problem of interpretation of 3D points in a 2D image, I don't know if it was a problem with my line or a bug). Anyway, I had no problem by not writing this line above.

With the new version 0.6.4, I get the following error when not setting the volume:

  File "<stdin>", line 9, in <module>
  File "/home/limozin/anaconda3/envs/btrack_last/lib/python3.11/site-packages/btrack/core.py", line 670, in to_napari
    assert self.configuration.volume is not None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The assertion in to_napari prevents me from using the default parameter (which is the following line in to_napari(). I'm not sure if this behavior is intended or not, maybe setting the volume has always been mandatory but I used to do it wrong or there was a problem in 0.6.3 that has been fixed in 0.6.4, provided I set the volume.

As a complement, this was my tracking config made with the napari-btrack plugin:

{
    "name": "cell",
    "version": "0.6.0",
    "verbose": false,
    "motion_model": {
        "measurements": 3,
        "states": 6,
        "A": [
            1.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0
        ],
        "H": [
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            1.0,
            0.0,
            0.0,
            0.0
        ],
        "P": [
            20.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            20.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            20.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            200.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            200.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            200.0
        ],
        "R": [
            5.0,
            0.0,
            0.0,
            0.0,
            5.0,
            0.0,
            0.0,
            0.0,
            5.0
        ],
        "G": [
            7.5,
            7.5,
            7.5,
            15.0,
            15.0,
            15.0
        ],
        "Q": [
            56.25,
            56.25,
            56.25,
            112.5,
            112.5,
            112.5,
            56.25,
            56.25,
            56.25,
            112.5,
            112.5,
            112.5,
            56.25,
            56.25,
            56.25,
            112.5,
            112.5,
            112.5,
            112.5,
            112.5,
            112.5,
            225.0,
            225.0,
            225.0,
            112.5,
            112.5,
            112.5,
            225.0,
            225.0,
            225.0,
            112.5,
            112.5,
            112.5,
            225.0,
            225.0,
            225.0
        ],
        "dt": 1.0,
        "accuracy": 7.5,
        "max_lost": 10,
        "prob_not_assign": 0.01,
        "name": "cell_motion"
    },
    "object_model": null,
    "hypothesis_model": {
        "hypotheses": [
            "P_FP",
            "P_init",
            "P_term",
            "P_link"
        ],
        "lambda_time": 5.0,
        "lambda_dist": 3.0,
        "lambda_link": 12.0,
        "lambda_branch": 50.0,
        "eta": 1e-10,
        "theta_dist": 20.0,
        "theta_time": 5.0,
        "dist_thresh": 150.0,
        "time_thresh": 10.0,
        "apop_thresh": 5,
        "segmentation_miss_rate": 0.05,
        "apoptosis_rate": 0.001,
        "relax": true,
        "name": "cell_hypothesis"
    },
    "max_search_radius": 150.0,
    "return_kalman": false,
    "store_candidate_graph": false,
    "volume": null,
    "update_method": 0,
    "optimizer_options": {
        "tm_lim": 60000
    },
    "features": [],
    "tracking_updates": [
        1
    ]
}

Thank you for your attention,

quantumjot commented 4 months ago

Hey @remyeltorro ,

Thanks for the report!

Just wondering, if you do this:

 tracker.volume = ((0, volume[1]), (0, volume[0]), (-1e5, 1e5)) 

does that get rid of the "ghost points"? btrack takes dimensions as XYZ, whereas most image stacks are ZYX. Also, I'm suprised that the tracking works properly if you set the volume to None. I can remove the line that checks, but that is currently the desired behavior.

remyeltorro commented 3 months ago

Hello @quantumjot, thank you for your reply,

On version 0.6.4, setting the volume works perfectly without creating ghost points,

 tracker.volume = ((0, volume[1]), (0, volume[0]), (-1e5, 1e5)) 

I can also get away with not setting the -z dimension as such (since my data has no -Z dimension):

 tracker.volume = ((0, volume[1]), (0, volume[0])) 

and it works like a charm. I think I just wanted confirmation that setting the volume was mandatory after version 0.6.4. The strange result I noticed was with version 0.6.3 but I migrated to 0.6.4 since then.

You can consider the case closed, Best,