def threshold(self, image, median_radius, window_size, min_contrast, remove_borderobjects, fill_holes, norm_min=0, norm_max=255, use_watershed=True, seeding_size=5, outline_smoothing=1, *args, **kw): image = self.normalize(image, norm_min, norm_max) image = ccore.numpy_to_image(image, copy=True) image_smoothed = ccore.gaussianFilter(image, median_radius) label_image = ccore.window_average_threshold( image_smoothed, window_size, min_contrast) if fill_holes: ccore.fill_holes(label_image) if outline_smoothing >= 1: label_image = outlineSmoothing(label_image.toArray(), outline_smoothing) label_image = ccore.numpy_to_image(label_image, copy=True) if use_watershed: label_image = label_image.toArray().copy() label_image = watershed(label_image, seeding_size=seeding_size) label_image = ccore.numpy_to_image( label_image.astype(np.int16), copy=True) return ccore.ImageMaskContainer(image, label_image, remove_borderobjects, True, True) else: # a static type system sucks! return ccore.ImageMaskContainer(image, label_image, remove_borderobjects)
def _constrained_watershed(self, img_in, img_labels, filter_size=2): maxlabel = img_labels.getMinmax()[1] img_bin = ccore.threshold(img_labels, 1, maxlabel, 0, 255) # internal marker img_ero = ccore.erode(img_bin, 3, 8) img_internal_marker = ccore.anchoredSkeleton(img_bin, img_ero) # external marker img_inv = ccore.linearRangeMapping(img_bin, 255, 0, 0, 255) img_voronoi = ccore.watershed(img_inv) img_external_marker = ccore.threshold(img_voronoi, 0, 0, 0, 255) # full marker image img_marker = ccore.supremum(img_internal_marker, img_external_marker) # gradient image img_filtered = ccore.gaussianFilter(img_in, filter_size) img_grad = ccore.morphoGradient(img_filtered, 1, 8) # Watershed result: 0 is WSL, 1 is Background, all other values correspond to labels. img_grad_watershed = ccore.constrainedWatershed(img_grad, img_marker) # we first get the regions maxreslab = img_grad_watershed.getMinmax()[1] img_bin2 = ccore.threshold(img_grad_watershed, 2, maxreslab, 0, 255) img_temp = ccore.copyImageIf(img_labels, img_bin2) img_out = ccore.relabelImage(img_bin2, img_temp) return img_out
def constrainedWatershedApproach(self, imgIn, imgLabel, iGaussFilterSize=2): minlabel, maxlabel = imgLabel.getMinmax() imgThresh = ccore.threshold(imgLabel, 1, maxlabel, 0, 255) # internal marker imgEro = ccore.erode(imgThresh, 3, 8) imgInternalMarker = ccore.anchoredSkeleton(imgThresh, imgEro) # external marker imgInv = ccore.linearRangeMapping(imgThresh, 255, 0, 0, 255) imgVoronoi = ccore.watershed(imgInv) imgExternalMarker = ccore.threshold(imgVoronoi, 0, 0, 0, 255) # full marker image imgMarker = ccore.supremum(imgInternalMarker, imgExternalMarker) # gradient image imgFiltered = ccore.gaussianFilter(imgIn, iGaussFilterSize) imgGrad = ccore.morphoGradient(imgFiltered, 1, 8) # Watershed result: 0 is WSL, 1 is Background, all other values correspond to labels. imgGradWatershed = ccore.constrainedWatershed(imgGrad, imgMarker) # we first get the regions minreslab, maxreslab = imgGradWatershed.getMinmax() imgBinSegmentationRes = ccore.threshold(imgGradWatershed, 2, maxreslab, 0, 255) imgTemp = ccore.copyImageIf(imgLabel, imgBinSegmentationRes) imgRes = ccore.relabelImage(imgBinSegmentationRes, imgTemp) return imgRes
def getFocusMeasurementFilterSeries(self, imin, method=None, gauss_sizes=None): if method is None: method = self.method if gauss_sizes is None: gauss_sizes = self.gauss_sizes init_meas = ccore.focusQuantification(imin, method) res = {0: 1.0} for filter_size in gauss_sizes: impref = ccore.gaussianFilter(imin, filter_size) focus_meas = ccore.focusQuantification(impref, method) res[filter_size] = focus_meas / init_meas return res
def threshold(self, image, median_radius, window_size, min_contrast, remove_borderobjects, fill_holes, norm_min=0, norm_max=255, use_watershed=True, seeding_size=5, outline_smoothing=1, *args, **kw): image = self.normalize(image, norm_min, norm_max) image = ccore.numpy_to_image(image, copy=True) image_smoothed = ccore.gaussianFilter(image, median_radius) label_image = ccore.window_average_threshold(image_smoothed, window_size, min_contrast) if fill_holes: ccore.fill_holes(label_image) if outline_smoothing >= 1: label_image = outlineSmoothing(label_image.toArray(), outline_smoothing) label_image = ccore.numpy_to_image(label_image, copy=True) if use_watershed: label_image = label_image.toArray().copy() label_image = watershed(label_image, seeding_size=seeding_size) label_image = ccore.numpy_to_image(label_image.astype(np.int16), copy=True) return ccore.ImageMaskContainer(image, label_image, remove_borderobjects, True, True) else: # a static type system sucks! return ccore.ImageMaskContainer(image, label_image, remove_borderobjects)