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


Python restoration.unwrap_phase函数代码示例

本文整理汇总了Python中skimage.restoration.unwrap_phase函数的典型用法代码示例。如果您正苦于以下问题:Python unwrap_phase函数的具体用法?Python unwrap_phase怎么用?Python unwrap_phase使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_mask

def test_mask():
    length = 100
    ramps = [np.linspace(0, 4 * np.pi, length),
             np.linspace(0, 8 * np.pi, length),
             np.linspace(0, 6 * np.pi, length)]
    image = np.vstack(ramps)
    mask_1d = np.ones((length,), dtype=np.bool)
    mask_1d[0] = mask_1d[-1] = False
    for i in range(len(ramps)):
        # mask all ramps but the i'th one
        mask = np.zeros(image.shape, dtype=np.bool)
        mask |= mask_1d.reshape(1, -1)
        mask[i, :] = False   # unmask i'th ramp
        image_wrapped = np.ma.array(np.angle(np.exp(1j * image)), mask=mask)
        image_unwrapped = unwrap_phase(image_wrapped)
        image_unwrapped -= image_unwrapped[0, 0]    # remove phase shift
        # The end of the unwrapped array should have value equal to the
        # endpoint of the unmasked ramp
        assert_array_almost_equal_nulp(image_unwrapped[:, -1], image[i, -1])
        assert_(np.ma.isMaskedArray(image_unwrapped))

        # Same tests, but forcing use of the 3D unwrapper by reshaping
        with expected_warnings(['length 1 dimension']):
            shape = (1,) + image_wrapped.shape
            image_wrapped_3d = image_wrapped.reshape(shape)
            image_unwrapped_3d = unwrap_phase(image_wrapped_3d)
            # remove phase shift
            image_unwrapped_3d -= image_unwrapped_3d[0, 0, 0]
        assert_array_almost_equal_nulp(image_unwrapped_3d[:, :, -1],
                                       image[i, -1])
开发者ID:Cadair,项目名称:scikit-image,代码行数:30,代码来源:test_unwrap.py

示例2: check_wrap_around

def check_wrap_around(ndim, axis):
    # create a ramp, but with the last pixel along axis equalling the first
    elements = 100
    ramp = np.linspace(0, 12 * np.pi, elements)
    ramp[-1] = ramp[0]
    image = ramp.reshape(tuple([elements if n == axis else 1
                                for n in range(ndim)]))
    image_wrapped = np.angle(np.exp(1j * image))

    index_first = tuple([0] * ndim)
    index_last = tuple([-1 if n == axis else 0 for n in range(ndim)])
    # unwrap the image without wrap around
    with warnings.catch_warnings():
        # We do not want warnings about length 1 dimensions
        warnings.simplefilter("ignore")
        image_unwrap_no_wrap_around = unwrap_phase(image_wrapped, seed=0)
    print('endpoints without wrap_around:',
          image_unwrap_no_wrap_around[index_first],
          image_unwrap_no_wrap_around[index_last])
    # without wrap around, the endpoints of the image should differ
    assert_(abs(image_unwrap_no_wrap_around[index_first] -
                image_unwrap_no_wrap_around[index_last]) > np.pi)
    # unwrap the image with wrap around
    wrap_around = [n == axis for n in range(ndim)]
    with warnings.catch_warnings():
        # We do not want warnings about length 1 dimensions
        warnings.simplefilter("ignore")
        image_unwrap_wrap_around = unwrap_phase(image_wrapped, wrap_around,
                                                seed=0)
    print('endpoints with wrap_around:',
          image_unwrap_wrap_around[index_first],
          image_unwrap_wrap_around[index_last])
    # with wrap around, the endpoints of the image should be equal
    assert_almost_equal(image_unwrap_wrap_around[index_first],
                        image_unwrap_wrap_around[index_last])
开发者ID:Cadair,项目名称:scikit-image,代码行数:35,代码来源:test_unwrap.py

示例3: test_unwrap_1d

def test_unwrap_1d():
    image = np.linspace(0, 10 * np.pi, 100)
    check_unwrap(image)
    # Masked arrays are not allowed in 1D
    with testing.raises(ValueError):
        check_unwrap(image, True)
    # wrap_around is not allowed in 1D
    with testing.raises(ValueError):
        unwrap_phase(image, True, seed=0)
开发者ID:Cadair,项目名称:scikit-image,代码行数:9,代码来源:test_unwrap.py

示例4: test_unwrap_3d_all_masked

def test_unwrap_3d_all_masked():
    # all elements masked
    image = np.ma.zeros((10, 10, 10))
    image[:] = np.ma.masked
    unwrap = unwrap_phase(image)
    assert_(np.ma.isMaskedArray(unwrap))
    assert_(np.all(unwrap.mask))

    # 1 unmasked element, still zero edges
    image = np.ma.zeros((10, 10, 10))
    image[:] = np.ma.masked
    image[0, 0, 0] = 0
    unwrap = unwrap_phase(image)
    assert_(np.ma.isMaskedArray(unwrap))
    assert_(np.sum(unwrap.mask) == 999)   # all but one masked
    assert_(unwrap[0, 0, 0] == 0)
开发者ID:Cadair,项目名称:scikit-image,代码行数:16,代码来源:test_unwrap.py

示例5: test_invalid_input

def test_invalid_input():
    with testing.raises(ValueError):
        unwrap_phase(np.zeros([]))
    with testing.raises(ValueError):
        unwrap_phase(np.zeros((1, 1, 1, 1)))
    with testing.raises(ValueError):
        unwrap_phase(np.zeros((1, 1)), 3 * [False])
    with testing.raises(ValueError):
        unwrap_phase(np.zeros((1, 1)), 'False')
开发者ID:Cadair,项目名称:scikit-image,代码行数:9,代码来源:test_unwrap.py

示例6: check_unwrap

def check_unwrap(image, mask=None):
    image_wrapped = np.angle(np.exp(1j * image))
    if mask is not None:
        print('Testing a masked image')
        image = np.ma.array(image, mask=mask)
        image_wrapped = np.ma.array(image_wrapped, mask=mask)
    image_unwrapped = unwrap_phase(image_wrapped, seed=0)
    assert_phase_almost_equal(image_unwrapped, image)
开发者ID:Cadair,项目名称:scikit-image,代码行数:8,代码来源:test_unwrap.py

示例7: test_unwrap_2d_all_masked

def test_unwrap_2d_all_masked():
    # Segmentation fault when image is masked array with a all elements masked
    # GitHub issue #1347
    # all elements masked
    image = np.ma.zeros((10, 10))
    image[:] = np.ma.masked
    unwrap = unwrap_phase(image)
    assert_(np.ma.isMaskedArray(unwrap))
    assert_(np.all(unwrap.mask))

    # 1 unmasked element, still zero edges
    image = np.ma.zeros((10, 10))
    image[:] = np.ma.masked
    image[0, 0] = 0
    unwrap = unwrap_phase(image)
    assert_(np.ma.isMaskedArray(unwrap))
    assert_(np.sum(unwrap.mask) == 99)    # all but one masked
    assert_(unwrap[0, 0] == 0)
开发者ID:Cadair,项目名称:scikit-image,代码行数:18,代码来源:test_unwrap.py

示例8: load_folder_pupil

def load_folder_pupil(folder, flag = 'mod', radius = 49 ):
    # load and plot all the pupil functions in the chosen folder.
    pupil_list = glob.glob(folder + '*'+ flag+'*.npy')
    pupil_list.sort(key = os.path.getmtime)
    for pname in pupil_list:
        session_name = os.path.basename(pname).split('.')[0]
        pupil_name = session_name + '_pupil'
        print(session_name)
        raw_pupil = unwrap_phase(np.load(pname))/(2*np.pi) # convert to wavelength
        pupil = pupil_crop(raw_pupil,mask = True, rad = radius)
        figp = pupil_showcross(pupil)
        figp.savefig(folder+pupil_name)
        plt.close()
开发者ID:danustc,项目名称:Optics,代码行数:13,代码来源:Scr_AOprocessing.py

示例9: single_2Dgrating_analyses

def single_2Dgrating_analyses(img, img_ref=None, harmonicPeriod=None,
                              unwrapFlag=True, plotFlag=True, verbose=False):
    """
    Function to process the data of single 2D grating Talbot imaging. It
    wraps other functions in order to make all the process transparent

    """

    # Obtain Harmonic images
    h_img = single_grating_harmonic_images(img, harmonicPeriod,
                                           plotFlag=plotFlag,
                                           verbose=verbose)

    if img_ref is not None:  # relative wavefront

        h_img_ref = single_grating_harmonic_images(img_ref, harmonicPeriod,
                                                   plotFlag=plotFlag,
                                                   verbose=verbose)

        int00 = np.abs(h_img[0])/np.abs(h_img_ref[0])
        int01 = np.abs(h_img[1])/np.abs(h_img_ref[1])
        int10 = np.abs(h_img[2])/np.abs(h_img_ref[2])

        if unwrapFlag is True:

            arg01 = (unwrap_phase(np.angle(h_img[1]), seed=72673) -
                     unwrap_phase(np.angle(h_img_ref[1]), seed=72673))

            arg10 = (unwrap_phase(np.angle(h_img[2]), seed=72673) -
                     unwrap_phase(np.angle(h_img_ref[2]), seed=72673))

        else:
            arg01 = np.angle(h_img[1]) - np.angle(h_img_ref[1])
            arg10 = np.angle(h_img[2]) - np.angle(h_img_ref[2])

    else:  # absolute wavefront

        int00 = np.abs(h_img[0])
        int01 = np.abs(h_img[1])
        int10 = np.abs(h_img[2])

        if unwrapFlag is True:

            arg01 = unwrap_phase(np.angle(h_img[1]), seed=72673)
            arg10 = unwrap_phase(np.angle(h_img[2]), seed=72673)
        else:
            arg01 = np.angle(h_img[1])
            arg10 = np.angle(h_img[2])

    if unwrapFlag is True:  # remove pi jump
        arg01 -= int(np.round(np.mean(arg01/np.pi)))*np.pi
        arg10 -= int(np.round(np.mean(arg10/np.pi)))*np.pi

    darkField01 = int01/int00
    darkField10 = int10/int00

    return [int00, int01, int10,
            darkField01, darkField10,
            arg01, arg10]
开发者ID:wavepy,项目名称:wavepy,代码行数:59,代码来源:grating_interferometry.py

示例10: wave_retrieval

def wave_retrieval(data,r_data=None,filt=None,STEPS=False,s=0.1,ARGS=False):
  # go to fourier space
  f_data = np.fft.fft2(data)
  # get the k-vector (lots of finagling here for fft shift crap)
  if r_data is None:
    K = get_wave(f_data)
    kx,ky = np.fft.fftfreq(f_data.shape[0]),np.fft.fftfreq(f_data.shape[1])
    k = kx[K[0]],ky[K[1]]
    nx,ny = data.shape
    Y,X = np.meshgrid(np.arange(nx),np.arange(ny),sparse=False,indexing='xy')
  #  phplot.imageshow(data)
  #  phplot.imageshow(np.real(r_data))
  #  phplot.imageshow(np.real(r_data*np.exp(+1j*2.*np.pi*(k[0]*X+k[1]*Y))))
    # reference beam
    r_data = np.exp(+1j*2.*np.pi*(k[0]*X+k[1]*Y))


  # filter k-space with a gaussian around data of interest
  if filt is None:
    try:
      gf_data = f_gaussian(f_data,K)*f_data
    except UnboundLocalError:
      K = get_wave(f_data)
    finally:
      gf_data = f_gaussian(f_data,K)*f_data
      filt = np.ones(f_data.shape)
      filt = f_gaussian(filt,K)*filt
#      band = get_band(data,K)
#      filt = f_bandpass(filt,band)
#      filt = hilbert_transform(filt,'x')
  else:
    gf_data = filt*f_data
  # check it out!!
#  phplot.imageshow(phplot.dB_data(gauss_filter))
  # go back to xy space
  g_data = np.fft.ifft2(gf_data)

  o_data = g_data*r_data  # retrieve the wrapped phase from the digital reference beam
  wrapped_phase = np.arctan2(o_data.imag,o_data.real)
  # unwrap the phase (may be unneccesary)
  unwrapped_phase = unwrap_phase(wrapped_phase)
  phase = unwrapped_phase
  #phase = wrapped_phase

  if STEPS:
    return data,f_data,gauss_filter,wrapped_phase,unwrapped_phase,plane,phase

  if ARGS:
    return -phase,r_data,filt

  return -phase
开发者ID:taylo589,项目名称:phproc,代码行数:51,代码来源:phretrieve.py

示例11: compute_local_phase_field

def compute_local_phase_field(camp):
    """ Compute local phase of each cell
    """
    width, height, depth = camp.shape

    # compute thetas
    tau = compute_tau(camp)

    theta = np.empty((width, height)).tolist()
    for j in range(width):
        for i in range(height):
            cur = compute_phase_variable(camp[i, j], tau)
            theta[i][j] = np.array(cur)
    theta = np.rollaxis(np.array(theta), 2, 0)

    # fix phase jumps greater than PI
    for i in range(len(theta)):
        theta[i] = unwrap_phase(theta[i])

    return theta
开发者ID:kpj,项目名称:PyWave,代码行数:20,代码来源:singularity_finder.py

示例12: parse_enz_solution

def parse_enz_solution(cfg, betak):
    if betak.ndim == 2:
        gpf = cfg.cpsf.czern.eval_grid(betak[:, 0])
    else:
        gpf = cfg.cpsf.czern.eval_grid(betak)
    wrph = np.arctan2(gpf.imag, gpf.real)
    wrph = np.mod(wrph, 2*np.pi) - np.pi

    ut1 = time()
    unph = unwrap_phase(wrph.reshape(
        (cfg.fit_L, cfg.fit_K), order='F')).ravel(order='F')
    ut2 = time()

    ft1 = time()
    alpha_hat = cfg.phase_fit.fit(unph)
    ft2 = time()

    alpha_hat[0] = 0.0

    return alpha_hat, ft2 - ft1, ut2 - ut1, wrph, unph
开发者ID:jacopoantonello,项目名称:enzpy,代码行数:20,代码来源:simulation.py

示例13: hilbert_retrieval

def hilbert_retrieval(data,plane=None,filt=None,STEPS=False,direction='x',ARGS=False):
  # fourier transform data and filter
  window_f = np.hanning
  w2 = np.sqrt(np.outer(window_f(data.shape[0]),window_f(data.shape[1])))
  f_data = np.fft.fft2(data)
  if filt is None:
    band = get_band(f_data)
    filt_f_data = f_bandpass(f_data,band)
    hilbert_f_data = hilbert_transform(filt_f_data,direction)
    filt = np.ones(f_data.shape)
    filt = f_bandpass(filt,band)
    filt = hilbert_transform(filt,direction)
  else:
    hilbert_f_data = f_data *filt

  # hilbert-transform
#  phplot.imageshow(phplot.dB_data(filt_f_data))
  hilbert_data = np.fft.ifft2(hilbert_f_data)

  # retrieve the wrapped phase
  wrapped_phase = np.arctan2(hilbert_data.imag,hilbert_data.real)

  # unwrap the phase
  unwrapped_phase = unwrap_phase(wrapped_phase)

  # flatten the data (if required - some methods can use the same level for all data)
  if plane is None:
    plane = diff_level(unwrapped_phase)
  phase = unwrapped_phase - plane

  if STEPS:
    return data,f_data,filt_f_data,hilbert_f_data,hilbert_data,wrapped_phase,unwrapped_phase,plane,phase

  if ARGS:
    return -phase,plane,filt
  return -phase
开发者ID:taylo589,项目名称:phproc,代码行数:36,代码来源:phretrieve.py

示例14: unwrap

 def unwrap(self):
     unwrapped = unwrap_phase(self._PF.phase)
     return unwrapped
开发者ID:coder-guy22296,项目名称:Device_manager,代码行数:3,代码来源:adaptiveOptics_v0.py

示例15: unwrap_phase

"""

import numpy as np
from matplotlib import pyplot as plt
from skimage import data, img_as_float, color, exposure
from skimage.restoration import unwrap_phase


# Load an image as a floating-point grayscale
image = color.rgb2gray(img_as_float(data.chelsea()))
# Scale the image to [0, 4*pi]
image = exposure.rescale_intensity(image, out_range=(0, 4 * np.pi))
# Create a phase-wrapped image in the interval [-pi, pi)
image_wrapped = np.angle(np.exp(1j * image))
# Perform phase unwrapping
image_unwrapped = unwrap_phase(image_wrapped)

fig, ax = plt.subplots(2, 2)
ax1, ax2, ax3, ax4 = ax.ravel()

fig.colorbar(ax1.imshow(image, cmap='gray', vmin=0, vmax=4 * np.pi), ax=ax1)
ax1.set_title('Original')

fig.colorbar(ax2.imshow(image_wrapped, cmap='gray', vmin=-np.pi, vmax=np.pi), ax=ax2)
ax2.set_title('Wrapped phase')

fig.colorbar(ax3.imshow(image_unwrapped, cmap='gray'), ax=ax3)
ax3.set_title('After phase unwrapping')

fig.colorbar(ax4.imshow(image_unwrapped - image, cmap='gray'), ax=ax4)
ax4.set_title('Unwrapped minus original')
开发者ID:A-0-,项目名称:scikit-image,代码行数:31,代码来源:plot_phase_unwrap.py


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