コード例 #1
0
ファイル: layerViewerGui.py プロジェクト: shengao01/ilastik
 def _create_grayscale_layer_from_slot(cls, slot, n_channels):
     source = LazyflowSource(slot)
     layer = GrayscaleLayer(source)
     layer.numberOfChannels = n_channels
     layer.set_range(0, slot.meta.drange)
     normalize = cls._should_normalize_display(slot)
     layer.set_normalize(0, normalize)
     return layer
コード例 #2
0
ファイル: layerViewerGui.py プロジェクト: DerThorsten/ilastik
 def _create_grayscale_layer_from_slot(cls, slot, n_channels):
     source = LazyflowSource(slot)
     layer = GrayscaleLayer(source)
     layer.numberOfChannels = n_channels
     layer.set_range(0, slot.meta.drange)
     normalize = cls._should_normalize_display(slot)
     layer.set_normalize( 0, normalize )
     return layer
コード例 #3
0
ファイル: layerViewerGui.py プロジェクト: nashmit/ilastik
 def _create_grayscale_layer_from_slot(cls, slot, n_channels):
     # FIXME: move all of this stuff into the class constructor. Same for all
     # _create_*layer_from_slot methods.
     source = createDataSource(slot)
     layer = GrayscaleLayer(source, window_leveling=True)
     layer.numberOfChannels = n_channels
     layer.set_normalize(0, (slot.meta.normalizeDisplay and slot.meta.drange) or None)
     return layer
コード例 #4
0
ファイル: layerViewerGui.py プロジェクト: ilastik/ilastik
 def _create_grayscale_layer_from_slot(cls, slot, n_channels):
     #FIXME: move all of this stuff into the class constructor. Same for all
     # _create_*layer_from_slot methods.
     source = LazyflowSource(slot)
     layer = GrayscaleLayer(source, window_leveling=True)
     layer.numberOfChannels = n_channels
     layer.set_range(0, slot.meta.drange)
     normalize = cls._should_normalize_display(slot)
     layer.set_normalize( 0, normalize )
     return layer
コード例 #5
0
ファイル: layerViewerGui.py プロジェクト: wolny/ilastik
 def _create_grayscale_layer_from_slot(cls, slot, n_channels):
     #FIXME: move all of this stuff into the class constructor. Same for all
     # _create_*layer_from_slot methods.
     source = LazyflowSource(slot)
     layer = GrayscaleLayer(source, window_leveling=True)
     layer.numberOfChannels = n_channels
     layer.set_range(0, slot.meta.drange)
     normalize = cls._should_normalize_display(slot)
     layer.set_normalize(0, normalize)
     return layer
コード例 #6
0
ファイル: layerViewerGui.py プロジェクト: hanslovsky/ilastik
    def createStandardLayerFromSlot(cls, slot, lastChannelIsAlpha=False):
        """
        Convenience function.
        Generates a volumina layer using the given slot.
        Chooses between grayscale or RGB depending on the number of channels in the slot.

        * If *slot* has 1 channel or more than 4 channels, a GrayscaleLayer is created.
        * If *slot* has 2 non-alpha channels, an RGBALayer is created with R and G channels.
        * If *slot* has 3 non-alpha channels, an RGBALayer is created with R,G, and B channels.
        * If *slot* has 4 channels, an RGBA layer is created

        :param slot: The slot to generate a layer from
        :param lastChannelIsAlpha: If True, the last channel in the slot is assumed to be an alpha channel.
                                   If slot has 4 channels, this parameter has no effect.
        """
        
        def getRange(meta):
            if meta.drange is not None and meta.normalizeDisplay is False:
                # do not normalize if the user provided a range and set normalization to False
                return meta.drange
            else:
                # If we don't know the range of the data and normalization is allowed
                # by the user, create a layer that is auto-normalized.
                # See volumina.pixelpipeline.datasources for details.
                #
                # Even in the case of integer data, which has more than 255 possible values,
                # (like uint16), it seems reasonable to use this setting as default
                return None # means autoNormalize
                   
        shape = slot.meta.shape
        
        try:
            channelAxisIndex = slot.meta.axistags.index('c')
            #assert channelAxisIndex < len(slot.meta.axistags), \
            #    "slot %s has shape = %r, axistags = %r, but no channel dimension" \
            #    % (slot.name, slot.meta.shape, slot.meta.axistags)
            numChannels = shape[channelAxisIndex]
            axisinfo = slot.meta.axistags["c"].description
        except:
            numChannels = 1
            axisinfo = "" # == no info on channels given
        
        rindex = None
        bindex = None
        gindex = None
        aindex = None
        
        if axisinfo == "" or axisinfo == "default":
            # Examine channel dimension to determine Grayscale vs. RGB

            if numChannels == 4:
                lastChannelIsAlpha = True
                
            if lastChannelIsAlpha:
                assert numChannels <= 4, "Can't display a standard layer with more than four channels (with alpha).  Your image has {} channels.".format(numChannels)

            if numChannels == 1 or (numChannels > 4):
                assert not lastChannelIsAlpha, "Can't have an alpha channel if there is no color channel"
                source = LazyflowSource(slot)
                layer = GrayscaleLayer(source)
                layer.numberOfChannels = numChannels
                normalize = getRange(slot.meta)
                layer.set_normalize(0,normalize)
                return layer

            assert numChannels > 2 or (numChannels == 2 and not lastChannelIsAlpha), \
                "Unhandled combination of channels.  numChannels={}, lastChannelIsAlpha={}, axistags={}".format( numChannels, lastChannelIsAlpha, slot.meta.axistags )
            
            rindex = 0
            gindex = 1
            if numChannels > 3 or (numChannels == 3 and not lastChannelIsAlpha):
                bindex = 2
            if lastChannelIsAlpha:
                aindex = numChannels-1
        
        elif axisinfo == "grayscale":
            source = LazyflowSource(slot)
            layer = GrayscaleLayer(source)
            layer.numberOfChannels = numChannels
            normalize = getRange(slot.meta)
            layer.set_normalize(0,normalize)            
            return layer
        
        elif axisinfo == "rgba":
            rindex = 0
            if numChannels>=2:
                gindex = 1
            if numChannels>=3:
                bindex = 2
            if numChannels>=4:
                aindex = numChannels-1
        else:
            raise RuntimeError("unknown channel display mode")

        redSource = None
        if rindex is not None:
            redProvider = OpSingleChannelSelector(parent=slot.getRealOperator().parent)
            redProvider.Input.connect(slot)
            redProvider.Index.setValue( rindex )
            redSource = LazyflowSource( redProvider.Output )
        
        greenSource = None
        if gindex is not None:
            greenProvider = OpSingleChannelSelector(parent=slot.getRealOperator().parent)
            greenProvider.Input.connect(slot)
            greenProvider.Index.setValue( gindex )
            greenSource = LazyflowSource( greenProvider.Output )
        
        blueSource = None
        if bindex is not None:
                blueProvider = OpSingleChannelSelector(parent=slot.getRealOperator().parent)
                blueProvider.Input.connect(slot)
                blueProvider.Index.setValue( bindex )
                blueSource = LazyflowSource( blueProvider.Output )

        alphaSource = None
        if aindex is not None:
            alphaProvider = OpSingleChannelSelector(parent=slot.getRealOperator().parent)
            alphaProvider.Input.connect(slot)
            alphaProvider.Index.setValue( aindex )
            alphaSource = LazyflowSource( alphaProvider.Output )
        
        layer = RGBALayer( red=redSource, green=greenSource, blue=blueSource, alpha=alphaSource)
        

        
        normalize = getRange(slot.meta)
        print "createLayer normalize", normalize
        for i in xrange(4):
            if [redSource,greenSource,blueSource,alphaSource][i]:
                layer.set_normalize(i,normalize)
        return layer
コード例 #7
0
    def createStandardLayerFromSlot(cls, slot, lastChannelIsAlpha=False):
        """
        Convenience function.
        Generates a volumina layer using the given slot.
        Chooses between grayscale or RGB depending on the number of channels in the slot.

        * If *slot* has 1 channel or more than 4 channels, a GrayscaleLayer is created.
        * If *slot* has 2 non-alpha channels, an RGBALayer is created with R and G channels.
        * If *slot* has 3 non-alpha channels, an RGBALayer is created with R,G, and B channels.
        * If *slot* has 4 channels, an RGBA layer is created

        :param slot: The slot to generate a layer from
        :param lastChannelIsAlpha: If True, the last channel in the slot is assumed to be an alpha channel.
                                   If slot has 4 channels, this parameter has no effect.
        """
        def getRange(meta):
            return meta.drange

        def getNormalize(meta):
            if meta.drange is not None and meta.normalizeDisplay is False:
                # do not normalize if the user provided a range and set normalization to False
                return False
            else:
                # If we don't know the range of the data and normalization is allowed
                # by the user, create a layer that is auto-normalized.
                # See volumina.pixelpipeline.datasources for details.
                #
                # Even in the case of integer data, which has more than 255 possible values,
                # (like uint16), it seems reasonable to use this setting as default
                return None  # means autoNormalize

        shape = slot.meta.shape

        try:
            channelAxisIndex = slot.meta.axistags.index('c')
            #assert channelAxisIndex < len(slot.meta.axistags), \
            #    "slot %s has shape = %r, axistags = %r, but no channel dimension" \
            #    % (slot.name, slot.meta.shape, slot.meta.axistags)
            numChannels = shape[channelAxisIndex]
            axisinfo = slot.meta.axistags["c"].description
        except:
            numChannels = 1
            axisinfo = ""  # == no info on channels given

        rindex = None
        bindex = None
        gindex = None
        aindex = None

        if axisinfo == "" or axisinfo == "default":
            # Examine channel dimension to determine Grayscale vs. RGB

            if numChannels == 4:
                lastChannelIsAlpha = True

            if lastChannelIsAlpha:
                assert numChannels <= 4, "Can't display a standard layer with more than four channels (with alpha).  Your image has {} channels.".format(
                    numChannels)

            if numChannels == 1 or (numChannels > 4):
                assert not lastChannelIsAlpha, "Can't have an alpha channel if there is no color channel"
                source = LazyflowSource(slot)
                layer = GrayscaleLayer(source)
                layer.numberOfChannels = numChannels
                normalize = getNormalize(slot.meta)
                range = getRange(slot.meta)
                layer.set_range(0, range)
                layer.set_normalize(0, normalize)
                return layer

            assert numChannels > 2 or (numChannels == 2 and not lastChannelIsAlpha), \
                "Unhandled combination of channels.  numChannels={}, lastChannelIsAlpha={}, axistags={}".format( numChannels, lastChannelIsAlpha, slot.meta.axistags )

            rindex = 0
            gindex = 1
            if numChannels > 3 or (numChannels == 3
                                   and not lastChannelIsAlpha):
                bindex = 2
            if lastChannelIsAlpha:
                aindex = numChannels - 1

        elif axisinfo == "grayscale":
            source = LazyflowSource(slot)
            layer = GrayscaleLayer(source)
            layer.numberOfChannels = numChannels
            normalize = getNormalize(slot.meta)
            range = getRange(slot.meta)
            layer.set_range(0, range)
            layer.set_normalize(0, normalize)
            return layer

        elif axisinfo == "rgba":
            rindex = 0
            if numChannels >= 2:
                gindex = 1
            if numChannels >= 3:
                bindex = 2
            if numChannels >= 4:
                aindex = numChannels - 1
        else:
            raise RuntimeError("unknown channel display mode")

        redSource = None
        if rindex is not None:
            redProvider = OpSingleChannelSelector(
                parent=slot.getRealOperator().parent)
            redProvider.Input.connect(slot)
            redProvider.Index.setValue(rindex)
            redSource = LazyflowSource(redProvider.Output)
            redSource.additional_owned_ops.append(redProvider)

        greenSource = None
        if gindex is not None:
            greenProvider = OpSingleChannelSelector(
                parent=slot.getRealOperator().parent)
            greenProvider.Input.connect(slot)
            greenProvider.Index.setValue(gindex)
            greenSource = LazyflowSource(greenProvider.Output)
            greenSource.additional_owned_ops.append(greenProvider)

        blueSource = None
        if bindex is not None:
            blueProvider = OpSingleChannelSelector(
                parent=slot.getRealOperator().parent)
            blueProvider.Input.connect(slot)
            blueProvider.Index.setValue(bindex)
            blueSource = LazyflowSource(blueProvider.Output)
            blueSource.additional_owned_ops.append(blueProvider)

        alphaSource = None
        if aindex is not None:
            alphaProvider = OpSingleChannelSelector(
                parent=slot.getRealOperator().parent)
            alphaProvider.Input.connect(slot)
            alphaProvider.Index.setValue(aindex)
            alphaSource = LazyflowSource(alphaProvider.Output)
            alphaSource.additional_owned_ops.append(alphaProvider)

        layer = RGBALayer(red=redSource,
                          green=greenSource,
                          blue=blueSource,
                          alpha=alphaSource)

        normalize = getNormalize(slot.meta)
        range = getRange(slot.meta)
        for i in xrange(4):
            if [redSource, greenSource, blueSource, alphaSource][i]:
                layer.set_range(i, range)
                layer.set_normalize(i, normalize)

        return layer