def test_stack_to_images_1_channel(): """Split when only one channel""" data = np.random.randint(0, 100, (10, 1, 128, 128)) stack = Image(data) images = stack_to_images(stack, 1, colormap=['magma']) assert isinstance(images, list) assert len(images) == 1 for i in images: assert i.rgb is False assert type(stack) == type(i) assert i.data.shape == (10, 128, 128)
def test_stack_to_images_0_rgb(): """Split RGB along the first axis (z or t) so the images remain rgb""" data = np.random.randint(0, 100, (10, 128, 128, 3)) stack = Image(data) images = stack_to_images(stack, 0, colormap=None) assert isinstance(images, list) assert len(images) == 10 for i in images: assert i.rgb assert type(stack) == type(i) assert i.data.shape == (128, 128, 3)
def test_stack_to_images_4_channels(): """Test 4x128x128 stack is split into 4 channels w/ colormap keyword""" data = np.random.randint(0, 100, (4, 128, 128)) stack = Image(data) images = stack_to_images(stack, 0, colormap=['red', 'blue']) assert isinstance(images, list) assert len(images) == 4 assert images[-2].colormap.name == 'red' for i in images: assert type(stack) == type(i) assert i.data.shape == (128, 128)
def test_stack_to_images_basic(): """Test that a 2 channel zcyx stack is split into 2 image layers""" data = np.random.randint(0, 100, (10, 2, 128, 128)) stack = Image(data) images = stack_to_images(stack, 1, colormap=None) assert isinstance(images, list) assert images[0].colormap.name == 'magenta' assert len(images) == 2 for i in images: assert type(stack) == type(i) assert i.data.shape == (10, 128, 128)
def test_stack_to_images_rgb(): """Test 3 channel RGB image (channel axis = -1) into single channels.""" data = np.random.randint(0, 100, (10, 128, 128, 3)) stack = Image(data) images = stack_to_images(stack, -1, colormap=None) assert isinstance(images, list) assert len(images) == 3 for i in images: assert type(stack) == type(i) assert i.data.shape == (10, 128, 128) assert i.scale.shape == (3, ) assert i.rgb is False
def test_stack_to_images_multiscale(): """Test that a 3 channel multiscale image returns 3 multiscale images.""" data = list() data.append(np.random.randint(0, 200, (3, 128, 128))) data.append(np.random.randint(0, 200, (3, 64, 64))) data.append(np.random.randint(0, 200, (3, 32, 32))) data.append(np.random.randint(0, 200, (3, 16, 16))) stack = Image(data) images = stack_to_images(stack, 0) assert len(images) == 3 assert len(images[0].data) == 4 assert images[0].data[-1].shape[-1] == 16 assert images[1].data[-1].shape[-1] == 16 assert images[2].data[-1].shape[-1] == 16