def test_briconToDisplayRange(): tests = list(it.product(np.linspace(0, 1, 5), np.linspace(0, 1, 5))) # bricon of 0.5/0.5 should result in a # display range equal to the data range assert fslcm.briconToDisplayRange((0, 100), 0.5, 0.5) == (0, 100) for inbri, incon in tests: dmin, dmax = fslcm.briconToDisplayRange((0, 100), inbri, incon) outbri, outcon = fslcm.displayRangeToBricon((0, 100), (dmin, dmax)) assert np.all(np.isclose((inbri, incon), (outbri, outcon)))
def getVectorColours(self): """Prepares the colours that represent each direction. Returns: - a ``numpy`` array of size ``(3, 4)`` containing the RGBA colours that correspond to the ``x``, ``y``, and ``z`` vector directions. - A ``numpy`` array of shape ``(4, 4)`` which encodes a scale and offset to be applied to the vector value before it is combined with the colours, encoding the current brightness and contrast settings. """ display = self.display opts = self.opts bri = display.brightness / 100.0 con = display.contrast / 100.0 alpha = display.alpha / 100.0 colours = np.array([opts.xColour, opts.yColour, opts.zColour]) colours[:, 3] = alpha if opts.suppressMode == 'white': suppress = [1, 1, 1, alpha] elif opts.suppressMode == 'black': suppress = [0, 0, 0, alpha] elif opts.suppressMode == 'transparent': suppress = [0, 0, 0, 0] # Transparent suppression if opts.suppressX: colours[0, :] = suppress if opts.suppressY: colours[1, :] = suppress if opts.suppressZ: colours[2, :] = suppress # Scale/offset for brightness/contrast. # Note: This code is a duplicate of # that found in ColourMapTexture. lo, hi = fslcm.briconToDisplayRange((0, 1), bri, con) if hi == lo: scale = 0.0000000000001 else: scale = hi - lo xform = np.identity(4, dtype=np.float32) xform[0, 0] = 1.0 / scale xform[0, 3] = -lo * xform[0, 0] return colours, xform
def __briconChanged(self, *a): """Called when the ``brightness``/``contrast`` properties of the :class:`.Display` instance change. Updates the :attr:`displayRange` property accordingly. See :func:`.colourmaps.briconToDisplayRange`. """ dataRange = self.getDataRange() dlo, dhi = fslcm.briconToDisplayRange(dataRange, self.display.brightness / 100.0, self.display.contrast / 100.0) self.__toggleListeners(False) self.displayRange.x = [dlo, dhi] self.__toggleListeners(True)
def refreshColourMapTexture(self, colourRes=256): """Called when the component colour maps need to be updated, when one of the :attr:`.VectorOpts.xColour`, ``yColour``, ``zColour``, ``cmap``, ``suppressX``, ``suppressY``, or ``suppressZ`` properties change. Regenerates the colour map texture. """ display = self.display opts = self.opts if self.colourImage is not None: dmin, dmax = self.colourImage.dataRange else: dmin, dmax = 0.0, 1.0 dmin, dmax = fslcm.briconToDisplayRange( (dmin, dmax), display.brightness / 100.0, display.contrast / 100.0) self.cmapTexture.set(cmap=opts.cmap, alpha=display.alpha / 100.0, displayRange=(dmin, dmax))