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

Added alternate constructor for RoiSet from either YX or YXZ monochromatic data

parent adc4795d
No related branches found
No related tags found
No related merge requests found
......@@ -223,6 +223,15 @@ class InMemoryDataAccessor(GenericImageDataAccessor):
self._data = self.conform_data(data)
self.lazy = False
@classmethod
def from_mono(cls, data):
if len(data.shape) == 2: # interpret as YX
return cls(np.expand_dims(data, (2, 3)))
if len(data.shape) == 3:
return cls(np.expand_dims(data, 2))
else:
raise InvalidDataShape(f'Expecting either YX or YXZ monochromatic data')
class GenericImageFileAccessor(GenericImageDataAccessor): # image data is loaded from a file
def __init__(self, fpath: Path, lazy=False):
"""
......
......@@ -114,6 +114,25 @@ class TestCziImageFileAccess(unittest.TestCase):
acc = InMemoryDataAccessor(_random_int(h, w, nc, nz))
self.assertEqual(acc.get_mono(0).data_mono.shape, (h, w, nz))
def test_make_from_mono_2d(self):
w = 256
h = 512
nda = _random_int(h, w)
acc = InMemoryDataAccessor.from_mono(nda)
self.assertEqual(acc.chroma, 1)
self.assertEqual(acc.hw, (h, w))
self.assertEqual(acc.nz, 1)
def test_make_from_mono_3d(self):
w = 256
h = 512
nz = 11
nda = _random_int(h, w, nz)
acc = InMemoryDataAccessor.from_mono(nda)
self.assertEqual(acc.chroma, 1)
self.assertEqual(acc.hw, (h, w))
self.assertEqual(acc.nz, nz)
def test_crop_yx(self):
w = 256
h = 512
......@@ -320,8 +339,8 @@ class TestPatchStackAccessor(unittest.TestCase):
# test that this persists after channel selection
for i in range(0, acc.count):
self.assertEqual(patches[i].shape[0:2], acc.get_channels([0]).iat_data(i, crop=True).shape[0:2])
self.assertEqual(patches[i].shape[3], acc.get_channels([0]).iat_data(i, crop=True).shape[3])
self.assertEqual(patches[i].shape[0:2], acc.get_channels([0]).iat(i, crop=True).shape[0:2])
self.assertEqual(patches[i].shape[3], acc.get_channels([0]).iat(i, crop=True).shape[3])
def test_write_nonuniform_patches(self):
w = 256
......
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