Python skimage.segmentation() Examples
The following are 11
code examples of skimage.segmentation().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
skimage
, or try the search function
.
Example #1
Source File: superpixel.py From eo-learn with MIT License | 6 votes |
def execute(self, eopatch): """ Main execute method """ feature_type, feature_name = next(self.feature_checker(eopatch)) data = eopatch[feature_type][feature_name] if np.isnan(data).any(): warnings.warn('There are NaN values in given data, super-pixel segmentation might produce bad results', RuntimeWarning) if feature_type.is_time_dependent(): data = np.moveaxis(data, 0, 2) data = data.reshape((data.shape[0], data.shape[1], data.shape[2] * data.shape[3])) superpixel_mask = np.atleast_3d(self._create_superpixel_mask(data)) new_feature_type, new_feature_name = self.superpixel_feature eopatch[new_feature_type][new_feature_name] = superpixel_mask return eopatch
Example #2
Source File: dsbowl_preprocess_2d.py From Kaggle-DSB with MIT License | 6 votes |
def generate_markers(image): #Creation of the internal Marker marker_internal = image < -400 marker_internal = segmentation.clear_border(marker_internal) marker_internal_labels = measure.label(marker_internal) areas = [r.area for r in measure.regionprops(marker_internal_labels)] areas.sort() if len(areas) > 2: for region in measure.regionprops(marker_internal_labels): if region.area < areas[-2]: for coordinates in region.coords: marker_internal_labels[coordinates[0], coordinates[1]] = 0 marker_internal = marker_internal_labels > 0 #Creation of the external Marker external_a = ndimage.binary_dilation(marker_internal, iterations=10) external_b = ndimage.binary_dilation(marker_internal, iterations=55) marker_external = external_b ^ external_a #Creation of the Watershed Marker matrix marker_watershed = np.zeros(image.shape, dtype=np.int) marker_watershed += marker_internal * 255 marker_watershed += marker_external * 128 return marker_internal, marker_external, marker_watershed
Example #3
Source File: LUNA_3d_merge_preproc.py From Kaggle-DSB with MIT License | 6 votes |
def generate_markers(image): #Creation of the internal Marker marker_internal = image < -400 marker_internal = segmentation.clear_border(marker_internal) marker_internal_labels = measure.label(marker_internal) areas = [r.area for r in measure.regionprops(marker_internal_labels)] areas.sort() if len(areas) > 2: for region in measure.regionprops(marker_internal_labels): if region.area < areas[-2]: for coordinates in region.coords: marker_internal_labels[coordinates[0], coordinates[1]] = 0 marker_internal = marker_internal_labels > 0 #Creation of the external Marker external_a = ndimage.binary_dilation(marker_internal, iterations=10) external_b = ndimage.binary_dilation(marker_internal, iterations=55) marker_external = external_b ^ external_a #Creation of the Watershed Marker matrix marker_watershed = np.zeros(image.shape, dtype=np.int) marker_watershed += marker_internal * 255 marker_watershed += marker_external * 128 return marker_internal, marker_external, marker_watershed
Example #4
Source File: preproc_utils.py From Kaggle-DSB with MIT License | 6 votes |
def generate_markers(image): #Creation of the internal Marker marker_internal = image < -400 marker_internal = segmentation.clear_border(marker_internal) marker_internal_labels = measure.label(marker_internal) areas = [r.area for r in measure.regionprops(marker_internal_labels)] areas.sort() if len(areas) > 2: for region in measure.regionprops(marker_internal_labels): if region.area < areas[-2]: for coordinates in region.coords: marker_internal_labels[coordinates[0], coordinates[1]] = 0 marker_internal = marker_internal_labels > 0 #Creation of the external Marker external_a = ndimage.binary_dilation(marker_internal, iterations=10) external_b = ndimage.binary_dilation(marker_internal, iterations=55) marker_external = external_b ^ external_a #Creation of the Watershed Marker matrix marker_watershed = np.zeros(image.shape, dtype=np.int) marker_watershed += marker_internal * 255 marker_watershed += marker_external * 128 return marker_internal, marker_external, marker_watershed
Example #5
Source File: FocusMask.py From BlurDetection with MIT License | 5 votes |
def get_masks(img, n_seg=250): logger.debug('SLIC segmentation initialised') segments = skimage.segmentation.slic(img, n_segments=n_seg, compactness=10, sigma=1) logger.debug('SLIC segmentation complete') logger.debug('contour extraction...') masks = [[numpy.zeros((img.shape[0], img.shape[1]), dtype=numpy.uint8), None]] for region in skimage.measure.regionprops(segments): masks.append([masks[0][0].copy(), region.bbox]) x_min, y_min, x_max, y_max = region.bbox masks[-1][0][x_min:x_max, y_min:y_max] = skimage.img_as_ubyte(region.convex_image) logger.debug('contours extracted') return masks[1:]
Example #6
Source File: superpixel.py From eo-learn with MIT License | 5 votes |
def __init__(self, feature, superpixel_feature, *, segmentation_object=skimage.segmentation.felzenszwalb, **segmentation_params): """ :param feature: Raster feature which will be used in segmentation :param superpixel_feature: A new mask timeless feature to hold super-pixel mask :param segmentation_object: A function (object) which performs superpixel segmentation, by default that is `skimage.segmentation.felzenszwalb` :param segmentation_params: Additional parameters which will be passed to segmentation_object function """ self.feature_checker = self._parse_features(feature, allowed_feature_types=FeatureTypeSet.SPATIAL_TYPES) self.superpixel_feature = next(self._parse_features(superpixel_feature, allowed_feature_types={FeatureType.MASK_TIMELESS})()) self.segmentation_object = segmentation_object self.segmentation_params = segmentation_params
Example #7
Source File: superpixel.py From eo-learn with MIT License | 5 votes |
def _create_superpixel_mask(self, data): """ Method which performs the segmentation """ with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=RuntimeWarning, module=skimage.segmentation.__name__) return self.segmentation_object(data, **self.segmentation_params)
Example #8
Source File: superpixel.py From eo-learn with MIT License | 5 votes |
def __init__(self, feature, superpixel_feature, **kwargs): """ Arguments are passed to `SuperpixelSegmentation` task """ super().__init__(feature, superpixel_feature, segmentation_object=skimage.segmentation.felzenszwalb, **kwargs)
Example #9
Source File: superpixel.py From eo-learn with MIT License | 5 votes |
def __init__(self, feature, superpixel_feature, **kwargs): """ Arguments are passed to `SuperpixelSegmentation` task """ super().__init__(feature, superpixel_feature, segmentation_object=skimage.segmentation.slic, **kwargs)
Example #10
Source File: superpixel.py From eo-learn with MIT License | 5 votes |
def execute(self, eopatch): """ Execute method """ feature_type, feature_name = next(self.feature_checker(eopatch)) segmentation_mask = eopatch[feature_type][feature_name][..., 0] bounds_mask = skimage.segmentation.mark_boundaries(np.zeros(segmentation_mask.shape[:2], dtype=np.uint8), segmentation_mask, **self.params) bounds_mask = bounds_mask[..., :1].astype(np.uint8) eopatch[self.new_feature[0]][self.new_feature[1]] = bounds_mask return eopatch
Example #11
Source File: extract_features.py From kaggle-ndsb with MIT License | 4 votes |
def getMinorMajorRatio_2(image): image = image.copy() # Create the thresholded image to eliminate some of the background imagethr = np.where(image > np.mean(image),0.,1.0) #Dilate the image imdilated = morphology.dilation(imagethr, np.ones((4,4))) # Create the label list label_list = measure.label(imdilated) label_list = imagethr*label_list label_list = label_list.astype(int) region_list = measure.regionprops(label_list) maxregion = getLargestRegion(region_list, label_list, imagethr) # guard against cases where the segmentation fails by providing zeros ratio = 0.0 minor_axis_length = 0.0 major_axis_length = 0.0 area = 0.0 convex_area = 0.0 eccentricity = 0.0 equivalent_diameter = 0.0 euler_number = 0.0 extent = 0.0 filled_area = 0.0 orientation = 0.0 perimeter = 0.0 solidity = 0.0 centroid = [0.0,0.0] if ((not maxregion is None) and (maxregion.major_axis_length != 0.0)): ratio = 0.0 if maxregion is None else maxregion.minor_axis_length*1.0 / maxregion.major_axis_length minor_axis_length = 0.0 if maxregion is None else maxregion.minor_axis_length major_axis_length = 0.0 if maxregion is None else maxregion.major_axis_length area = 0.0 if maxregion is None else maxregion.area convex_area = 0.0 if maxregion is None else maxregion.convex_area eccentricity = 0.0 if maxregion is None else maxregion.eccentricity equivalent_diameter = 0.0 if maxregion is None else maxregion.equivalent_diameter euler_number = 0.0 if maxregion is None else maxregion.euler_number extent = 0.0 if maxregion is None else maxregion.extent filled_area = 0.0 if maxregion is None else maxregion.filled_area orientation = 0.0 if maxregion is None else maxregion.orientation perimeter = 0.0 if maxregion is None else maxregion.perimeter solidity = 0.0 if maxregion is None else maxregion.solidity centroid = [0.0,0.0] if maxregion is None else maxregion.centroid return ratio,minor_axis_length,major_axis_length,area,convex_area,eccentricity,\ equivalent_diameter,euler_number,extent,filled_area,orientation,perimeter,solidity, centroid[0], centroid[1]