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

Added Accessor method to handle YX cropping

parent 8ecc14be
No related branches found
No related tags found
No related merge requests found
......@@ -85,6 +85,15 @@ class GenericImageDataAccessor(ABC):
def _ga(self, arg):
return self.get_axis(arg)
def crop_hw(self, yxhw: tuple):
"""
Return subset of data cropped in X and Y
:param yxhw: tuple (Y, X, H, W)
:return: InMemoryDataAccessor of size (H x W), starting at (Y, X)
"""
y, x, h, w = yxhw
return InMemoryDataAccessor(self.data[y: (y + h), x: (x + w), :, :])
@property
def hw(self):
"""
......
......@@ -73,6 +73,19 @@ class TestCziImageFileAccess(unittest.TestCase):
self.assertTrue(np.all(sz.data[:, :, :, 0] == cf.data[:, :, :, zi]))
def test_crop_yx(self):
w = 256
h = 512
nc = 4
nz = 11
cf = InMemoryDataAccessor(_random_int(h, w, nc, nz))
yxhw = (100, 200, 10, 20)
sc = cf.crop_hw(yxhw)
self.assertEqual(sc.shape_dict['Z'], nz)
self.assertEqual(sc.shape_dict['C'], nc)
self.assertEqual(sc.hw, yxhw[2:])
def test_write_single_channel_tif(self):
ch = 4
cf = CziImageFileAccessor(data['czifile']['path'])
......
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