位相展开

有些信号只能观察到模2*pi,这也适用于二维和三维图像。在这些情况下,需要相位解缠来恢复潜在的解缠信号。在本例中,我们将演示一种算法 1 实施于 skimage 在工作中遇到这样的问题。一维、二维和三维图像都可以使用skImage进行解包。在这里,我们将演示二维情况下的位相展开。

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, sharex=True, sharey=True)
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')
Original, Wrapped phase, After phase unwrapping, Unwrapped minus original

输出:

Text(0.5, 1.0, 'Unwrapped minus original')

展开过程接受被屏蔽的数组,并且还可以选择性地采用循环边界来连接图像的边缘。在下面的例子中,我们研究了一个简单的相位斜坡,它通过遮罩图像的一行被一分为二。

# Create a simple ramp
image = np.ones((100, 100)) * np.linspace(0, 8 * np.pi, 100).reshape((-1, 1))
# Mask the image to split it in two horizontally
mask = np.zeros_like(image, dtype=bool)
mask[image.shape[0] // 2, :] = True

image_wrapped = np.ma.array(np.angle(np.exp(1j * image)), mask=mask)
# Unwrap image without wrap around
image_unwrapped_no_wrap_around = unwrap_phase(image_wrapped,
                                              wrap_around=(False, False))
# Unwrap with wrap around enabled for the 0th dimension
image_unwrapped_wrap_around = unwrap_phase(image_wrapped,
                                           wrap_around=(True, False))

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

fig.colorbar(ax1.imshow(np.ma.array(image, mask=mask), cmap='rainbow'), ax=ax1)
ax1.set_title('Original')

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

fig.colorbar(ax3.imshow(image_unwrapped_no_wrap_around, cmap='rainbow'),
             ax=ax3)
ax3.set_title('Unwrapped without wrap_around')

fig.colorbar(ax4.imshow(image_unwrapped_wrap_around, cmap='rainbow'), ax=ax4)
ax4.set_title('Unwrapped with wrap_around')

plt.tight_layout()
plt.show()
Original, Wrapped phase, Unwrapped without wrap_around, Unwrapped with wrap_around

在上图中,遮罩的行可以看到是一条横跨图像的白线。底部一行中的两个展开图像之间的区别很明显:如果不展开(左下角),遮罩边界上方和下方的区域根本不会交互,从而导致任意整数乘以2 pi的两个区域之间的偏移。我们可以像解开两张独立的图像一样解开这些区域。在启用垂直方向(右下角)绕排的情况下,情况发生了变化:现在允许展开路径从图像的底部通过到顶部,反之亦然,这实际上提供了一种确定两个区域之间的偏移的方法。

参考文献

1

Miguel Arevallilo Herraez、David R.Burton、Michael J.Lalor和Munther A.Gdeisat,《基于沿非连续路径的可靠性排序的快速二维相位展开算法》,《应用光学》,第41卷,第35期,第7437页,2002

脚本的总运行时间: (0分0.630秒)

Gallery generated by Sphinx-Gallery