def onNewImage(self, dataItemImage): dataItemImage.Classification.setModuleMgr(self) #create featureM dataItemImage.module["Classification"]["featureM"] = numpy.zeros(dataItemImage.shape[0:-1] + (self.featureMgr.totalFeatureSize,),'float32') #clear features and training self.classificationMgr.clearFeaturesAndTrainingForImage(dataItemImage) #handle obsolete file formats: if dataItemImage.Classification["labels"] is not None: labels = dataItemImage.Classification["labels"] ov = overlayMgr.OverlayItem(labels._data, alpha = 1.0, colorTable = labels.getColorTab(), autoAdd = True, autoVisible = True, autoAlphaChannel = False, linkColorTable = True) dataItemImage.overlayMgr["Classification/Labels"] = ov if len(self.dataMgr.module["Classification"]["labelDescriptions"]) == 0: for d in labels.descriptions: self.dataMgr.module["Classification"]["labelDescriptions"].append(d) dataItemImage.Classification["labels"] = None #create LabelOverlay if dataItemImage.overlayMgr["Classification/Labels"] is None: data = numpy.zeros(dataItemImage.shape[0:-1]+(1,),'uint8') ov = overlayMgr.OverlayItem(data, color = 0, alpha = 1.0, colorTable = self.dataMgr.module["Classification"]["labelDescriptions"].getColorTab(), autoAdd = True, autoVisible = True, linkColorTable = True) dataItemImage.overlayMgr["Classification/Labels"] = ov #be able to show the labels in 3D dataItemImage.overlayMgr["Classification/Labels"].displayable3D = True dataItemImage.overlayMgr["Classification/Labels"].backgroundClasses = set([0]) dataItemImage.overlayMgr["Classification/Labels"].smooth3D = False #add the raw data if dataItemImage.overlayMgr["Raw Data"] is not None: dataItemImage.Classification.addOverlayRef(dataItemImage.overlayMgr["Raw Data"].getRef()) if dataItemImage.Classification["prediction"] is not None: prediction = dataItemImage.Classification["prediction"] for index, descr in enumerate(self.dataMgr.module["Classification"]["labelDescriptions"]): ov = overlayMgr.OverlayItem(DataAccessor(prediction[:,:,:,:,index:index+1], channels = False), color = long(descr.color), alpha = 0.4, colorTable = None, autoAdd = True, autoVisible = True, min = 0, max = 1.0) ov.setColorGetter(descr.getColor, descr) dataItemImage.overlayMgr["Classification/Prediction/" + descr.name] = ov margin = activeLearning.computeEnsembleMargin(prediction[:,:,:,:,:]) ov = overlayMgr.OverlayItem(DataAccessor(margin), alpha = 1.0, color = long(65535)<<16, colorTable = None, autoAdd = True, autoVisible = True, min = 0, max = 1.0) dataItemImage.overlayMgr["Classification/Uncertainty"] = ov dataItemImage.Classification["prediction"] = None # if self._dataVol.uncertainty is not None: # #create Overlay for uncertainty: # ov = overlayMgr.OverlayItem(self._dataVol.uncertainty, color = QtGui.QColor(255, 0, 0), alpha = 1.0, colorTable = None, autoAdd = True, autoVisible = False) # self.overlayMgr["Classification/Uncertainty"] = ov #calculate features for the image featureProcess = featureMgr.FeatureThread(self.featureMgr, self.dataMgr, [dataItemImage]) featureProcess.start() featureProcess.wait()
def generateOverlays(self, activeImage = None): for itemindex, activeItem in enumerate(self.dataMgr): prediction = self._prediction descriptions = self.dataMgr.module["Classification"]["labelDescriptions"] classifiers = self.dataMgr.module["Classification"]["classificationMgr"].classifiers if prediction is not None and prediction[itemindex] is not None: foregrounds = [] for p_i, p_num in enumerate(classifiers[0].unique_vals): #create Overlay for _prediction: ov = overlayMgr.OverlayItem(prediction[itemindex][:,:,:,:,p_i], color = long(descriptions[p_num-1].color), alpha = 0.4, colorTable = None, autoAdd = True, autoVisible = True, min = 0, max = 1) ov.setColorGetter(descriptions[p_num-1].getColor, descriptions[p_num-1]) activeItem.overlayMgr["Classification/Prediction/" + descriptions[p_num-1].name] = ov ov = activeItem.overlayMgr["Classification/Prediction/" + descriptions[p_num-1].name] ov.setColorGetter(descriptions[p_num-1].getColor, descriptions[p_num-1]) foregrounds.append(ov) import ilastik.core.overlays.thresholdOverlay as tho if len(foregrounds) > 1: if activeItem.overlayMgr["Classification/Segmentation"] is None: ov = tho.ThresholdOverlay(foregrounds, [], autoAdd = True, autoVisible = True) activeItem.overlayMgr["Classification/Segmentation"] = ov else: ov = activeItem.overlayMgr["Classification/Segmentation"] ov.setForegrounds(foregrounds) all = range(len(descriptions)) if len(classifiers) > 0: not_predicted = numpy.setdiff1d(all, classifiers[0].unique_vals - 1) if len(not_predicted) > 0: print not_predicted for p_i, p_num in enumerate(not_predicted): if activeItem.overlayMgr["Classification/Prediction/" + descriptions[p_num].name] is not None: print "clearing prediction for unused Label ", p_num activeItem.overlayMgr["Classification/Prediction/" + descriptions[p_num].name][:,:,:,:,:] = 0 margin = activeLearning.computeEnsembleMargin(prediction[itemindex][:,:,:,:,:]) #create Overlay for uncertainty: ov = overlayMgr.OverlayItem(margin, color = long(65535 << 16), alpha = 1.0, colorTable = None, autoAdd = True, autoVisible = False, min = 0, max = 1) activeItem.overlayMgr["Classification/Uncertainty"] = ov else: print "Prediction for item ", itemindex, "is None, not generating Overlays"