def prefilter(self, img_in, radius=None): img_temp = img_in if self.params['togglemappings']: img_temp = ccore.toggle_mapping(img_in, self.params['tm_size']) if radius is None: radius = self.params['medianradius'] img_out = ccore.disc_median(img_temp, radius) return img_out
def _run(self, meta_image, container): image = meta_image.image img_prefiltered = ccore.disc_median(image, self.params['presegmentation_median_radius']) t = int(ccore.get_otsu_threshold(img_prefiltered) * self.params['presegmentation_alpha']) img_bin = ccore.threshold_image(img_prefiltered, t) img_labels = ccore.segmentation_propagate(img_prefiltered, img_bin, container.img_labels, self.params['lambda'], self.params['delta_width']) return ccore.ImageMaskContainer(image, img_labels, False, True, True)
def prefilter(self, img_in, radius=None): if radius is None: radius = self.params['medianradius'] img_out = ccore.disc_median(img_in, radius) return img_out
def __call__(self, meta_image, container): stopwatch_total = StopWatch() stopwatch = StopWatch() image, width, height = meta_image.image, meta_image.width, meta_image.height containers = {} iLabelNumber = container.img_labels.getMinmax()[1]+1 img_prefiltered = image # expanded - in case expansion size == 0 original regions are taken if 'expanded' in self.lstAreaSelection: stopwatch.reset() if self.iExpansionSizeExpanded > 0: imgLabelsOut = ccore.seeded_region_expansion(img_prefiltered, container.img_labels, ccore.SrgType.KeepContours, iLabelNumber, self.fExpansionCostThreshold, self.iExpansionSizeExpanded, 0 ) else: imgLabelsOut = container.img_labels containers['expanded'] =\ ccore.ImageMaskContainer(image, imgLabelsOut, False, True, True) self._logger.debug(" --- expanded region ok, %s" % stopwatch.current_interval()) # inside - in case shrinking size == 0 original regions are taken if 'inside' in self.lstAreaSelection: stopwatch.reset() if self.iShrinkingSizeInside > 0: imgLabelsOut = ccore.seeded_region_shrinking(img_prefiltered, container.img_labels, iLabelNumber, self.iShrinkingSizeInside ) else: imgLabelsOut = container.img_labels containers['inside'] =\ ccore.ImageMaskContainer(image, imgLabelsOut, False, True, True) self._logger.debug(" --- inside region ok, %s" % stopwatch.current_interval()) # outside - expansion size > 0 AND expansion > separation size needed, # otherwise area is 0 if ('outside' in self.lstAreaSelection and self.iExpansionSizeOutside > 0 and self.iExpansionSizeOutside > self.iExpansionSeparationSizeOutside): stopwatch.reset() imgLabelsOut = ccore.seeded_region_expansion(img_prefiltered, container.img_labels, ccore.SrgType.KeepContours, iLabelNumber, self.fExpansionCostThreshold, self.iExpansionSizeOutside, self.iExpansionSeparationSizeOutside, ) imgLabelsOut = ccore.substractImages(imgLabelsOut, container.img_labels) containers['outside'] =\ ccore.ImageMaskContainer(image, imgLabelsOut, False, True, True) self._logger.debug(" --- outside region ok, %s" % stopwatch.current_interval()) # rim - one value > 0 needed, otherwise area is 0 if ('rim' in self.lstAreaSelection and (self.iExpansionSizeRim > 0 or self.iShrinkingSizeRim > 0)): stopwatch.reset() if self.iShrinkingSizeRim > 0: imgLabelsOutA = ccore.seeded_region_shrinking(img_prefiltered, container.img_labels, iLabelNumber, self.iShrinkingSizeRim ) else: imgLabelsOutA = container.img_labels if self.iExpansionSizeRim > 0: imgLabelsOutB = ccore.seeded_region_expansion(img_prefiltered, container.img_labels, ccore.SrgType.KeepContours, iLabelNumber, self.fExpansionCostThreshold, self.iExpansionSizeRim, 0 ) else: imgLabelsOutB = container.img_labels imgLabelsOut = ccore.substractImages(imgLabelsOutB, imgLabelsOutA) containers['rim'] =\ ccore.ImageMaskContainer(image, imgLabelsOut, False, True, True) self._logger.debug(" --- rim region ok, %s" % stopwatch.current_interval()) if ('propagate' in self.lstAreaSelection): stopwatch.reset() if self.iPresegmentationMedianRadius > 0: img_prefiltered = ccore.disc_median(image, self.iPresegmentationMedianRadius) t = int(ccore.get_otsu_threshold(img_prefiltered) * self.fPresegmentationAlpha) img_binary = ccore.threshold_image(img_prefiltered, t) #self._logger.debug(" --- pre-segmentation ok, %s" % # stopwatch.current_interval()) labels_out = ccore.segmentation_propagate(img_prefiltered, img_binary, container.img_labels, self.fPropagateLambda, self.iPropagateDeltaWidth) containers['propagate'] =\ ccore.ImageMaskContainer(image, labels_out, False, True, True) self._logger.debug(" --- propagate region ok, %s" % stopwatch.current_interval()) if ('constrained_watershed' in self.lstAreaSelection): labels_out = self.constrainedWatershedApproach(image, container.img_labels, iGaussFilterSize=self.iConstrainedWatershedGaussFilterSize) containers['constrained_watershed'] =\ ccore.ImageMaskContainer(image, labels_out, False, True, True) self._logger.debug(" --- constrained_watershed region ok, %s", stopwatch.current_interval()) self._logger.debug(" total time: %s" % stopwatch_total.current_interval()) return containers
def __call__(self, meta_image): stopwatch_total = StopWatch() stopwatch = StopWatch() #print "moo123" #image = meta_image.image #print type(image), image.getMinmax() #meta_image.setImageXY(convertImageMinMax(image)) image = meta_image.image #print type(image), image.getMinmax() width, height = meta_image.width, meta_image.height #print width, height, self.strPathOutDebug if self.bSpeedup: imgTmp1 = ccore.Image(width, height) ccore.binImage(image, imgTmp1, 2) width /= 2 height /= 2 imgTmp2 = ccore.Image(width, height) ccore.scaleImage(imgTmp1, imgTmp2, "no") image = imgTmp2 # if self.bDebugMode: # strPathOutDebug = self.strPathOutDebug # ccore.writeImage(image, # os.path.join(strPathOutDebug, # meta_image.format("00raw.jpg", bC=True)), # self.strImageOutCompression) img_prefiltered = ccore.disc_median(image, self.iMedianRadius) self._logger.debug(" --- median ok, %s" % stopwatch.current_interval()) stopwatch.reset() #print self.bDebugMode, self.strPathOutDebug # if self.bDebugMode: # ccore.writeImage(img_prefiltered, # os.path.join(strPathOutDebug, # meta_image.format("00pre.jpg", bC=True)), # self.strImageOutCompression) imgBin = ccore.window_average_threshold(img_prefiltered, self.iLatWindowSize, self.iLatLimit) self._logger.debug(" --- local threshold ok, %s" % stopwatch.current_interval()) if self.hole_filling: ccore.fill_holes(imgBin, False) stopwatch.reset() #self._logger.debug(" --- local threshold2 %s %s" % (self.iLatWindowSize2, ) if not self.iLatWindowSize2 is None and not self.iLatLimit2 is None: imgBin2 = ccore.window_average_threshold(img_prefiltered, self.iLatWindowSize2, self.iLatLimit2) imgBin = ccore.projectImage([imgBin, imgBin2], ccore.ProjectionType.MaxProjection) self._logger.debug(" --- local threshold2 ok, %s" % stopwatch.current_interval()) stopwatch.reset() # if self.bDebugMode: # strPathOutDebug = self.strPathOutDebug # ccore.writeImage(imgBin, # os.path.join(strPathOutDebug, # meta_image.format("01bin.jpg", bC=True)), # self.strImageOutCompression) # else: # strPathOutDebug = "" if self.bDoShapeWatershed: imgBin = ccore.segmentation_correction_shape(img_prefiltered, imgBin, self.iLatWindowSize, self.iGaussSizeShape, self.iMaximaSizeShape, self.iMinMergeSize) if self.bDoIntensityWatershed: imgBin = ccore.segmentation_correction_intensity(img_prefiltered, imgBin, self.iLatWindowSize, self.iGaussSizeIntensity, self.iMaximaSizeIntensity, self.iMinMergeSize) self._logger.debug(" --- segmentation ok, %s" % stopwatch.current_interval()) stopwatch.reset() if self.bSpeedup: width, height = meta_image.width, meta_image.height imgTmpBin = ccore.Image(width, height) ccore.scaleImage(imgBin, imgTmpBin, "no") imgBin = imgTmpBin image = meta_image.image container = ccore.ImageMaskContainer(image, imgBin, self.bRemoveBorderObjects) self._logger.debug(" --- container ok, %s" % stopwatch.current_interval()) stopwatch.reset() # post-processing #print self.bPostProcessing, self.lstPostprocessingFeatureCategories if self.bPostProcessing: # extract features for strFeature in self.lstPostprocessingFeatureCategories: container.applyFeature(strFeature) dctObjects = container.getObjects() lstGoodObjectIds = [] lstRejectedObjectIds = [] for iObjectId in dctObjects.keys()[:]: dctObjectFeatures = dctObjects[iObjectId].getFeatures() if not eval(self.strPostprocessingConditions, dctObjectFeatures): if self.bPostProcessDeleteObjects: del dctObjects[iObjectId] container.delObject(iObjectId) lstRejectedObjectIds.append(iObjectId) else: lstGoodObjectIds.append(iObjectId) self._logger.debug(" --- post-processing ok, %s" % stopwatch.current_interval()) else: lstGoodObjectIds = container.getObjects().keys() lstRejectedObjectIds = [] container.lstGoodObjectIds = lstGoodObjectIds container.lstRejectedObjectIds = lstRejectedObjectIds # if self.bDebugMode: # container.markObjects(ccore.RGBValue(0,255,0), False, False) # #container.markObjects(lstGoodObjectIds, ccore.RGBValue(0,255,0), False, False) # #container.markObjects(lstRejectedObjectIds, ccore.RGBValue(255,0,0), False, False) # container.exportRGB(os.path.join(strPathOutDebug, # meta_image.format("03Contour.jpg", bC=True)), # self.strImageOutCompression) # # # reset the container RGB # container.eraseRGB() # container.combineExtraRGB([7],[1]) self._logger.debug(" total time: %s" % stopwatch_total.current_interval()) return container