コード例 #1
0
 def initGraph(self):
     shape = self.inputProvider.outputs["Output"].shape
     srcs    = []
     minMax = []
     normalize = []
     
     print "* Data has shape=%r" % (shape,)
     
     #create a layer for each channel of the input:
     slicer=OpMultiArraySlicer2(self.g)
     slicer.inputs["Input"].connect(self.inputProvider.outputs["Output"])
     slicer.inputs["AxisFlag"].setValue('c')
    
     nchannels = shape[-1]
     for ich in xrange(nchannels):
         data=slicer.outputs['Slices'][ich][:].allocate().wait()
         #find the minimum and maximum value for normalization
         mm = (numpy.min(data), numpy.max(data))
         print "  - channel %d: min=%r, max=%r" % (ich, mm[0], mm[1])
         minMax.append(mm)
         if self._normalize_data:
             normalize.append(mm)
         else:
             normalize.append((0,255))
         layersrc = LazyflowSource(slicer.outputs['Slices'][ich], priority = 100)
         layersrc.setObjectName("raw data channel=%d" % ich)
         srcs.append(layersrc)
         
     #FIXME: we shouldn't merge channels automatically, but for now it's prettier
     layer1 = None
     if nchannels == 1:
         layer1 = GrayscaleLayer(srcs[0], range=minMax[0], normalize=normalize[0])
         print "  - showing raw data as grayscale"
     elif nchannels==2:
         layer1 = RGBALayer(red  = srcs[0], normalizeR=normalize[0],
                            green = srcs[1], normalizeG=normalize[1], range=minMax[0:2]+[(0,255), (0,255)])
         print "  - showing channel 1 as red, channel 2 as green"
     elif nchannels==3:
         layer1 = RGBALayer(red   = srcs[0], normalizeR=normalize[0],
                            green = srcs[1], normalizeG=normalize[1],
                            blue  = srcs[2], normalizeB=normalize[2],
                            range = minMax[0:3])
         print "  - showing channel 1 as red, channel 2 as green, channel 3 as blue"
     else:
         print "only 1,2 or 3 channels supported so far"
         return
     print
     
     layer1.name = "Input data"
     layer1.ref_object = None
     self.layerstack.append(layer1)
     
     opImageList = Op5ToMulti(self.g)    
     opImageList.inputs["Input0"].connect(self.inputProvider.outputs["Output"])
     
     #init the features operator
     opPF = OpPixelFeaturesPresmoothed(self.g)
     opPF.inputs["Input"].connect(opImageList.outputs["Outputs"])
     opPF.inputs["Scales"].setValue(self.featScalesList)
     self.opPF=opPF
     
     #Caches the features
     opFeatureCache = OpBlockedArrayCache(self.g)
     opFeatureCache.inputs["innerBlockShape"].setValue((1,32,32,32,16))
     opFeatureCache.inputs["outerBlockShape"].setValue((1,128,128,128,64))
     opFeatureCache.inputs["Input"].connect(opPF.outputs["Output"])
     opFeatureCache.inputs["fixAtCurrent"].setValue(False)  
     self.opFeatureCache=opFeatureCache
     
     
     self.initLabels()
     self.dataReadyToView.emit()
コード例 #2
0
    def initGraph(self):
        shape = self.inputProvider.outputs["Output"].shape
        srcs    = []
        minMax = []
        
        print "* Data has shape=%r" % (shape,)
        
        #create a layer for each channel of the input:
        slicer=OpMultiArraySlicer2(self.g)
        slicer.inputs["Input"].connect(self.inputProvider.outputs["Output"])
        
        slicer.inputs["AxisFlag"].setValue('c')
       
        nchannels = shape[-1]
        for ich in xrange(nchannels):
            if self._normalize_data:
                data=slicer.outputs['Slices'][ich][:].allocate().wait()
                #find the minimum and maximum value for normalization
                mm = (numpy.min(data), numpy.max(data))
                print "  - channel %d: min=%r, max=%r" % (ich, mm[0], mm[1])
                minMax.append(mm)
            else:
                minMax.append(None)
            layersrc = LazyflowSource(slicer.outputs['Slices'][ich], priority = 100)
            layersrc.setObjectName("raw data channel=%d" % ich)
            srcs.append(layersrc)
            
        #FIXME: we shouldn't merge channels automatically, but for now it's prettier
        layer1 = None
        if nchannels == 1:
            layer1 = GrayscaleLayer(srcs[0], normalize=minMax[0])
            layer1.set_range(0,minMax[0])
            print "  - showing raw data as grayscale"
        elif nchannels==2:
            layer1 = RGBALayer(red  = srcs[0], normalizeR=minMax[0],
                               green = srcs[1], normalizeG=minMax[1])
            layer1.set_range(0, minMax[0])
            layer1.set_range(1, minMax[1])
            print "  - showing channel 1 as red, channel 2 as green"
        elif nchannels==3:
            layer1 = RGBALayer(red   = srcs[0], normalizeR=minMax[0],
                               green = srcs[1], normalizeG=minMax[1],
                               blue  = srcs[2], normalizeB=minMax[2])
            layer1.set_range(0, minMax[0])
            layer1.set_range(1, minMax[1])
            layer1.set_range(2, minMax[2])
            print "  - showing channel 1 as red, channel 2 as green, channel 3 as blue"
        else:
            print "only 1,2 or 3 channels supported so far"
            return
        print
        
        layer1.name = "Input data"
        layer1.ref_object = None
        self.layerstack.append(layer1)
 
        self.workflow = PixelClassificationLazyflow( self.g, self.featScalesList, self.inputProvider.outputs["Output"])

        self.initLabels()
        self.startClassification()
        self.dataReadyToView.emit()