当前位置: 首页>>代码示例>>Python>>正文


Python ndimage.median_filter方法代码示例

本文整理汇总了Python中scipy.ndimage.median_filter方法的典型用法代码示例。如果您正苦于以下问题:Python ndimage.median_filter方法的具体用法?Python ndimage.median_filter怎么用?Python ndimage.median_filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.ndimage的用法示例。


在下文中一共展示了ndimage.median_filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: prepare_n_mnist

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def prepare_n_mnist(filename, is_filter, num_spikes, step_factor=1):
    """Creates images from the specified n mnist recording
    filename: path to the recording
    is_filter: True if median filtering should be applied to the constructed image
    num_spikes: number of unique spikes per image
    step_factor: proportional amount to shift before generating the next image
        1 would result in no overlapping events between images
        0.6 would result in the next image overlapping with 40% of the previous image
    returns: list of images, where each image is a 2d numpy array (height, width)
    """
    td = ev.read_dataset(filename)
    #td.show_td(100)
    td.data = stabilize(td)
    td.data = td.extract_roi([3, 3], [28, 28], True)
    images = make_td_images(td, num_spikes, step_factor)

    if is_filter:
        images = ndimage.median_filter(images, 3)

    #for image in images:
    #    cv2.imshow('img', image)
    #    cv2.waitKey(70)
    return images 
开发者ID:gorchard,项目名称:event-Python,代码行数:25,代码来源:neuro_dataset.py

示例2: MedianFilter

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def MedianFilter(in_dem, kernel_size=3, out_file=None):

    print("Median filtering ...")
    start_time = time.time()
    dem = rd.LoadGDAL(in_dem)
    no_data = dem.no_data
    projection = dem.projection
    geotransform = dem.geotransform

    med = ndimage.median_filter(dem, size=kernel_size)
    med = np2rdarray(med, no_data, projection, geotransform)
    print("Run time: {:.4f} seconds".format(time.time() - start_time))

    if out_file is not None:
        print("Saving dem ...")
        rd.SaveGDAL(out_file, med)
        return out_file

    return med


# Gaussian filter 
开发者ID:giswqs,项目名称:lidar,代码行数:24,代码来源:filtering.py

示例3: test_rank12

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def test_rank12(self):
        expected = [[3, 3, 2, 4, 4],
                [3, 5, 2, 5, 1],
                [5, 5, 8, 3, 5]]
        footprint = [[1, 0, 1], [0, 1, 0]]
        for type in self.types:
            array = numpy.array([[3, 2, 5, 1, 4],
                                    [5, 8, 3, 7, 1],
                                    [5, 6, 9, 3, 5]], type)
            output = ndimage.rank_filter(array, 1,
                                                  footprint=footprint)
            assert_array_almost_equal(expected, output)
            output = ndimage.percentile_filter(array, 50.0,
                                                     footprint=footprint)
            assert_array_almost_equal(expected, output)
            output = ndimage.median_filter(array,
                                                    footprint=footprint)
            assert_array_almost_equal(expected, output) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,代码来源:test_ndimage.py

示例4: filter

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def filter(self, signal):
        """Filter a given signal with a choice of filter type (self.lres_filter).
        """
        signal = signal.copy()
        filter_size = [1, self.downsamp_t*2-1, self.downsamp_xz*2-1, self.downsamp_xz*2-1]

        if self.lres_filter == 'none' or (not self.lres_filter):
            output = signal
        elif self.lres_filter == 'gaussian':
            sigma = [0, int(self.downsamp_t/2), int(self.downsamp_xz/2), int(self.downsamp_xz/2)]
            output = ndimage.gaussian_filter(signal, sigma=sigma)
        elif self.lres_filter == 'uniform':
            output = ndimage.uniform_filter(signal, size=filter_size)
        elif self.lres_filter == 'median':
            output = ndimage.median_filter(signal, size=filter_size)
        elif self.lres_filter == 'maximum':
            output = ndimage.maximum_filter(signal, size=filter_size)
        else:
            raise NotImplementedError(
                "lres_filter must be one of none/gaussian/uniform/median/maximum")
        return output 
开发者ID:maxjiang93,项目名称:space_time_pde,代码行数:23,代码来源:dataloader_spacetime.py

示例5: test_rank12

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def test_rank12(self):
        expected = [[3, 3, 2, 4, 4],
                    [3, 5, 2, 5, 1],
                    [5, 5, 8, 3, 5]]
        footprint = [[1, 0, 1], [0, 1, 0]]
        for type_ in self.types:
            array = numpy.array([[3, 2, 5, 1, 4],
                                 [5, 8, 3, 7, 1],
                                 [5, 6, 9, 3, 5]], type_)
            output = ndimage.rank_filter(array, 1, footprint=footprint)
            assert_array_almost_equal(expected, output)
            output = ndimage.percentile_filter(array, 50.0,
                                               footprint=footprint)
            assert_array_almost_equal(expected, output)
            output = ndimage.median_filter(array, footprint=footprint)
            assert_array_almost_equal(expected, output) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:18,代码来源:test_ndimage.py

示例6: find_jumps2

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def find_jumps2(self,ds,threshold=30000):
        self._prepare_find_jumps()
        ds = self._hf[ds]
        offset=ds[0]
        # first we remove a bit of noise
        #flt = gaussian_filter1d(ds,10)
        flt = median_filter(ds,size=10)
        #flt = ds
        # the sobel filter finds the "jumps" 
        sb=sobel(flt)
        for i in sb:
            self.qps_jpn_hight.append(float(i))
            
        for i in flt: self.qps_jpn_spec.append(float(i))
        """    
        for i in xrange(flt.shape[0]-1):
            if(abs(sb[i])>threshold):
                offset -= sb[i]
                
                self.qps_jpn_spec.append(float(flt[i]-offset))
            else:
                self.qps_jpn_spec.append(float(flt[i]-offset))
        """       

        #for i in sb 
开发者ID:qkitgroup,项目名称:qkit,代码行数:27,代码来源:qps_rings.py

示例7: _background_removal_single_frame_median

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def _background_removal_single_frame_median(frame, footprint=19):
    """Background removal using median filter.

    Parameters
    ----------
    frame : NumPy 2D array
    footprint : float

    Returns
    -------
    background_removed : Numpy 2D array

    Examples
    --------
    >>> import pyxem.utils.dask_tools as dt
    >>> s = pxm.dummy_data.dummy_data.get_cbed_signal()
    >>> s_rem = dt._background_removal_single_frame_median(s.data[0, 0])

    """
    bg_subtracted = frame - ndi.median_filter(frame, size=footprint)
    return bg_subtracted 
开发者ID:pyxem,项目名称:pyxem,代码行数:23,代码来源:dask_tools.py

示例8: filter

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def filter(self, size: NumberLike=0.05, kind: str='median'):
        """Filter the profile.

        Parameters
        ----------
        size : float, int
            Size of the median filter to apply.
            If a float, the size is the ratio of the length. Must be in the range 0-1.
            E.g. if size=0.1 for a 1000-element array, the filter will be 100 elements.
            If an int, the filter is the size passed.
        kind : {'median', 'gaussian'}
            The kind of filter to apply. If gaussian, `size` is the sigma value.
        """
        if isinstance(size, float):
            if 0 < size < 1:
                size = int(round(len(self.values)*size))
                size = max(size, 1)
            else:
                raise TypeError("Float was passed but was not between 0 and 1")

        if kind == 'median':
            self.values = ndimage.median_filter(self.values, size=size)
        elif kind == 'gaussian':
            self.values = ndimage.gaussian_filter(self.values, sigma=size) 
开发者ID:jrkerns,项目名称:pylinac,代码行数:26,代码来源:profile.py

示例9: filter

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def filter(self, size: Union[float, int]=0.05, kind: str='median'):
        """Filter the profile.

        Parameters
        ----------
        size : int, float
            Size of the median filter to apply.
            If a float, the size is the ratio of the length. Must be in the range 0-1.
            E.g. if size=0.1 for a 1000-element array, the filter will be 100 elements.
            If an int, the filter is the size passed.
        kind : {'median', 'gaussian'}
            The kind of filter to apply. If gaussian, *size* is the sigma value.
        """
        if isinstance(size, float):
            if 0 < size < 1:
                size *= len(self.array)
                size = max(size, 1)
            else:
                raise TypeError("Float was passed but was not between 0 and 1")

        if kind == 'median':
            self.array = ndimage.median_filter(self.array, size=size)
        elif kind == 'gaussian':
            self.array = ndimage.gaussian_filter(self.array, sigma=size) 
开发者ID:jrkerns,项目名称:pylinac,代码行数:26,代码来源:image.py

示例10: prepare_n_mnist_continuous

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def prepare_n_mnist_continuous(filename, is_filter, is_normalize=False):
    """Creates image with pixel values indicating probability of a spike
    filename: path to the recording
    is_filter: True if median filtering should be applied to the constructed image
    is_normalize: If True, the probabilities will be normalized to make the image more obvious
    returns: image (2d numpy array (height, width))
    """
    td = ev.read_dataset(filename)
    #td.show_td(100)
    td.data = stabilize(td)
    td.data = td.extract_roi([0, 0], [28, 28], True)
    #td.data = apply_tracking1(td)
    #td.data = apply_tracking2(td)
    #td.data = apply_tracking3(td)
    #td.data = td.extract_roi([3, 3], [28, 28], True)
    image = make_td_probability_image(td, 9, is_normalize)

    if is_filter:
        image = ndimage.median_filter(image, 3)

    #cv2.imshow('img', image)
    #cv2.waitKey(1)
    return image 
开发者ID:gorchard,项目名称:event-Python,代码行数:25,代码来源:neuro_dataset.py

示例11: test_rank01

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def test_rank01(self):
        array = numpy.array([1, 2, 3, 4, 5])
        output = ndimage.rank_filter(array, 1, size=2)
        assert_array_almost_equal(array, output)
        output = ndimage.percentile_filter(array, 100, size=2)
        assert_array_almost_equal(array, output)
        output = ndimage.median_filter(array, 2)
        assert_array_almost_equal(array, output) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_ndimage.py

示例12: test_rank02

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def test_rank02(self):
        array = numpy.array([1, 2, 3, 4, 5])
        output = ndimage.rank_filter(array, 1, size=[3])
        assert_array_almost_equal(array, output)
        output = ndimage.percentile_filter(array, 50, size=3)
        assert_array_almost_equal(array, output)
        output = ndimage.median_filter(array, (3,))
        assert_array_almost_equal(array, output) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:test_ndimage.py

示例13: test_rank04

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def test_rank04(self):
        array = numpy.array([3, 2, 5, 1, 4])
        expected = [3, 3, 2, 4, 4]
        output = ndimage.rank_filter(array, 1, size=3)
        assert_array_almost_equal(expected, output)
        output = ndimage.percentile_filter(array, 50, size=3)
        assert_array_almost_equal(expected, output)
        output = ndimage.median_filter(array, size=3)
        assert_array_almost_equal(expected, output) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:11,代码来源:test_ndimage.py

示例14: test_rank08

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def test_rank08(self):
        array = numpy.array([[3, 2, 5, 1, 4],
                                [5, 8, 3, 7, 1],
                                [5, 6, 9, 3, 5]])
        expected = [[3, 3, 2, 4, 4],
                [5, 5, 5, 4, 4],
                [5, 6, 7, 5, 5]]
        output = ndimage.percentile_filter(array, 50.0,
                                                    size=(2, 3))
        assert_array_almost_equal(expected, output)
        output = ndimage.rank_filter(array, 3, size=(2, 3))
        assert_array_almost_equal(expected, output)
        output = ndimage.median_filter(array, size=(2, 3))
        assert_array_almost_equal(expected, output) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:16,代码来源:test_ndimage.py

示例15: test_rank08

# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import median_filter [as 别名]
def test_rank08(self):
        array = numpy.array([[3, 2, 5, 1, 4],
                             [5, 8, 3, 7, 1],
                             [5, 6, 9, 3, 5]])
        expected = [[3, 3, 2, 4, 4],
                    [5, 5, 5, 4, 4],
                    [5, 6, 7, 5, 5]]
        output = ndimage.percentile_filter(array, 50.0, size=(2, 3))
        assert_array_almost_equal(expected, output)
        output = ndimage.rank_filter(array, 3, size=(2, 3))
        assert_array_almost_equal(expected, output)
        output = ndimage.median_filter(array, size=(2, 3))
        assert_array_almost_equal(expected, output) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:15,代码来源:test_ndimage.py


注:本文中的scipy.ndimage.median_filter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。