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 testOpaqueness(self): ims_opaque = RGBAImageSource(self.red, self.green, self.blue, ConstantSource(), RGBALayer(self.red, self.green, self.blue, alpha_missing_value=255), guarantees_opaqueness=True) self.assertTrue(ims_opaque.isOpaque()) ims_notopaque = RGBAImageSource( self.red, self.green, self.blue, ConstantSource(), RGBALayer(self.red, self.green, self.blue, alpha_missing_value=100)) self.assertFalse(ims_notopaque.isOpaque())
def setUp(self): super(RGBAImageSourceTest, self).setUp() basedir = os.path.dirname(volumina._testing.__file__) self.data = numpy.load(os.path.join(basedir, 'rgba129x104.npy')) self.red = _ArraySource2d(self.data[:, :, 0]) self.green = _ArraySource2d(self.data[:, :, 1]) self.blue = _ArraySource2d(self.data[:, :, 2]) self.alpha = _ArraySource2d(self.data[:, :, 3]) self.ims_rgba = RGBAImageSource( self.red, self.green, self.blue, self.alpha, RGBALayer(self.red, self.green, self.blue, self.alpha)) self.ims_rgb = RGBAImageSource( self.red, self.green, self.blue, ConstantSource(), RGBALayer(self.red, self.green, self.blue)) self.ims_rg = RGBAImageSource(self.red, self.green, ConstantSource(), ConstantSource(), RGBALayer(self.red, self.green)) self.ims_ba = RGBAImageSource(red=ConstantSource(), green=ConstantSource(), blue=self.blue, alpha=self.alpha, layer=RGBALayer(blue=self.blue, alpha=self.alpha)) self.ims_a = RGBAImageSource(red=ConstantSource(), green=ConstantSource(), blue=ConstantSource(), alpha=self.alpha, layer=RGBALayer(alpha=self.alpha)) self.ims_none = RGBAImageSource(ConstantSource(), ConstantSource(), ConstantSource(), ConstantSource(), RGBALayer())