def _add_color_layer(self, data, name=None, visible=False): ''' adds a color layer to the layerstack :param data: numpy array (2D, c) containing the data (c is color) :param name: name of layer :param visible: bool determining whether this layer should be set to visible :return: ''' assert len(data.shape) == 3 data_sources = [] for i in range(data.shape[2]): a, data_shape = createDataSource(data[:, :, i], True) data_sources.append(a) self.editor.dataShape = list(data_shape) if data.shape[2] == 2: new_layer = RGBALayer(data_sources[0], data_sources[1]) elif data.shape[2] == 3: new_layer = RGBALayer(data_sources[0], data_sources[1], data_sources[2]) elif data.shape[2] == 4: new_layer = RGBALayer(data_sources[0], data_sources[1], data_sources[2], data_sources[3]) else: raise Exception("Unexpected number of colors") new_layer.visible = visible if name is not None: new_layer.name = name self.layerstack.append(new_layer)
def _add_color_layer(self, data, name=None, visible=False): ''' adds a color layer to the layerstack :param data: numpy array (2D, c) containing the data (c is color) :param name: name of layer :param visible: bool determining whether this layer should be set to visible :return: ''' assert len(data.shape) == 3 data_sources = [] for i in range(data.shape[2]): a, data_shape = createDataSource(data[:,:,i], True) data_sources.append(a) self.editor.dataShape = list(data_shape) if data.shape[2] == 2: new_layer = RGBALayer(data_sources[0], data_sources[1]) elif data.shape[2] == 3: new_layer = RGBALayer(data_sources[0], data_sources[1], data_sources[2]) elif data.shape[2] == 4: new_layer = RGBALayer(data_sources[0], data_sources[1], data_sources[2], data_sources[3]) else: raise Exception("Unexpected number of colors") new_layer.visible = visible if name is not None: new_layer.name = name self.layerstack.append(new_layer)
def test_numpyArraySource(self): for i in range(2, 6): array = rand(*self.dim[:i]) source = createDataSource(array) self.assertEqual(type(source), ArraySource, 'Resulting datatype is not as expected') self.assertEqual( squeeze(ndarray(source._array.shape)).shape, array.shape, 'Inputdatashape does not match outputdatashape')
def test_lazyflowSource(self): if hasLazyflow: import vigra def test_source( src, array ): self.assertEqual(type(src), LazyflowSource) self.assertEqual(squeeze(ndarray(src._op5.Output.meta.shape)).shape, array.shape) for i in range(2,6): array = rand(*self.dim[:i]).view(vigra.VigraArray) array.axistags = vigra.defaultAxistags('txyzc'[:i]) self.op.inputs["Input"].setValue(array) source_output = createDataSource(self.op.Output) test_source( source_output, array ) source_input = createDataSource(self.op.Input) test_source( source_input, array ) else: pass
def test_lazyflowSource(self): if hasLazyflow: import vigra def test_source( src, array ): self.assertEqual(type(src), LazyflowSource) self.assertEqual(squeeze(ndarray(src._op5.Output.meta.shape)).shape, array.shape) for i in range(2,6): array = rand(*self.dim[:i]).view(vigra.VigraArray) array.axistags = vigra.defaultAxistags('txyzc'[:i]) self.op.inputs["Input"].setValue(array) source_output = createDataSource(self.op.Output) test_source( source_output, array ) source_input = createDataSource(self.op.Input) test_source( source_input, array ) else: pass
def test_numpyArraySource(self): for i in range(2, 6): array = rand(*self.dim[:i]) source = createDataSource(array) self.assertEqual(type(source), ArraySource, "Resulting datatype is not as expected") self.assertEqual( squeeze(ndarray(source._array.shape)).shape, array.shape, "Inputdatashape does not match outputdatashape", )
def test_lazyflowSource(self): if hasLazyflow: import vigra for i in range(2,6): array = rand(*self.dim[:i]).view(vigra.VigraArray) array.axistags = vigra.defaultAxistags('txyzc'[:i]) self.op.inputs["Input"].setValue(array) source = createDataSource(self.op.outputs["Output"]) self.assertEqual(type(source), LazyflowSource, 'Resulting datatype is not as expected') self.assertEqual(squeeze(ndarray(source._op5.output.meta.shape)).shape, array.shape, 'Inputdatashape does not match outputdatashape') else: pass
def test_lazyflow_tagged_shape_embedding(lazyflow_op, vigra, dims, expected_shape, transpose): shape = select(DIMS, dims) len_ = np.product(shape) array = np.array(range(len_)).reshape(shape).view(vigra.VigraArray) array.axistags = vigra.defaultAxistags(dims) lazyflow_op.Input.setValue(array) src = factories.createDataSource(lazyflow_op.Input) assert isinstance(src, ds.LazyflowSource) assert src._op5.Output.meta.shape == expected_shape outsrc = factories.createDataSource(lazyflow_op.Output) assert isinstance(outsrc, ds.LazyflowSource) assert outsrc._op5.Output.meta.shape == expected_shape src_array = outsrc.request(np.s_[:, :, :, :, :]).wait() expected_array = np.array(array[:]).transpose(*transpose) expected_array.shape = src_array.shape assert_array_equal(expected_array, src_array)
def test_array_untagged_shape_embedding(make_source, shape, expected_shape): array = make_source(shape) source, src_shape = factories.createDataSource(array, True) assert isinstance(source, ds.ArraySource) assert np.squeeze(np.ndarray(source._array.shape)).shape == array.shape assert src_shape == expected_shape src_array = source.request(np.s_[:, :, :, :, :]).wait() array = array[:] array.shape = src_array.shape assert_array_equal(array, src_array)
def _add_grayscale_layer(self, data, name=None, visible=False): ''' adds a grayscale layer to the layerstack :param data: numpy array (2D) containing the data :param name: name of layer :param visible: bool determining whether this layer should be set to visible :return: ''' #assert len(data.shape) == 2 a, data_shape = createDataSource(data, True) self.editor.dataShape = list(data_shape) new_layer = GrayscaleLayer(a) new_layer.visible = visible if name is not None: new_layer.name = name self.layerstack.append(new_layer)
def _add_grayscale_layer(self, data, name=None, visible=False): ''' adds a grayscale layer to the layerstack :param data: numpy array (2D) containing the data :param name: name of layer :param visible: bool determining whether this layer should be set to visible :return: ''' #assert len(data.shape) == 2 a, data_shape = createDataSource(data, True) self.editor.dataShape = list(data_shape) new_layer = GrayscaleLayer(a) new_layer.visible = visible if name is not None: new_layer.name = name self.layerstack.append(new_layer)
def _add_segmentation_layer(self, data, name=None, visible=False): ''' adds a segementation layer to the layerstack :param data: numpy array (2D) containing the data :param name: name of layer :param visible: bool determining whether this layer should be set to visible :return: ''' assert len(data.shape) == 2 a, data_shape = createDataSource(data, True) self.editor.dataShape = list(data_shape) new_layer = ColortableLayer(a, self.colortable) new_layer.visible = visible new_layer.opacity = 0.5 if name is not None: new_layer.name = name self.layerstack.append(new_layer)
def _add_segmentation_layer(self, data, name=None, visible=False): ''' adds a segementation layer to the layerstack :param data: numpy array (2D) containing the data :param name: name of layer :param visible: bool determining whether this layer should be set to visible :return: ''' assert len(data.shape) == 2 a, data_shape = createDataSource(data, True) self.editor.dataShape = list(data_shape) new_layer = ColortableLayer(a, self.colortable) new_layer.visible = visible new_layer.opacity = 0.5 if name is not None: new_layer.name = name self.layerstack.append(new_layer)