def test_get_index(): """ Test getting indexing from LayerList """ layers = LayerList() layer_a = Image(np.random.random((10, 10)), name='image_a') layer_b = Image(np.random.random((15, 15)), name='image_b') layers.append(layer_a) layers.append(layer_b) assert layers.index(layer_a) == 0 assert layers.index('image_a') == 0 assert layers.index(layer_b) == 1 assert layers.index('image_b') == 1
def _duplicate_layer(ll: LayerList): from copy import deepcopy for lay in list(ll.selection): new = deepcopy(lay) new.name += ' copy' ll.insert(ll.index(lay) + 1, new)
def _convert(ll: LayerList, type_: str): from .base.base import Layer for lay in list(ll.selection): idx = ll.index(lay) data = lay.data.astype(int) if type_ == 'labels' else lay.data ll.pop(idx) ll.insert(idx, Layer.create(data, {'name': lay.name}, type_))