def test_regionprops_table(): out = regionprops_table(SAMPLE) assert out == { 'label': array([1]), 'bbox-0': array([0]), 'bbox-1': array([0]), 'bbox-2': array([10]), 'bbox-3': array([18]) } out = regionprops_table(SAMPLE, properties=('label', 'area', 'bbox'), separator='+') assert out == { 'label': array([1]), 'area': array([72]), 'bbox+0': array([0]), 'bbox+1': array([0]), 'bbox+2': array([10]), 'bbox+3': array([18]) } out = regionprops_table(np.zeros((2, 2), dtype=int), properties=('label', 'area', 'bbox'), separator='+') assert len(out) == 6 assert len(out['label']) == 0 assert len(out['area']) == 0 assert len(out['bbox+0']) == 0 assert len(out['bbox+1']) == 0 assert len(out['bbox+2']) == 0 assert len(out['bbox+3']) == 0
def test_regionprops_table(): out = regionprops_table(SAMPLE) assert out == {'label': np.array([1]), 'bbox-0': np.array([0]), 'bbox-1': np.array([0]), 'bbox-2': np.array([10]), 'bbox-3': np.array([18])} out = regionprops_table(SAMPLE, properties=('label', 'area', 'bbox'), separator='+') assert out == {'label': np.array([1]), 'area': np.array([72]), 'bbox+0': np.array([0]), 'bbox+1': np.array([0]), 'bbox+2': np.array([10]), 'bbox+3': np.array([18])}
def test_extra_properties_table(): out = regionprops_table(SAMPLE_MULTIPLE, intensity_image=INTENSITY_SAMPLE_MULTIPLE, properties=('label', ), extra_properties=(intensity_median, pixelcount)) assert_array_almost_equal(out['intensity_median'], np.array([2., 4.])) assert_array_equal(out['pixelcount'], np.array([10, 2]))
def test_regionprops_table_equal_to_original(): regions = regionprops(SAMPLE, INTENSITY_FLOAT_SAMPLE) out_table = regionprops_table(SAMPLE, INTENSITY_FLOAT_SAMPLE, properties=COL_DTYPES.keys()) for prop in COL_DTYPES.keys(): for i in range(len(regions)): if not isinstance(regions[i][prop], Iterable): assert regions[i][prop] == out_table[prop][i]
def test_regionprops_table_no_regions(): out = regionprops_table(np.zeros((2, 2), dtype=int), properties=('label', 'area', 'bbox'), separator='+') assert len(out) == 6 assert len(out['label']) == 0 assert len(out['area']) == 0 assert len(out['bbox+0']) == 0 assert len(out['bbox+1']) == 0 assert len(out['bbox+2']) == 0 assert len(out['bbox+3']) == 0
def test_regionprops_table_equal_to_original(): regions = regionprops(SAMPLE, INTENSITY_FLOAT_SAMPLE) out_table = regionprops_table(SAMPLE, INTENSITY_FLOAT_SAMPLE, properties=COL_DTYPES.keys()) for prop, dtype in COL_DTYPES.items(): for i, reg in enumerate(regions): rp = reg[prop] if np.isscalar(rp) or \ prop in OBJECT_COLUMNS or \ dtype is np.object_: assert_array_equal(rp, out_table[prop][i]) else: shape = rp.shape if isinstance(rp, np.ndarray) else (len(rp),) for ind in np.ndindex(shape): modified_prop = "-".join(map(str, (prop,) + ind)) loc = ind if len(ind) > 1 else ind[0] assert_equal(rp[loc], out_table[modified_prop][i])
def test_regionprops_table_deprecated_scalar_property(): out = regionprops_table(SAMPLE, properties=('bbox_area', )) assert list(out.keys()) == ['bbox_area']
def test_regionprops_table_deprecated_vector_property(): out = regionprops_table(SAMPLE, properties=('local_centroid', )) for key in out.keys(): # key reflects the deprecated name, not its new (centroid_local) value assert key.startswith('local_centroid')