def __init__(self, rag, ndim=3, axis=2): self.rag = rag self.labels = rag.labels self.featureExtractor = graphs.gridRagFeatureExtractor(self.rag, self.labels) self.featureExtractor.labels = self.labels self.featureExtractor.graph = self.rag self.shape = self.labels.shape self.blocking2d = Blocking2d(self.shape[0:2], (40,40)) self.ndim = ndim self.axis = axis assert len(self.shape) == ndim self.nSlices = 1 if ndim == 3: self.nSlices = self.shape[axis] self.sliceDict = None # qt gui self.win = QtGui.QMainWindow() self.win.setWindowTitle('pyqtgraph example: ImageItem') self.win.show() self.win.resize(800, 600) self.cw = QtGui.QWidget() self.cw.setMouseTracking(True) self.win.setCentralWidget(self.cw) self.layout = QtGui.QHBoxLayout() self.layout2 = QtGui.QVBoxLayout() self.cw.setLayout(self.layout) self.gv = pg.GraphicsLayoutWidget() self.gv.scene() self.gv.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding) self.gv.setMouseTracking(True) self.layerCtrl = BvLayerCtrl() self.layout.addLayout(self.layout2) self.layout.addWidget(self.layerCtrl) self.layout2.addWidget(self.gv,3) self.viewBox = BvGridViewBox(blocking2d=self.blocking2d) #self.viewBox.setMouseTracking(True) self.gv.addItem(self.viewBox) self.viewBox.setAspectLocked(True) self.edgeClickLabels = dict() def scrolled(d): if d>0: d=5 else : d=-5 if self.ndim == 3: newSlice = min(self.nSlices-1, self.currentSlice - d) newSlice = max(0, newSlice) self.currentSlice = newSlice with vigra.Timer("scroll"): self.setZ(self.currentSlice) self.viewBox.sigScrolled.connect(scrolled) self.ctrlWidget = DownCtrl() self.ctrlWidget.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum) self.layout2.insertStretch(1,0) self.layout2.addWidget(self.ctrlWidget) self.ctrlWidget.modeSelectorComboBox.currentIndexChanged.connect(self.updatePens) self.ctrlWidget.brushSizeSlider.sliderMoved.connect(self.changeLineSize) self.ctrlWidget.saveLabelsButton.clicked.connect(self.onClickedSaveLabels) self.ctrlWidget.loadLabelsButton.clicked.connect(self.onClickedLoadLabels) self.ctrlWidget.computeFeaturesButton.clicked.connect(self.onClickedComputeFeatures) self.ctrlWidget.saveFeaturesButton.clicked.connect(self.onClickedSaveFeatures) self.ctrlWidget.loadFeaturesButton.clicked.connect(self.onClickedLoadFeatures) self.ctrlWidget.featureGradientWidget.sigGradientChanged.connect(self.onGradientChanged) self.ctrlWidget.trainRfButton.clicked.connect(self.onClickedTrainRf) self.ctrlWidget.predictProbsButton.clicked.connect(self.onClickedPredictProbs) self.ctrlWidget.predictMcButton.clicked.connect(self.onClickedMulticut) self.ctrlWidget.saveRfButton.clicked.connect(self.onClickedSaveRf) self.ctrlWidget.loadRfButton.clicked.connect(self.onClickedLoadRf) self.layerCtrl.sigFeatureSelected.connect(self.onFeatureSelected) self.imgItem = pg.ImageItem(border='w') self.viewBox.addItem(self.imgItem) self.dataDict = dict() self.curves = [] self.allCurves = None self.currentSlice = 0 self.pathHint = None self.currentFeatures = None self.featureMinMax = None self.currentFi = 0 self.rf = None self.probs = None self.nCurves = 0 self.ScrollLock = threading.Lock() self.scrollingIsLocked = False
def makeFeat(rag, raw, labels, show=True): featureExtractor = graphs.gridRagFeatureExtractor(rag, labels) featureExtractor.labels = labels featureExtractor.graph = rag geoFeat = featureExtractor.geometricFeatures() topoFeat = featureExtractor.topologicalFeatures() features = [geoFeat, topoFeat] # ward facs wardness = numpy.array([0.0, 0.1, 0.15, 0.25, 0.5, 1.0], dtype="float32") accFeat = featureExtractor.accumulatedFeatures(raw) features.append(accFeat) for s in [2.0, 3.0, 4.0]: res = vigra.filters.gaussianGradientMagnitude(raw, s) accFeat = featureExtractor.accumulatedFeatures(res) features.append(accFeat) for s in [2.0, 3.0, 4.0]: res = vigra.filters.laplacianOfGaussian(raw, s) accFeat = featureExtractor.accumulatedFeatures(res) features.append(accFeat) for s in [2.0, 3.0, 4.0]: res = vigra.gaussianSmoothing(raw, s) accFeat = featureExtractor.accumulatedFeatures(res) features.append(accFeat) # st ev for s in [2.0, 3.0, 4.0]: res = stEv(raw, s) accFeat = featureExtractor.accumulatedFeatures(res) mean = accFeat[:, 0] ucm = featureExtractor.ucmTransformFeatures(mean[:, None], wardness) features.extend([accFeat, ucm]) if False: for x in range(ucm.shape[1]): rag.showEdgeFeature(raw, ucm[:, x]) vigra.show() # hessian ev for s in [1.0, 3.0, 4.0, 6.0, 8.0]: img = hessianEv2(raw, s, 2.0) # vigra.imshow(img) # vigra.show() accFeat = featureExtractor.accumulatedFeatures(img) mean = accFeat[:, 0] ucm = featureExtractor.ucmTransformFeatures(mean[:, None], wardness) features.extend([accFeat, ucm]) if False: for x in range(ucm.shape[1]): print "x", x rag.showEdgeFeature(raw, ucm[:, x]) vigra.show() # break # features = numpy.concatenate(features, axis=1) return features
def __init__(self, rag, ndim=3, axis=2): self.rag = rag self.labels = rag.labels self.featureExtractor = graphs.gridRagFeatureExtractor( self.rag, self.labels) self.featureExtractor.labels = self.labels self.featureExtractor.graph = self.rag self.shape = self.labels.shape self.blocking2d = Blocking2d(self.shape[0:2], (40, 40)) self.ndim = ndim self.axis = axis assert len(self.shape) == ndim self.nSlices = 1 if ndim == 3: self.nSlices = self.shape[axis] self.sliceDict = None # qt gui self.win = QtGui.QMainWindow() self.win.setWindowTitle('pyqtgraph example: ImageItem') self.win.show() self.win.resize(800, 600) self.cw = QtGui.QWidget() self.cw.setMouseTracking(True) self.win.setCentralWidget(self.cw) self.layout = QtGui.QHBoxLayout() self.layout2 = QtGui.QVBoxLayout() self.cw.setLayout(self.layout) self.gv = pg.GraphicsLayoutWidget() self.gv.scene() self.gv.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding) self.gv.setMouseTracking(True) self.layerCtrl = BvLayerCtrl() self.layout.addLayout(self.layout2) self.layout.addWidget(self.layerCtrl) self.layout2.addWidget(self.gv, 3) self.viewBox = BvGridViewBox(blocking2d=self.blocking2d) #self.viewBox.setMouseTracking(True) self.gv.addItem(self.viewBox) self.viewBox.setAspectLocked(True) self.edgeClickLabels = dict() def scrolled(d): if d > 0: d = 5 else: d = -5 if self.ndim == 3: newSlice = min(self.nSlices - 1, self.currentSlice - d) newSlice = max(0, newSlice) self.currentSlice = newSlice with vigra.Timer("scroll"): self.setZ(self.currentSlice) self.viewBox.sigScrolled.connect(scrolled) self.ctrlWidget = DownCtrl() self.ctrlWidget.setSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum) self.layout2.insertStretch(1, 0) self.layout2.addWidget(self.ctrlWidget) self.ctrlWidget.modeSelectorComboBox.currentIndexChanged.connect( self.updatePens) self.ctrlWidget.brushSizeSlider.sliderMoved.connect( self.changeLineSize) self.ctrlWidget.saveLabelsButton.clicked.connect( self.onClickedSaveLabels) self.ctrlWidget.loadLabelsButton.clicked.connect( self.onClickedLoadLabels) self.ctrlWidget.computeFeaturesButton.clicked.connect( self.onClickedComputeFeatures) self.ctrlWidget.saveFeaturesButton.clicked.connect( self.onClickedSaveFeatures) self.ctrlWidget.loadFeaturesButton.clicked.connect( self.onClickedLoadFeatures) self.ctrlWidget.featureGradientWidget.sigGradientChanged.connect( self.onGradientChanged) self.ctrlWidget.trainRfButton.clicked.connect(self.onClickedTrainRf) self.ctrlWidget.predictProbsButton.clicked.connect( self.onClickedPredictProbs) self.ctrlWidget.predictMcButton.clicked.connect(self.onClickedMulticut) self.ctrlWidget.saveRfButton.clicked.connect(self.onClickedSaveRf) self.ctrlWidget.loadRfButton.clicked.connect(self.onClickedLoadRf) self.layerCtrl.sigFeatureSelected.connect(self.onFeatureSelected) self.imgItem = pg.ImageItem(border='w') self.viewBox.addItem(self.imgItem) self.dataDict = dict() self.curves = [] self.allCurves = None self.currentSlice = 0 self.pathHint = None self.currentFeatures = None self.featureMinMax = None self.currentFi = 0 self.rf = None self.probs = None self.nCurves = 0 self.ScrollLock = threading.Lock() self.scrollingIsLocked = False
# parameter: imPath = ('holyRegion.h5', 'im') # input image path labPath = ('segMaskOnly.h5', 'data') # labeled image path # load volume labels = vigra.impex.readHDF5(*labPath).astype(np.uint32)#[:,:,0:20] volume = vigra.impex.readHDF5(*imPath)#[:,:,0:20] volume = volume.astype('float32') gridGraph = graphs.gridGraph(labels.shape) rag = graphs.regionAdjacencyGraph(gridGraph, labels) featureExtractor = graphs.gridRagFeatureExtractor(rag, labels) accSimpel = featureExtractor.accumulatedFeaturesSimple with vigra.Timer("acc raw"): miMa = float(volume.min()),float(volume.max()) accFeatRaw = featureExtractor.accumulatedFeatures(volume,miMa[0],miMa[1]) with vigra.Timer("acc grad"): grad = vigra.filters.gaussianGradientMagnitude(volume,1.0) accFeatGrad = accSimpel(grad)
from matplotlib.widgets import Slider, Button, RadioButtons # parameter: imPath = ('holyRegion.h5', 'im') # input image path labPath = ('segMaskOnly.h5', 'data') # labeled image path # load volume labels = vigra.impex.readHDF5(*labPath).astype(np.uint32) #[:,:,0:20] volume = vigra.impex.readHDF5(*imPath) #[:,:,0:20] volume = volume.astype('float32') gridGraph = graphs.gridGraph(labels.shape) rag = graphs.regionAdjacencyGraph(gridGraph, labels) featureExtractor = graphs.gridRagFeatureExtractor(rag, labels) accSimpel = featureExtractor.accumulatedFeaturesSimple with vigra.Timer("acc raw"): miMa = float(volume.min()), float(volume.max()) accFeatRaw = featureExtractor.accumulatedFeatures(volume, miMa[0], miMa[1]) with vigra.Timer("acc grad"): grad = vigra.filters.gaussianGradientMagnitude(volume, 1.0) accFeatGrad = accSimpel(grad) with vigra.Timer("acc hessian"): grad = vigra.filters.hessianOfGaussianEigenvalues(volume, 1.0)[:, :, 0] accFeatHess = accSimpel(grad) gui = vigra.graphs.TinyEdgeLabelGui(rag=rag,
def makeFeat(rag, raw, labels, show=True): featureExtractor = graphs.gridRagFeatureExtractor(rag, labels) featureExtractor.labels = labels featureExtractor.graph = rag geoFeat = featureExtractor.geometricFeatures() topoFeat = featureExtractor.topologicalFeatures() features = [geoFeat, topoFeat] # ward facs wardness = numpy.array([0.0, 0.1, 0.15, 0.25, 0.5, 1.0], dtype='float32') accFeat = featureExtractor.accumulatedFeatures(raw) features.append(accFeat) for s in [2.0, 3.0, 4.0]: res = vigra.filters.gaussianGradientMagnitude(raw, s) accFeat = featureExtractor.accumulatedFeatures(res) features.append(accFeat) for s in [2.0, 3.0, 4.0]: res = vigra.filters.laplacianOfGaussian(raw, s) accFeat = featureExtractor.accumulatedFeatures(res) features.append(accFeat) for s in [2.0, 3.0, 4.0]: res = vigra.gaussianSmoothing(raw, s) accFeat = featureExtractor.accumulatedFeatures(res) features.append(accFeat) # st ev for s in [2.0, 3.0, 4.0]: res = stEv(raw, s) accFeat = featureExtractor.accumulatedFeatures(res) mean = accFeat[:, 0] ucm = featureExtractor.ucmTransformFeatures(mean[:, None], wardness) features.extend([accFeat, ucm]) if False: for x in range(ucm.shape[1]): rag.showEdgeFeature(raw, ucm[:, x]) vigra.show() # hessian ev for s in [1.0, 3.0, 4.0, 6.0, 8.0]: img = hessianEv2(raw, s, 2.0) #vigra.imshow(img) #vigra.show() accFeat = featureExtractor.accumulatedFeatures(img) mean = accFeat[:, 0] ucm = featureExtractor.ucmTransformFeatures(mean[:, None], wardness) features.extend([accFeat, ucm]) if False: for x in range(ucm.shape[1]): print "x", x rag.showEdgeFeature(raw, ucm[:, x]) vigra.show() #break # features = numpy.concatenate(features, axis=1) return features