Repository: scikit-image/scikit-image

Issue:
`measure._regionprops._infer_region_props_dtype` does not account for regions of different sizes
### Description:

There is a chance I'm holding this wrong. I was just trying to add an extra property to my regions that would compute the pixelwise mean along an axis. The length of the property will always be equal to the dimension of the bounding box along that axis.  Since the regions are not the same size, this property ends up having varying length. 

From the notes of `_props_to_dict` I get the impression that this should be possible.

>     For multidimensional properties that don't have a fixed size, such as
>     "image" (the image of a region varies in size depending on the region
>     size), an object array will be used, with the corresponding property name
>     as the key.

But something is stange with the `_infer_regionprop_dtype` test because I keep getting index out of range error so it is not set as an object array. I think because the test is using regionsmasks of the same size it never gets varying lengths property for my edge case property. 

Note: this is fine with `regionprops` it just seems to be an issue with making the dictionary. 

### Way to reproduce:

```python
import numpy as np
from skimage.measure import regionprops, regionprops_table, label
from skimage import data

image = data.coins()

def bbox_length_property(regionmask):
        return [0] * regionmask.shape[1]

label_image = label( image > 110)
table_props = regionprops_table(label_image,
                                intensity_image=image,
                                extra_properties=(bbox_length_property, ),
                            )
```

```bash
<python3.8 path>\lib\site-packages\skimage\measure\_regionprops.py", line 878, in _props_to_dict
    column_data[k, i] = rp[loc]
IndexError: list index out of range
```

### Version information:

```Shell
3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]
Windows-10-10.0.19045-SP0
scikit-image version: 0.20.0
numpy version: 1.24.4
```



Discussion:

Resolving patch:
diff --git a/skimage/measure/_regionprops.py b/skimage/measure/_regionprops.py
--- a/skimage/measure/_regionprops.py
+++ b/skimage/measure/_regionprops.py
@@ -194,17 +194,17 @@ def _infer_regionprop_dtype(func, *, intensity, ndim):
     dtype : NumPy data type
         The data type of the returned property.
     """
-    labels = [1, 2]
-    sample = np.zeros((3,) * ndim, dtype=np.intp)
-    sample[(0,) * ndim] = labels[0]
-    sample[(slice(1, None),) * ndim] = labels[1]
-    propmasks = [(sample == n) for n in labels]
+    mask_1 = np.ones((1,) * ndim, dtype=bool)
+    mask_1 = np.pad(mask_1, (0, 1), constant_values=False)
+    mask_2 = np.ones((2,) * ndim, dtype=bool)
+    mask_2 = np.pad(mask_2, (1, 0), constant_values=False)
+    propmasks = [mask_1, mask_2]
 
     rng = np.random.default_rng()
 
     if intensity and _infer_number_of_required_args(func) == 2:
         def _func(mask):
-            return func(mask, rng.random(sample.shape))
+            return func(mask, rng.random(mask.shape))
     else:
         _func = func
     props1, props2 = map(_func, propmasks)


Test patch:
diff --git a/skimage/measure/tests/test_regionprops.py b/skimage/measure/tests/test_regionprops.py
--- a/skimage/measure/tests/test_regionprops.py
+++ b/skimage/measure/tests/test_regionprops.py
@@ -1280,6 +1280,11 @@ def intensity_median(regionmask, image_intensity):
     return np.median(image_intensity[regionmask])
 
 
+def bbox_list(regionmask):
+    """Extra property whose output shape is dependent on mask shape."""
+    return [1] * regionmask.shape[1]
+
+
 def too_many_args(regionmask, image_intensity, superfluous):
     return 1
 
@@ -1337,14 +1342,19 @@ def test_extra_properties_mixed():
 
 
 def test_extra_properties_table():
-    out = regionprops_table(SAMPLE_MULTIPLE,
-                            intensity_image=INTENSITY_SAMPLE_MULTIPLE,
-                            properties=('label',),
-                            extra_properties=(intensity_median, pixelcount)
-                            )
+    out = regionprops_table(
+        SAMPLE_MULTIPLE,
+        intensity_image=INTENSITY_SAMPLE_MULTIPLE,
+        properties=('label',),
+        extra_properties=(intensity_median, pixelcount, bbox_list)
+    )
     assert_array_almost_equal(out['intensity_median'], np.array([2., 4.]))
     assert_array_equal(out['pixelcount'], np.array([10, 2]))
 
+    assert out['bbox_list'].dtype == np.object_
+    assert out["bbox_list"][0] == [1] * 10
+    assert out["bbox_list"][1] == [1] * 1
+
 
 def test_multichannel():
     """Test that computing multichannel properties works."""