本文整理汇总了Python中scipy.ndimage.binary_opening方法的典型用法代码示例。如果您正苦于以下问题:Python ndimage.binary_opening方法的具体用法?Python ndimage.binary_opening怎么用?Python ndimage.binary_opening使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.ndimage
的用法示例。
在下文中一共展示了ndimage.binary_opening方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_binary_opening01
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_opening [as 别名]
def test_binary_opening01(self):
expected = [[0, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]]
for type in self.types:
data = numpy.array([[0, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 0, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]], type)
out = ndimage.binary_opening(data)
assert_array_almost_equal(out, expected)
示例2: test_binary_opening02
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_opening [as 别名]
def test_binary_opening02(self):
struct = ndimage.generate_binary_structure(2, 2)
expected = [[1, 1, 1, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]]
for type in self.types:
data = numpy.array([[1, 1, 1, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 0, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0]], type)
out = ndimage.binary_opening(data, struct)
assert_array_almost_equal(out, expected)
示例3: test_binary_opening01
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_opening [as 别名]
def test_binary_opening01(self):
expected = [[0, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 1, 1, 1, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]]
for type_ in self.types:
data = numpy.array([[0, 1, 0, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 0, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]], type_)
out = ndimage.binary_opening(data)
assert_array_almost_equal(out, expected)
示例4: test_binary_opening02
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_opening [as 别名]
def test_binary_opening02(self):
struct = ndimage.generate_binary_structure(2, 2)
expected = [[1, 1, 1, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 0, 0, 0],
[0, 1, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0]]
for type_ in self.types:
data = numpy.array([[1, 1, 1, 0, 0, 0, 0, 0],
[1, 1, 1, 0, 0, 0, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 0, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0]], type_)
out = ndimage.binary_opening(data, struct)
assert_array_almost_equal(out, expected)
示例5: _prepare_mask
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_opening [as 别名]
def _prepare_mask(mask, label, erode=True):
fgmask = mask.copy()
if np.issubdtype(fgmask.dtype, np.integer):
if isinstance(label, (str, bytes)):
label = FSL_FAST_LABELS[label]
fgmask[fgmask != label] = 0
fgmask[fgmask == label] = 1
else:
fgmask[fgmask > 0.95] = 1.0
fgmask[fgmask < 1.0] = 0
if erode:
# Create a structural element to be used in an opening operation.
struc = nd.generate_binary_structure(3, 2)
# Perform an opening operation on the background data.
fgmask = nd.binary_opening(fgmask, structure=struc).astype(np.uint8)
return fgmask
示例6: setup_method
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_opening [as 别名]
def setup_method(self):
a = numpy.zeros((5,5), dtype=bool)
a[1:4, 1:4] = True
a[4,4] = True
self.array = a
self.sq3x3 = numpy.ones((3,3))
self.opened_old = ndimage.binary_opening(self.array, self.sq3x3,
1, None, 0)
self.closed_old = ndimage.binary_closing(self.array, self.sq3x3,
1, None, 0)
示例7: test_opening_new_arguments
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_opening [as 别名]
def test_opening_new_arguments(self):
opened_new = ndimage.binary_opening(self.array, self.sq3x3, 1, None,
0, None, 0, False)
assert_array_equal(opened_new, self.opened_old)
示例8: _run_interface
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_opening [as 别名]
def _run_interface(self, runtime):
in_file = nb.load(self.inputs.in_file)
data = in_file.get_data()
mask = data <= 0
# Pad one pixel to control behavior on borders of binary_opening
mask = np.pad(mask, pad_width=(1,), mode="constant", constant_values=1)
# Remove noise
struc = nd.generate_binary_structure(3, 2)
mask = nd.binary_opening(mask, structure=struc).astype(np.uint8)
# Remove small objects
label_im, nb_labels = nd.label(mask)
if nb_labels > 2:
sizes = nd.sum(mask, label_im, list(range(nb_labels + 1)))
ordered = list(reversed(sorted(zip(sizes, list(range(nb_labels + 1))))))
for _, label in ordered[2:]:
mask[label_im == label] = 0
# Un-pad
mask = mask[1:-1, 1:-1, 1:-1]
# If mask is small, clean-up
if mask.sum() < 500:
mask = np.zeros_like(mask, dtype=np.uint8)
out_img = in_file.__class__(mask, in_file.affine, in_file.header)
out_img.header.set_data_dtype(np.uint8)
out_file = fname_presuffix(self.inputs.in_file, suffix="_rotmask", newpath=".")
out_img.to_filename(out_file)
self._results["out_file"] = out_file
return runtime
示例9: artifact_mask
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_opening [as 别名]
def artifact_mask(imdata, airdata, distance, zscore=10.0):
"""Computes a mask of artifacts found in the air region"""
from statsmodels.robust.scale import mad
if not np.issubdtype(airdata.dtype, np.integer):
airdata[airdata < 0.95] = 0
airdata[airdata > 0.0] = 1
bg_img = imdata * airdata
if np.sum((bg_img > 0).astype(np.uint8)) < 100:
return np.zeros_like(airdata)
# Find the background threshold (the most frequently occurring value
# excluding 0)
bg_location = np.median(bg_img[bg_img > 0])
bg_spread = mad(bg_img[bg_img > 0])
bg_img[bg_img > 0] -= bg_location
bg_img[bg_img > 0] /= bg_spread
# Apply this threshold to the background voxels to identify voxels
# contributing artifacts.
qi1_img = np.zeros_like(bg_img)
qi1_img[bg_img > zscore] = 1
qi1_img[distance < 0.10] = 0
# Create a structural element to be used in an opening operation.
struc = nd.generate_binary_structure(3, 1)
qi1_img = nd.binary_opening(qi1_img, struc).astype(np.uint8)
qi1_img[airdata <= 0] = 0
return qi1_img
示例10: pixMorphSequence_mask_seed_fill_holes
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_opening [as 别名]
def pixMorphSequence_mask_seed_fill_holes(self, I):
Imask = self.reduction_T_1(I)
Imask = self.reduction_T_1(Imask)
Imask = ndimage.binary_fill_holes(Imask)
Iseed = self.reduction_T_4(Imask)
Iseed = self.reduction_T_3(Iseed)
mask = array(ones((5, 5)), dtype=int)
Iseed = ndimage.binary_opening(Iseed, mask)
Iseed = self.expansion(Iseed, Imask.shape)
return Imask, Iseed
示例11: test_morphology_fft_opening_2D
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_opening [as 别名]
def test_morphology_fft_opening_2D(self):
im = self.im[:, :, 50]
truth = spim.binary_opening(im, structure=disk(3))
test = ps.tools.fftmorphology(im, strel=disk(3), mode='opening')
assert np.all(truth == test)
示例12: test_morphology_fft_opening_3D
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_opening [as 别名]
def test_morphology_fft_opening_3D(self):
im = self.im
truth = spim.binary_opening(im, structure=ball(3))
test = ps.tools.fftmorphology(im, strel=ball(3), mode='opening')
assert np.all(truth == test)
示例13: extract_binary_regions
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import binary_opening [as 别名]
def extract_binary_regions(sequence, opening_param = 3, mshape = ((0,1,0),(1,1,1),(0,1,0))):
labelblock = np.zeros_like(sequence)
for idx in range(sequence.shape[0]):
labelblock[idx] = sequence[idx].copy()
labelblock[idx] = ndi.binary_opening(labelblock[idx], iterations = opening_param, structure = mshape)
labelblock[idx], num_labels = ndi.label(labelblock[idx])
return labelblock, opening_param, mshape