本文整理汇总了Python中skimage.morphology.square方法的典型用法代码示例。如果您正苦于以下问题:Python morphology.square方法的具体用法?Python morphology.square怎么用?Python morphology.square使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skimage.morphology
的用法示例。
在下文中一共展示了morphology.square方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getTerminationBifurcation
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def getTerminationBifurcation(img, mask):
img = img == 255;
(rows, cols) = img.shape;
minutiaeTerm = np.zeros(img.shape);
minutiaeBif = np.zeros(img.shape);
for i in range(1,rows-1):
for j in range(1,cols-1):
if(img[i][j] == 1):
block = img[i-1:i+2,j-1:j+2];
block_val = np.sum(block);
if(block_val == 2):
minutiaeTerm[i,j] = 1;
elif(block_val == 4):
minutiaeBif[i,j] = 1;
mask = convex_hull_image(mask>0)
mask = erosion(mask, square(5)) # Structuing element for mask erosion = square(5)
minutiaeTerm = np.uint8(mask)*minutiaeTerm
return(minutiaeTerm, minutiaeBif)
开发者ID:Utkarsh-Deshmukh,项目名称:Fingerprint-Feature-Extraction,代码行数:22,代码来源:getTerminationBifurcation.py
示例2: updateRasterInfo
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def updateRasterInfo(self, **kwargs):
kwargs['output_info']['statistics'] = ()
kwargs['output_info']['histogram'] = ()
self.window = square(int(kwargs.get('size', 3)))
m = kwargs.get('measure', 'Mean').lower()
if m == 'minimum':
self.func = rank.minimum
elif m == 'maximum':
self.func = rank.maximum
elif m == 'mean':
self.func = rank.mean
elif m == 'bilateral mean':
self.func = rank.mean_bilateral
elif m == 'median':
self.func = rank.median
elif m == 'sum':
self.func = rank.sum
elif m == 'entropy':
self.func = rank.entropy
elif m == 'threshold':
self.func = rank.threshold
elif m == 'autolevel':
self.func = rank.autolevel
return kwargs
示例3: generate_wsl
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def generate_wsl(ws):
"""
Generates watershed line. In particular, useful for seperating object
in ground thruth as they are labeled by different intergers.
"""
se = square(3)
ero = ws.copy()
ero[ero == 0] = ero.max() + 1
ero = erosion(ero, se)
ero[ws == 0] = 0
grad = dilation(ws, se) - ero
grad[ws == 0] = 0
grad[grad > 0] = 255
grad = grad.astype(np.uint8)
return grad
示例4: generate_wsl
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def generate_wsl(ws):
"""
Generates watershed line that correspond to areas of
touching objects.
"""
se = square(3)
ero = ws.copy()
ero[ero == 0] = ero.max() + 1
ero = erosion(ero, se)
ero[ws == 0] = 0
grad = dilation(ws, se) - ero
grad[ws == 0] = 0
grad[grad > 0] = 255
grad = grad.astype(np.uint8)
return grad
示例5: dilate
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def dilate(data, size, shape, dim=None):
"""
Dilate data using ball structuring element
:param data: Image or numpy array: 2d or 3d array
:param size: int: If shape={'square', 'cube'}: Corresponds to the length of an edge (size=1 has no effect).
If shape={'disk', 'ball'}: Corresponds to the radius, not including the center element (size=0 has no effect).
:param shape: {'square', 'cube', 'disk', 'ball'}
:param dim: {0, 1, 2}: Dimension of the array which 2D structural element will be orthogonal to. For example, if
you wish to apply a 2D disk kernel in the X-Y plane, leaving Z unaffected, parameters will be: shape=disk, dim=2.
:return: numpy array: data dilated
"""
if isinstance(data, Image):
im_out = data.copy()
im_out.data = dilate(data.data, size, shape, dim)
return im_out
else:
return dilation(data, selem=_get_selem(shape, size, dim), out=None)
示例6: erode
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def erode(data, size, shape, dim=None):
"""
Dilate data using ball structuring element
:param data: Image or numpy array: 2d or 3d array
:param size: int: If shape={'square', 'cube'}: Corresponds to the length of an edge (size=1 has no effect).
If shape={'disk', 'ball'}: Corresponds to the radius, not including the center element (size=0 has no effect).
:param shape: {'square', 'cube', 'disk', 'ball'}
:param dim: {0, 1, 2}: Dimension of the array which 2D structural element will be orthogonal to. For example, if
you wish to apply a 2D disk kernel in the X-Y plane, leaving Z unaffected, parameters will be: shape=disk, dim=2.
:return: numpy array: data dilated
"""
if isinstance(data, Image):
im_out = data.copy()
im_out.data = erode(data.data, size, shape, dim)
return im_out
else:
return erosion(data, selem=_get_selem(shape, size, dim), out=None)
示例7: thicken_drawings
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def thicken_drawings(image):
"""
:param image: [H, W, 3], np.float32
:return:
"""
img = np.array(image[:, :, 0], dtype=np.uint8)
img = 255 - img
dilated_img = sm.dilation(img, sm.square(2))
dilated_img = 255 - dilated_img # [H, W]
rst_img3 = np.zeros([dilated_img.shape[0], dilated_img.shape[1], 3], dtype=np.uint8)
for i in range(3):
rst_img3[:, :, i] = dilated_img
return rst_img3
示例8: subtract_background_median
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def subtract_background_median(z, footprint):
"""Remove background using a median filter.
Parameters
----------
footprint : int
size of the window that is convoluted with the array to determine
the median. Should be large enough that it is about 3x as big as the
size of the peaks.
Returns
-------
Pattern with background subtracted as np.array
"""
selem = morphology.square(footprint)
# skimage only accepts input image as uint16
bg_subtracted = z - filters.median(z.astype(np.uint16), selem).astype(z.dtype)
return np.maximum(bg_subtracted, 0)
示例9: isolate_islands
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [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
示例10: key_point_to_mask
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def key_point_to_mask(key_points, img_size, radius=6):
new_points = expand_key_points(key_points, radius)
mask = np.zeros(shape=img_size, dtype=bool)
for i, joint in enumerate(list(key_points) + new_points):
if KEY_POINT_MISSING_VALUE in joint:
continue
yy, xx = circle(joint[0], joint[1], radius=radius, shape=img_size)
mask[yy, xx] = True
mask = dilation(mask, square(radius + 3))
mask = erosion(mask, square(radius + 3))
return mask
示例11: produce_ma_mask
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def produce_ma_mask(kp_array, img_size, point_radius=4):
from skimage.morphology import dilation, erosion, square
mask = np.zeros(shape=img_size, dtype=bool)
limbs = [[2, 3], [2, 6], [3, 4], [4, 5], [6, 7], [7, 8], [2, 9], [9, 10],
[10, 11], [2, 12], [12, 13], [13, 14], [2, 1], [1, 15], [15, 17],
[1, 16], [16, 18], [2, 17], [2, 18], [9, 12], [12, 6], [9, 3], [17, 18]]
limbs = np.array(limbs) - 1
for f, t in limbs:
from_missing = kp_array[f][0] == MISSING_VALUE or kp_array[f][1] == MISSING_VALUE
to_missing = kp_array[t][0] == MISSING_VALUE or kp_array[t][1] == MISSING_VALUE
if from_missing or to_missing:
continue
norm_vec = kp_array[f] - kp_array[t]
norm_vec = np.array([-norm_vec[1], norm_vec[0]])
norm_vec = point_radius * norm_vec / np.linalg.norm(norm_vec)
vetexes = np.array([
kp_array[f] + norm_vec,
kp_array[f] - norm_vec,
kp_array[t] - norm_vec,
kp_array[t] + norm_vec
])
yy, xx = polygon(vetexes[:, 0], vetexes[:, 1], shape=img_size)
mask[yy, xx] = True
for i, joint in enumerate(kp_array):
if kp_array[i][0] == MISSING_VALUE or kp_array[i][1] == MISSING_VALUE:
continue
yy, xx = circle(joint[0], joint[1], radius=point_radius, shape=img_size)
mask[yy, xx] = True
mask = dilation(mask, square(5))
mask = erosion(mask, square(5))
return mask
示例12: __call__
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def __call__(self, img_small):
m = morphology.square(self.square_size)
img_th = morphology.black_tophat(img_small, m)
img_sob = abs(filters.sobel_v(img_th))
img_closed = morphology.closing(img_sob, m)
threshold = filters.threshold_otsu(img_closed)
return img_closed > threshold
示例13: produce_ma_mask
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def produce_ma_mask(kp_array, img_size, point_radius=4):
from skimage.morphology import dilation, erosion, square
mask = np.zeros(shape=img_size, dtype=bool)
limbs = [[2,3], [2,6], [3,4], [4,5], [6,7], [7,8], [2,9], [9,10],
[10,11], [2,12], [12,13], [13,14], [2,1], [1,15], [15,17],
[1,16], [16,18], [2,17], [2,18], [9,12], [12,6], [9,3], [17,18]]
limbs = np.array(limbs) - 1
for f, t in limbs:
from_missing = kp_array[f][0] == MISSING_VALUE or kp_array[f][1] == MISSING_VALUE
to_missing = kp_array[t][0] == MISSING_VALUE or kp_array[t][1] == MISSING_VALUE
if from_missing or to_missing:
continue
norm_vec = kp_array[f] - kp_array[t]
norm_vec = np.array([-norm_vec[1], norm_vec[0]])
norm_vec = point_radius * norm_vec / np.linalg.norm(norm_vec)
vetexes = np.array([
kp_array[f] + norm_vec,
kp_array[f] - norm_vec,
kp_array[t] - norm_vec,
kp_array[t] + norm_vec
])
yy, xx = polygon(vetexes[:, 0], vetexes[:, 1], shape=img_size)
mask[yy, xx] = True
for i, joint in enumerate(kp_array):
if kp_array[i][0] == MISSING_VALUE or kp_array[i][1] == MISSING_VALUE:
continue
yy, xx = circle(joint[0], joint[1], radius=point_radius, shape=img_size)
mask[yy, xx] = True
mask = dilation(mask, square(5))
mask = erosion(mask, square(5))
return mask
示例14: points_to_rectangle_mask
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def points_to_rectangle_mask(shape, top_left, bottom_right, width=1):
"""Convert two points into a rectangle boolean mask.
Parameters
----------
shape : tuple
Represents the `(height, width)` of the final mask.
top_left : tuple
Two element tuple representing `(row, column)` of the top left corner of the inner rectangle.
bottom_right : tuple
Two element tuple representing `(row, column)` of the bottom right corner of the inner rectangle.
width : int
Width of the edge of the rectangle. Note that it is generated by dilation.
Returns
-------
rectangle_mask : np.ndarray
Boolean mask of shape `shape` where True entries represent the edge of the rectangle.
Notes
-----
The output can be easily used for quickly visualizing a rectangle in an image. One simply does
something like img[rectangle_mask] = 255.
"""
if len(shape) != 2:
raise ValueError('Only works for 2 dimensional arrays')
rectangle_mask = np.zeros(shape, dtype=np.bool)
rr, cc = rectangle_perimeter(top_left, bottom_right)
rectangle_mask[rr, cc] = True
rectangle_mask = dilation(rectangle_mask, square(width))
return rectangle_mask
示例15: get_rough_detection
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import square [as 别名]
def get_rough_detection(self, img, bigsize=40.0, smallsize=4.0, thresh = 0):
diff = self.difference_of_gaussian(-img, bigsize, smallsize)
diff[diff>thresh] = 1
se = morphology.square(4)
ero = morphology.erosion(diff, se)
labimage = label(ero)
#rec = morphology.reconstruction(ero, img, method='dilation').astype(np.dtype('uint8'))
# connectivity=1 corresponds to 4-connectivity.
morphology.remove_small_objects(labimage, min_size=600, connectivity=1, in_place=True)
#res = np.zeros(img.shape)
ero[labimage==0] = 0
ero = 1 - ero
labimage = label(ero)
morphology.remove_small_objects(labimage, min_size=400, connectivity=1, in_place=True)
ero[labimage==0] = 0
res = 1 - ero
res[res>0] = 255
#temp = 255 - temp
#temp = morphology.remove_small_objects(temp, min_size=400, connectivity=1, in_place=True)
#res = 255 - temp
return res