本文整理汇总了Python中skimage.morphology.diamond方法的典型用法代码示例。如果您正苦于以下问题:Python morphology.diamond方法的具体用法?Python morphology.diamond怎么用?Python morphology.diamond使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skimage.morphology
的用法示例。
在下文中一共展示了morphology.diamond方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_pos_dst_transform
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import diamond [as 别名]
def get_pos_dst_transform(label_unmodified, img, instance, old_label=None, dt_method="edt"):
label = np.where(label_unmodified == instance, 1, 0)
# If an old label is available, then sample positive clicks on the difference between the two.
if old_label is not None:
# The difference should be taken only if there is atleast one object pixel in the difference.
label = np.max(0, label - old_label) if np.any((label - old_label) == 1) else label
# Leave a margin around the object boundary
img_area = morphology.binary_erosion(label, morphology.diamond(D_MARGIN))
img_area = img_area if len(np.where(img_area == 1)[0]) > 0 else np.copy(label)
# Set of ground truth pixels.
O = np.where(img_area == 1)
# Randomly sample the number of positive clicks and negative clicks to use.
num_clicks_pos = 0 if len(O) == 0 else random.sample(list(range(1, Npos + 1)), 1)
# num_clicks_pos = random.sample(range(1, Npos + 1), 1)
pts = get_sampled_locations(O, img_area, num_clicks_pos)
u1 = get_distance_transform(pts, img_area, img=img, dt_method=dt_method)
return u1, pts
示例2: get_image_area_to_sample
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import diamond [as 别名]
def get_image_area_to_sample(img):
"""
calculate set g_c, which has two properties
1) They represent background pixels
2) They are within a certain distance to the object
:param img: Image that represents the object instance
"""
#TODO: In the paper 'Deep Interactive Object Selection', they calculate g_c first based on the original object instead
# of the dilated one.
# Dilate the object by d_margin pixels to extend the object boundary
img_area = np.copy(img)
img_area = morphology.binary_dilation(img_area, morphology.diamond(D_MARGIN)).astype(np.uint8)
g_c = np.logical_not(img_area).astype(int)
g_c[np.where(distance_transform_edt(g_c) > D)] = 0
return g_c
示例3: overlay
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import diamond [as 别名]
def overlay(self, img, imbin, contour=False):
colim = color.gray2rgb(img)
colorvalue = (0, 100, 200)
if contour:
se = morphology.diamond(2)
ero = morphology.erosion(imbin, se)
grad = imbin - ero
colim[grad > 0] = colorvalue
else:
colim[imbin>0] = colorvalue
return colim
示例4: morpho_rec
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import diamond [as 别名]
def morpho_rec(self, img, size=10):
# internal gradient of the cells:
se = morphology.diamond(size)
ero = morphology.erosion(img, se)
rec = morphology.reconstruction(ero, img, method='dilation').astype(np.dtype('uint8'))
return rec
示例5: morpho_rec2
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import diamond [as 别名]
def morpho_rec2(self, img, size=10):
# internal gradient of the cells:
se = morphology.diamond(size)
dil = morphology.dilation(img, se)
rec = morphology.reconstruction(dil, img, method='erosion').astype(np.dtype('uint8'))
return rec
示例6: test_morpho2
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import diamond [as 别名]
def test_morpho2(self, bigsize=20.0, smallsize=3.0, threshold=5.0):
img = self.read_H_image()
pref = self.morpho_rec(img, 10)
filename = os.path.join(test_out_folder, 'morpho_00_rec_%s.png' % self.image_name)
skimage.io.imsave(filename, pref)
res = self.difference_of_gaussian(pref, bigsize, smallsize)
filename = os.path.join(test_out_folder, 'morpho_01_diff_%s_%i_%i.png' % (self.image_name, int(bigsize), int(smallsize)))
skimage.io.imsave(filename, res)
#res = self.morpho_rec2(diff, 15)
#filename = os.path.join(test_out_folder, 'morpho_02_rec_%s.png' % self.image_name)
#skimage.io.imsave(filename, res)
res[res>threshold] = 255
filename = os.path.join(test_out_folder, 'morpho_03_res_%s_%i.png' % (self.image_name, threshold))
skimage.io.imsave(filename, res)
se = morphology.diamond(3)
ero = morphology.erosion(res, se)
filename = os.path.join(test_out_folder, 'morpho_03_ero_%s_%i.png' % (self.image_name, threshold))
skimage.io.imsave(filename, ero)
res[ero>0] = 0
overlay_img = self.overlay(img, res)
filename = os.path.join(test_out_folder, 'morpho_04_overlay_%s_%i.png' % (self.image_name, int(threshold)))
skimage.io.imsave(filename, overlay_img)
return
示例7: postprocessing
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import diamond [as 别名]
def postprocessing(prediction, threshold=0.75, dataset='G'):
if dataset[0] == 'D':
prediction = prediction.numpy()
prediction_copy = np.copy(prediction)
disc_mask = prediction[1]
cup_mask = prediction[0]
disc_mask = (disc_mask > 0.5) # return binary mask
cup_mask = (cup_mask > 0.1) # return binary mask
disc_mask = disc_mask.astype(np.uint8)
cup_mask = cup_mask.astype(np.uint8)
for i in range(5):
disc_mask = scipy.signal.medfilt2d(disc_mask, 7)
cup_mask = scipy.signal.medfilt2d(cup_mask, 7)
disc_mask = morphology.binary_erosion(disc_mask, morphology.diamond(7)).astype(np.uint8) # return 0,1
cup_mask = morphology.binary_erosion(cup_mask, morphology.diamond(7)).astype(np.uint8) # return 0,1
disc_mask = get_largest_fillhole(disc_mask).astype(np.uint8) # return 0,1
cup_mask = get_largest_fillhole(cup_mask).astype(np.uint8)
prediction_copy[0] = cup_mask
prediction_copy[1] = disc_mask
return prediction_copy
else:
prediction = prediction.numpy()
prediction = (prediction > threshold) # return binary mask
prediction = prediction.astype(np.uint8)
prediction_copy = np.copy(prediction)
disc_mask = prediction[1]
cup_mask = prediction[0]
for i in range(5):
disc_mask = scipy.signal.medfilt2d(disc_mask, 7)
cup_mask = scipy.signal.medfilt2d(cup_mask, 7)
disc_mask = morphology.binary_erosion(disc_mask, morphology.diamond(7)).astype(np.uint8) # return 0,1
cup_mask = morphology.binary_erosion(cup_mask, morphology.diamond(7)).astype(np.uint8) # return 0,1
disc_mask = get_largest_fillhole(disc_mask).astype(np.uint8) # return 0,1
cup_mask = get_largest_fillhole(cup_mask).astype(np.uint8)
prediction_copy[0] = cup_mask
prediction_copy[1] = disc_mask
return prediction_copy
示例8: _get_axial_shifts
# 需要导入模块: from skimage import morphology [as 别名]
# 或者: from skimage.morphology import diamond [as 别名]
def _get_axial_shifts(ndim=2, include_diagonals=False):
r'''
Helper function to generate the axial shifts that will be performed on
the image to identify bordering pixels/voxels
'''
if ndim == 2:
if include_diagonals:
neighbors = square(3)
else:
neighbors = diamond(1)
neighbors[1, 1] = 0
x, y = np.where(neighbors)
x -= 1
y -= 1
return np.vstack((x, y)).T
else:
if include_diagonals:
neighbors = cube(3)
else:
neighbors = octahedron(1)
neighbors[1, 1, 1] = 0
x, y, z = np.where(neighbors)
x -= 1
y -= 1
z -= 1
return np.vstack((x, y, z)).T