本文整理汇总了Python中skimage.measure.regionprops方法的典型用法代码示例。如果您正苦于以下问题:Python measure.regionprops方法的具体用法?Python measure.regionprops怎么用?Python measure.regionprops使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skimage.measure
的用法示例。
在下文中一共展示了measure.regionprops方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter_cloudmask
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def filter_cloudmask(cloudmask, threshold=1, connectivity=1):
"""Filter a given cloudmask for small cloud objects defined by their pixel
number.
Parameters:
cloudmask (ndarray): 2d binary cloud mask (optional with NaNs).
threshold (int): minimum pixel number of objects remaining in cloudmask.
connectivity (int): Maximum number of orthogonal hops to consider
a pixel/voxel as a neighbor (see :func:`skimage.measure.label`).
Return:
ndarray: filtered cloudmask without NaNs.
"""
cloudmask[np.isnan(cloudmask)] = 0
labels = measure.label(cloudmask, connectivity=connectivity)
props = measure.regionprops(labels)
area = [prop.area for prop in props]
# Find objects < threshold pixle number, get their labels, set them to 0-clear.
smallclouds = [t[0] for t in filter(lambda a: a[1] < threshold, enumerate(area, 1))]
for label in smallclouds:
cloudmask[labels == label] = 0
return cloudmask
示例2: scale_radius
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def scale_radius(src, img_size, padding=False):
x = src[src.shape[0] // 2, ...].sum(axis=1)
r = (x > x.mean() / 10).sum() // 2
yx = src.sum(axis=2)
region_props = measure.regionprops((yx > yx.mean() / 10).astype('uint8'))
yc, xc = np.round(region_props[0].centroid).astype('int')
x1 = max(xc - r, 0)
x2 = min(xc + r, src.shape[1] - 1)
y1 = max(yc - r, 0)
y2 = min(yc + r, src.shape[0] - 1)
dst = src[y1:y2, x1:x2]
dst = cv2.resize(dst, dsize=None, fx=img_size/(2*r), fy=img_size/(2*r))
if padding:
pad_x = (img_size - dst.shape[1]) // 2
pad_y = (img_size - dst.shape[0]) // 2
dst = np.pad(dst, ((pad_y, pad_y), (pad_x, pad_x), (0, 0)), 'constant')
return dst
示例3: centroids_of_connected_components
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def centroids_of_connected_components(bitmap, threshold=0.05, rescale=1.0):
# TODO: don't do raw (binary) threshold; instead use P(y) as weighting for centroid
# e.g. https://arxiv.org/abs/1806.03413 sec 3.D
# update: this didn't help much :/ centroid weighted by intensities moved only up
# to a single pixel (guess centroids are already quite evenly dispersed)
# see https://gist.github.com/matpalm/20a3974ceb7f632f935285262fac4e98
# TODO: hunt down the x/y swap between PIL and label db :/
# threshold
mask = bitmap > threshold
bitmap = np.zeros_like(bitmap)
bitmap[mask] = 1.0
# calc connected components
all_labels = measure.label(bitmap)
# return centroids
centroids = []
for region in measure.regionprops(label_image=all_labels):
cx, cy = map(lambda p: int(p*rescale), (region.centroid[0], region.centroid[1]))
centroids.append((cx, cy))
return centroids
示例4: segment_body
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def segment_body (image, smooth=1, th=-300):
blur = scipy.ndimage.filters.gaussian_filter(image, smooth, mode='constant')
binary = np.array(blur < th, dtype=np.uint8)
# body is a rough region covering human body
body = np.zeros_like(binary)
for i, sl in enumerate(binary):
#H, W = sl.shape
ll = measure.label(sl, background=1) # connected components
# biggest CC should be body
pp = measure.regionprops(ll)
boxes = [(x.area, x.bbox, x.filled_image) for x in pp if x.label != 0] # label 0 is air
boxes = sorted(boxes, key = lambda x: -x[0])
if len(boxes) == 0:
continue
y0, x0, y1, x1 = boxes[0][1]
body[i,y0:y1,x0:x1] = boxes[0][2]
pass
return body, None
示例5: keep_largest_connected_components
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def keep_largest_connected_components(mask):
'''
Keeps only the largest connected components of each label for a segmentation mask.
'''
out_img = np.zeros(mask.shape, dtype=np.uint8)
for struc_id in [1, 2, 3]:
binary_img = mask == struc_id
blobs = measure.label(binary_img, connectivity=1)
props = measure.regionprops(blobs)
if not props:
continue
area = [ele.area for ele in props]
largest_blob_ind = np.argmax(area)
largest_blob_label = props[largest_blob_ind].label
out_img[blobs == largest_blob_label] = struc_id
return out_img
示例6: _find_AP_and_RL_diameter
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def _find_AP_and_RL_diameter(major_axis, minor_axis, orientation, dim):
"""
This script checks the orientation of the and assigns the major/minor axis to the appropriate dimension, right-
left (RL) or antero-posterior (AP). It also multiplies by the pixel size in mm.
:param major_axis: major ellipse axis length calculated by regionprops
:param minor_axis: minor ellipse axis length calculated by regionprops
:param orientation: orientation in degree. Ranges between [0, 90]
:param dim: pixel size in mm.
:return: diameter_AP, diameter_RL
"""
if 0 <= orientation < 45.0:
diameter_AP = minor_axis
diameter_RL = major_axis
else:
diameter_AP = major_axis
diameter_RL = minor_axis
# Adjust with pixel size
diameter_AP *= dim[0]
diameter_RL *= dim[1]
return diameter_AP, diameter_RL
示例7: _apply_segmentation
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def _apply_segmentation(self, image, replace_samples, segments):
nb_channels = image.shape[2]
image_sp = np.copy(image)
for c in range(nb_channels):
# segments+1 here because otherwise regionprops always misses
# the last label
regions = measure.regionprops(segments + 1,
intensity_image=image[..., c])
for ridx, region in enumerate(regions):
# with mod here, because slic can sometimes create more
# superpixel than requested. replace_samples then does
# not have enough values, so we just start over with the
# first one again.
if replace_samples[ridx % len(replace_samples)] == 1:
mean_intensity = region.mean_intensity
image_sp_c = image_sp[..., c]
image_sp_c[segments == ridx] = mean_intensity
return image_sp
示例8: label_mask
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def label_mask(pred, main_threshold=0.3, seed_threshold=0.7, w_pixel_t=20, pixel_t=100):
av_pred = pred / 255.
av_pred = av_pred[..., 0] * (1 - av_pred[..., 2])
av_pred = 1 * (av_pred > seed_threshold)
av_pred = av_pred.astype(np.uint8)
y_pred = measure.label(av_pred, neighbors=8, background=0)
props = measure.regionprops(y_pred)
for i in range(len(props)):
if props[i].area < w_pixel_t:
y_pred[y_pred == i + 1] = 0
y_pred = measure.label(y_pred, neighbors=8, background=0)
nucl_msk = (255 - pred[..., 0])
nucl_msk = nucl_msk.astype('uint8')
y_pred = watershed(nucl_msk, y_pred, mask=(pred[..., 0] > main_threshold * 255), watershed_line=True)
props = measure.regionprops(y_pred)
for i in range(len(props)):
if props[i].area < pixel_t:
y_pred[y_pred == i + 1] = 0
y_pred = measure.label(y_pred, neighbors=8, background=0)
return y_pred
示例9: postprocess_victor
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def postprocess_victor(pred):
av_pred = pred / 255.
av_pred = av_pred[..., 2] * (1 - av_pred[..., 1])
av_pred = 1 * (av_pred > 0.5)
av_pred = av_pred.astype(np.uint8)
y_pred = measure.label(av_pred, neighbors=8, background=0)
props = measure.regionprops(y_pred)
for i in range(len(props)):
if props[i].area < 12:
y_pred[y_pred == i + 1] = 0
y_pred = measure.label(y_pred, neighbors=8, background=0)
nucl_msk = (255 - pred[..., 2])
nucl_msk = nucl_msk.astype('uint8')
y_pred = watershed(nucl_msk, y_pred, mask=((pred[..., 2] > 80)), watershed_line=True)
return y_pred
# test_dir = r'C:\dev\dsbowl\results_test\bowl_remap3\merged'
# borders_dir = r'C:\dev\dsbowl\results_test\bowl_remap_border2\merged'
示例10: get_traffic_sign_bounding_boxes
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def get_traffic_sign_bounding_boxes(self, min_width=2, min_height=3):
"""Extracts traffic sign bounding boxes from the frame.
Returns:
list(:py:class:`~pylot.perception.detection.utils.BoundingBox2D`):
Traffic sign bounding boxes.
"""
assert self.encoding == 'carla', \
'Not implemented on cityscapes encoding'
# Set the pixels we are interested in to True.
traffic_signs_frame = self._get_traffic_sign_pixels()
# Extracts bounding box from frame.
bboxes = []
# Labels the connected segmented pixels.
map_labeled = measure.label(traffic_signs_frame, connectivity=1)
# Extract the regions out of the labeled frames.
for region in measure.regionprops(map_labeled):
x_min = region.bbox[1]
x_max = region.bbox[3]
y_min = region.bbox[0]
y_max = region.bbox[2]
# Filter the bboxes that are extremely small.
if x_max - x_min > min_width and y_max - y_min > min_height:
bboxes.append(BoundingBox2D(x_min, x_max, y_min, y_max))
return bboxes
示例11: _setup_geometry_rois
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def _setup_geometry_rois(self):
boxsize = self.geometry_roi_size_mm / self.mm_per_pixel
xbounds = (int(self.phan_center.x-boxsize), int(self.phan_center.x+boxsize))
ybounds = (int(self.phan_center.y-boxsize), int(self.phan_center.y+boxsize))
geo_img = self.image[ybounds[0]:ybounds[1], xbounds[0]:xbounds[1]]
larr, regionprops, num_roi = get_regions(geo_img, fill_holes=True, clear_borders=False)
# check that there is at least 1 ROI
if num_roi < 4:
raise ValueError("Unable to locate the Geometric nodes")
elif num_roi > 4:
regionprops = sorted(regionprops, key=lambda x: x.filled_area, reverse=True)[:4]
sorted_regions = sorted(regionprops, key=lambda x: (2*x.centroid[0]+x.centroid[1]))
centers = [Point(r.weighted_centroid[1]+xbounds[0], r.weighted_centroid[0]+ybounds[0]) for r in sorted_regions]
# setup the geometric lines
for name, order in self.geometry_roi_settings.items():
self.lines[name] = GeometricLine(centers[order[0]], centers[order[1]], self.mm_per_pixel, self.scaling_tolerance)
示例12: MaxBodyBox
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def MaxBodyBox(input):
Otsu=filters.threshold_otsu(input[input.shape[0]//2])
Seg=np.zeros(input.shape)
Seg[input>=Otsu]=255
Seg=Seg.astype(np.int)
ConnectMap=label(Seg, connectivity= 2)
Props = regionprops(ConnectMap)
Area=np.zeros([len(Props)])
Area=[]
Bbox=[]
for j in range(len(Props)):
Area.append(Props[j]['area'])
Bbox.append(Props[j]['bbox'])
Area=np.array(Area)
Bbox=np.array(Bbox)
argsort=np.argsort(Area)
Area=Area[argsort]
Bbox=Bbox[argsort]
Area=Area[::-1]
Bbox=Bbox[::-1,:]
MaximumBbox=Bbox[0]
return Otsu,MaximumBbox
示例13: isolate_islands
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def isolate_islands(prediction, threshold):
bw = closing(prediction > threshold , square(3))
labelled = label(bw)
regions_properties = regionprops(labelled)
max_region_area = 0
select_region = 0
for region in regions_properties:
if region.area > max_region_area:
max_region_area = region.area
select_region = region
output = np.zeros(labelled.shape)
if select_region == 0:
return output
else:
output[labelled == select_region.label] = 1
return output
# input: output from bwperim -- 2D image with perimeter of the ellipse = 1
示例14: get_geobody_tops
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
def get_geobody_tops(rprops, geo_data=None):
"""Get the top vertical limit coordinate of geobodies (via bbox).
Args:
rprops (list): List of regionprops object for each unique region of the model.
(skimage.measure._regionprops._RegionProperties object)
geo_data (gempy.data_management.InputData):
Returns:
(dict): Dict with node labels as keys and geobody top coordinates as values.
"""
if geo_data is None:
return {rprop.label: rprop.bbox[5] for rprop in rprops}
else:
return {rprop.label: rprop.bbox[5] * geo_data.extent[5] / geo_data.resolution[2] for rprop in rprops}
示例15: generate_markers
# 需要导入模块: from skimage import measure [as 别名]
# 或者: from skimage.measure import regionprops [as 别名]
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