Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btrack.utils.segmentation_to_objects fails if you are trying to measure an intensity_image from a single segment #361

Open
nthndy opened this issue Aug 3, 2023 · 0 comments
Labels

Comments

@nthndy
Copy link
Contributor

nthndy commented Aug 3, 2023

I have some images where the associated segmentation may only feature one single segment/object in a frame. I need to extract the intensity_image as a part of the properties parameter of segmentation_to_objects so that I can do some extra measurements before removing this property from all the objects prior to tracking. However, when iterating over all my frames I noticed that segmentation_to_objects fails on the frames where there is just a single mask/segment. Here's the full error message:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [37], in <cell line: 11>()
      2 props = ('axis_major_length',
      3          'axis_minor_length',
      4          'eccentricity',
   (...)
      7          'mean_intensity',
      8          'intensity_image')
     10 # localise all cells in image stack
---> 11 objects = btrack.utils.segmentation_to_objects(
     12                                                segmentation = mask_stack, # set the masks here 
     13                                                intensity_image = image, # provide the image so that the mean intensity can be measured
     14                                                properties = props, # provide the cell properties to improve tracker 
     15                                                use_weighted_centroid = False, 
     16 #                                                    assign_class_ID=True,
     17                                                )

File ~/analysis/btrack/btrack/io/_localization.py:290, in segmentation_to_objects(segmentation, intensity_image, properties, extra_properties, scale, use_weighted_centroid, assign_class_ID, num_workers)
    288     for data in tqdm(container, total=len(container), position=0):
    289         _nodes = processor(data)
--> 290         nodes = _concat_nodes(nodes, _nodes)
    291 else:
    292     logger.info(f"Processing using {num_workers} workers.")

File ~/analysis/btrack/btrack/io/_localization.py:34, in _concat_nodes(nodes, new_nodes)
     31 """Concatentate centroid dictionaries."""
     32 for key, values in new_nodes.items():
     33     nodes[key] = (
---> 34         np.concatenate([nodes[key], values]) if key in nodes else values
     35     )
     36 return nodes

File <__array_function__ internals>:180, in concatenate(*args, **kwargs)

ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 4 dimension(s) and the array at index 1 has 1 dimension(s)

I think it might be important to note that this is specific to the intensity_image parameter and that if I remove that property it can still manage the non-scalar mean_intensity parameter.

Setup:
btrack.SystemInformation() output:

btrack_version: 0.6.1.dev30
system_platform: Linux-5.15.0-76-generic-x86_64-with-glibc2.31
system_python: 3.9.12
@nthndy nthndy added the bug label Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant