當前位置: 首頁>>代碼示例>>Python>>正文


Python ndimage.binary_opening方法代碼示例

本文整理匯總了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) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:22,代碼來源:test_ndimage.py

示例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) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:23,代碼來源:test_ndimage.py

示例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) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:22,代碼來源:test_ndimage.py

示例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) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:23,代碼來源:test_ndimage.py

示例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 
開發者ID:poldracklab,項目名稱:mriqc,代碼行數:22,代碼來源:anatomical.py

示例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) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:12,代碼來源:test_ndimage.py

示例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) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:6,代碼來源:test_ndimage.py

示例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 
開發者ID:poldracklab,項目名稱:mriqc,代碼行數:36,代碼來源:anatomical.py

示例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 
開發者ID:poldracklab,項目名稱:mriqc,代碼行數:33,代碼來源:anatomical.py

示例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 
開發者ID:OCR-D,項目名稱:ocrd_anybaseocr,代碼行數:12,代碼來源:ocrd_anybaseocr_tiseg.py

示例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) 
開發者ID:PMEAL,項目名稱:porespy,代碼行數:7,代碼來源:test_filters.py

示例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) 
開發者ID:PMEAL,項目名稱:porespy,代碼行數:7,代碼來源:test_filters.py

示例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 
開發者ID:317070,項目名稱:kaggle-heart,代碼行數:12,代碼來源:segmentation_labelling.py


注:本文中的scipy.ndimage.binary_opening方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。