本文整理汇总了Python中scipy.ndimage.binary_fill_holes方法的典型用法代码示例。如果您正苦于以下问题:Python ndimage.binary_fill_holes方法的具体用法?Python ndimage.binary_fill_holes怎么用?Python ndimage.binary_fill_holes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.ndimage
的用法示例。
在下文中一共展示了ndimage.binary_fill_holes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_binary_fill_holes02
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def test_binary_fill_holes02(self):
expected = numpy.array([[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]], bool)
data = numpy.array([[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]], bool)
out = ndimage.binary_fill_holes(data)
assert_array_almost_equal(out, expected)
示例2: test_binary_fill_holes03
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def test_binary_fill_holes03(self):
expected = numpy.array([[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 1, 1, 1],
[0, 1, 1, 1, 0, 1, 1, 1],
[0, 1, 1, 1, 0, 1, 1, 1],
[0, 0, 1, 0, 0, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0]], bool)
data = numpy.array([[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 1, 0, 1, 0, 1, 1, 1],
[0, 1, 0, 1, 0, 1, 0, 1],
[0, 1, 0, 1, 0, 1, 0, 1],
[0, 0, 1, 0, 0, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0]], bool)
out = ndimage.binary_fill_holes(data)
assert_array_almost_equal(out, expected)
示例3: test_binary_fill_holes01
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def test_binary_fill_holes01(self):
expected = numpy.array([[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]], bool)
data = numpy.array([[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]], bool)
out = ndimage.binary_fill_holes(data)
assert_array_almost_equal(out, expected)
示例4: test_binary_fill_holes01
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def test_binary_fill_holes01(self):
expected = numpy.array([[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]], bool)
data = numpy.array([[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]], bool)
out = ndimage.binary_fill_holes(data)
assert_array_almost_equal(out, expected)
示例5: test_binary_fill_holes02
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def test_binary_fill_holes02(self):
expected = numpy.array([[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]], bool)
data = numpy.array([[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]], bool)
out = ndimage.binary_fill_holes(data)
assert_array_almost_equal(out, expected)
示例6: test_binary_fill_holes03
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def test_binary_fill_holes03(self):
expected = numpy.array([[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 1, 1, 1],
[0, 1, 1, 1, 0, 1, 1, 1],
[0, 1, 1, 1, 0, 1, 1, 1],
[0, 0, 1, 0, 0, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0]], bool)
data = numpy.array([[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0],
[0, 1, 0, 1, 0, 1, 1, 1],
[0, 1, 0, 1, 0, 1, 0, 1],
[0, 1, 0, 1, 0, 1, 0, 1],
[0, 0, 1, 0, 0, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0]], bool)
out = ndimage.binary_fill_holes(data)
assert_array_almost_equal(out, expected)
示例7: fill_tissue_holes
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def fill_tissue_holes(bw_img):
""" Filling holes in tissue image
Parameters
----------
bw_img : np.array
2D binary image.
Returns
-------
bw_fill: np.array
Binary image with no holes
"""
# Fill holes
bw_fill = binary_fill_holes(bw_img)
return bw_fill
示例8: simple_bodymask
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def simple_bodymask(img):
maskthreshold = -500
oshape = img.shape
img = ndimage.zoom(img, 128/np.asarray(img.shape), order=0)
bodymask = img > maskthreshold
bodymask = ndimage.binary_closing(bodymask)
bodymask = ndimage.binary_fill_holes(bodymask, structure=np.ones((3, 3))).astype(int)
bodymask = ndimage.binary_erosion(bodymask, iterations=2)
bodymask = skimage.measure.label(bodymask.astype(int), connectivity=1)
regions = skimage.measure.regionprops(bodymask.astype(int))
if len(regions) > 0:
max_region = np.argmax(list(map(lambda x: x.area, regions))) + 1
bodymask = bodymask == max_region
bodymask = ndimage.binary_dilation(bodymask, iterations=2)
real_scaling = np.asarray(oshape)/128
return ndimage.zoom(bodymask, real_scaling, order=0)
示例9: _find_field_centroid
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def _find_field_centroid(self) -> Tuple[Point, List]:
"""Find the centroid of the radiation field based on a 50% height threshold.
Returns
-------
p
The CAX point location.
edges
The bounding box of the field, plus a small margin.
"""
min, max = np.percentile(self.array, [5, 99.9])
threshold_img = self.as_binary((max - min)/2 + min)
filled_img = ndimage.binary_fill_holes(threshold_img)
# clean single-pixel noise from outside field
cleaned_img = ndimage.binary_erosion(threshold_img)
[*edges] = bounding_box(cleaned_img)
edges[0] -= 10
edges[1] += 10
edges[2] -= 10
edges[3] += 10
coords = ndimage.measurements.center_of_mass(filled_img)
p = Point(x=coords[-1], y=coords[0])
return p, edges
示例10: patch_up_roi
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def patch_up_roi(roi):
"""
After being non-linearly transformed, ROIs tend to have holes in them.
We perform a couple of computational geometry operations on the ROI to
fix that up.
Parameters
----------
roi : 3D binary array
The ROI after it has been transformed.
sigma : float
The sigma for initial Gaussian smoothing.
truncate : float
The truncation for the Gaussian
Returns
-------
ROI after dilation and hole-filling
"""
hole_filled = ndim.binary_fill_holes(roi > 0)
try:
return convex_hull_image(hole_filled)
except QhullError:
return hole_filled
示例11: clean_mask
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def clean_mask(m, c):
# threshold
m_thresh = threshold_otsu(m)
c_thresh = threshold_otsu(c)
m_b = m > m_thresh
c_b = c > c_thresh
# combine contours and masks and fill the cells
m_ = np.where(m_b | c_b, 1, 0)
m_ = ndi.binary_fill_holes(m_)
# close what wasn't closed before
area, radius = mean_blob_size(m_b)
struct_size = int(1.25 * radius)
struct_el = morph.disk(struct_size)
m_padded = pad_mask(m_, pad=struct_size)
m_padded = morph.binary_closing(m_padded, selem=struct_el)
m_ = crop_mask(m_padded, crop=struct_size)
# open to cut the real cells from the artifacts
area, radius = mean_blob_size(m_b)
struct_size = int(0.75 * radius)
struct_el = morph.disk(struct_size)
m_ = np.where(c_b & (~m_b), 0, m_)
m_padded = pad_mask(m_, pad=struct_size)
m_padded = morph.binary_opening(m_padded, selem=struct_el)
m_ = crop_mask(m_padded, crop=struct_size)
# join the connected cells with what we had at the beginning
m_ = np.where(m_b | m_, 1, 0)
m_ = ndi.binary_fill_holes(m_)
# drop all the cells that weren't present at least in 25% of area in the initial mask
m_ = drop_artifacts(m_, m_b, min_coverage=0.25)
return m_
示例12: fill_holes_per_blob
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def fill_holes_per_blob(image):
image_cleaned = np.zeros_like(image)
for i in range(1, image.max() + 1):
mask = np.where(image == i, 1, 0)
mask = ndi.morphology.binary_fill_holes(mask)
image_cleaned = image_cleaned + mask * i
return image_cleaned
示例13: post_processing
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def post_processing(prediction):
prediction = nd.binary_fill_holes(prediction)
label_cc, num_cc = measure.label(prediction,return_num=True)
total_cc = np.sum(prediction)
measure.regionprops(label_cc)
for cc in range(1,num_cc+1):
single_cc = (label_cc==cc)
single_vol = np.sum(single_cc)
if single_vol/total_cc<0.2:
prediction[single_cc]=0
return prediction
示例14: binarize_volume
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def binarize_volume(vol, t, minvol=0, fill=False):
mask = vol >= t
if minvol != 0:
mask = binary_volume_opening(mask, minvol)
if fill:
mask = binary_fill_holes(mask)
return mask
示例15: create_nonzero_mask
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_fill_holes [as 别名]
def create_nonzero_mask(data):
from scipy.ndimage import binary_fill_holes
assert len(data.shape) == 4 or len(data.shape) == 3, "data must have shape (C, X, Y, Z) or shape (C, X, Y)"
nonzero_mask = np.zeros(data.shape[1:], dtype=bool)
for c in range(data.shape[0]):
this_mask = data[c] != 0
nonzero_mask = nonzero_mask | this_mask
nonzero_mask = binary_fill_holes(nonzero_mask)
return nonzero_mask