Skip to content
Snippets Groups Projects
Commit f7a56191 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Added height, width fields for convenience

parent 1c543e96
No related branches found
No related tags found
No related merge requests found
......@@ -178,6 +178,8 @@ class RoiSet(object):
# compute expanded bounding boxes
h, w, c, nz = acc_raw.shape
df['h'] = df['y1'] - df['y0']
df['w'] = df['x1'] - df['x0']
ebxy, ebz = expand_box_by
df['ebb_y0'] = (df.y0 - ebxy).apply(lambda x: max(x, 0))
df['ebb_y1'] = (df.y1 + ebxy).apply(lambda x: min(x, h))
......@@ -563,7 +565,7 @@ class RoiSet(object):
# export dataframe and patch masks
record['dataframe'] = self.export_dataframe(where / 'dataframe' / (prefix + '.csv'))
self.export_patch_masks(where / 'patch_masks', prefix=prefix, pad_to=None)
self.export_patch_masks(where / 'tight_patch_masks', prefix=prefix, pad_to=None, expanded=False)
for k in params.dict().keys():
subdir = where / k
......
......@@ -45,7 +45,7 @@ class TestRoiSetMonoProducts(BaseTestRoiSetMonoProducts, unittest.TestCase):
for roi in roiset.get_df().itertuples():
self.assertEqual(roi.binary_mask.dtype, 'bool')
sh = roi.binary_mask.shape
self.assertEqual(sh, (roi.y1 - roi.y0, roi.x1 - roi.x0))
self.assertEqual(sh, (roi.h, roi.w))
self.assertGreaterEqual(sh[0] * sh[1], roi.area)
def test_roi_zmask(self, **kwargs):
......@@ -87,7 +87,7 @@ class TestRoiSetMonoProducts(BaseTestRoiSetMonoProducts, unittest.TestCase):
for roi in roiset:
ma = roi.binary_mask
self.assertEqual(ma.dtype, 'bool')
self.assertEqual(ma.shape, (roi.y1 - roi.y0, roi.x1 - roi.x0))
self.assertEqual(ma.shape, (roi.h, roi.w))
def test_rel_slices_are_valid(self):
roiset = self._make_roi_set()
......@@ -130,9 +130,7 @@ class TestRoiSetMonoProducts(BaseTestRoiSetMonoProducts, unittest.TestCase):
roi_q = df.loc[df.label == la, :]
self.assertEqual(len(roi_q), 1)
roi = roi_q.iloc[0]
h = int(roi.y1 - roi.y0)
w = int(roi.x1 - roi.x0)
self.assertEqual((h, w), acc.hw)
self.assertEqual((roi.h, roi.w), acc.hw)
def test_make_expanded_3d_patches(self):
roiset = self._make_roi_set()
......@@ -218,8 +216,8 @@ class TestRoiSetMonoProducts(BaseTestRoiSetMonoProducts, unittest.TestCase):
h, w, nc, nz = roi.patch_mask.shape
self.assertEqual(nc, 1)
self.assertEqual(nz, 1)
self.assertEqual(h, roi.y1 - roi.y0)
self.assertEqual(w, roi.x1 - roi.x0)
self.assertEqual(h, roi.h)
self.assertEqual(w, roi.w)
class TestRoiSetMultichannelProducts(BaseTestRoiSetMonoProducts, unittest.TestCase):
......@@ -379,25 +377,22 @@ class TestRoiSetFromZmask(unittest.TestCase):
output_path / 'roiset_from_3d',
roiset_test_data['pipeline_params']['segmentation_channel'],
'ref',
params=RoiSetExportParams(patch_masks={'pad_to': 256}, dataframe=True)
params=RoiSetExportParams()
)
where_df = output_path / 'roiset_from_3d' / 'dataframe' / 'ref.csv'
self.assertTrue(where_df.exists())
df_test = pd.read_csv(where_df)
# check that patches are correct size
where_patch_masks = output_path / 'roiset_from_3d' / 'patch_masks'
where_patch_masks = output_path / 'roiset_from_3d' / 'tight_patch_masks'
for pmf in where_patch_masks.iterdir():
self.assertTrue(pmf.suffix.upper() == '.PNG')
la = int(re.search(r'la([\d]+)', str(pmf)).group(1))
roi_q = df_test.loc[df_test.label == la, :]
self.assertEqual(len(roi_q), 1)
roi = roi_q.iloc[0]
h = int(roi.y1 - roi.y0)
w = int(roi.x1 - roi.x0)
m_acc = generate_file_accessor(pmf)
self.assertEqual((h, w), m_acc.hw)
self.assertEqual((roi.h, roi.w), m_acc.hw)
# df_test = pd.read_csv(where_df)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment