skimage 学习第三天:ski官网示例程序总结(2)

13 Gabors / Primary Visual Cortex “Simple Cells” from an Image

这个很像在生物学神经视觉和深度学习计算机视觉相关的东西。。。贴着估计也没用,请自动移驾到原文

14 Shape Index

形状指数是一种局部曲率的单一值度量,它来源于Koenderink所定义的Hessian的特征值。范·多尔恩[1]。它可以被用来根据它们表面的形状来找到结构。形状索引映射到-1到1的值,表示不同类型的形状(请参阅文档以获得详细信息)。在这个例子中,生成一个带有点的随机图像,这应该被检测到。形状指数1代表球帽,我们想要检测的斑点的形状。最左边的情节显示生成的图像,图像的中心显示了一个3 d渲染,以强度值作为一个3 d表面的高度,和正确的显示了形状指数(s)。可见,形状指数容易放大的局部形状的噪音,但不为所动的全球现象(如不均匀照明)。蓝色和绿色的标记是指从理想形状中偏离不超过0.05的点。为了减弱信号中的噪声,在另一个高斯模糊通过(屈服s)之后,绿色标记从形状指数(s)中提取出来。请注意,由于它们没有达到所需的形状,所以没有检测到它们之间的相互连接。

skimage 学习第三天:ski官网示例程序总结(2)_第1张图片

 First create the test image and its shape index

image = create_test_image()
点击打开链接
s = shape_index(image)

# In this example we want to detect 'spherical caps',
# so we threshold the shape index map to
# find points which are 'spherical caps' (~1)

target = 1
delta = 0.05

point_y, point_x = np.where(np.abs(s - target) < delta)
point_z = image[point_y, point_x]

# The shape index map relentlessly produces the shape, even that of noise.
# In order to reduce the impact of noise, we apply a Gaussian filter to it,
# and show the results once in

s_smooth = ndi.gaussian_filter(s, sigma=0.5)

point_y_s, point_x_s = np.where(np.abs(s_smooth - target) < delta)
point_z_s = image[point_y_s, point_x_s]

15Gabor filter banks for texture classification

在这个例子中,我们将看到如何根据Gabor过滤银行对纹理进行分类。Gabor滤波器的频率和方向表示与人类视觉系统相似。这些图像是通过各种不同的Gabor过滤器的真实部件进行过滤的。然后,过滤后的图像的均值和方差被用作分类的特征,这是基于简单的最小平方误差。

skimage 学习第三天:ski官网示例程序总结(2)_第2张图片

results = []
kernel_params = []
for theta in (0, 1):
    theta = theta / 4. * np.pi
    for frequency in (0.1, 0.4):
        kernel = gabor_kernel(frequency, theta=theta)
        params = 'theta=%d,\nfrequency=%.2f' % (theta * 180 / np.pi, frequency)
        kernel_params.append(params)
        # Save kernel and the power image for each image
        results.append((kernel, [power(img, kernel) for img in images]))

fig, axes = plt.subplots(nrows=5, ncols=4, figsize=(5, 6))
plt.gray()

16 Local Binary Pattern for texture classification

在这个例子中,我们将看到如何根据LBP(局部二元模式)对纹理进行分类。LBP观察中心点周围的点,并测试周围的点是否大于或小于中心点(即给出一个二进制结果)。在尝试在图像上使用LBP之前,它有助于查看LBPs的示意图。

skimage 学习第三天:ski官网示例程序总结(2)_第3张图片

上面的图显示了以黑色(或白色)表示像素的例子,这些像素比中心像素更少(或更多)。当周围的像素都是黑色的或全是白色的,那么这个图像区域是平的(也就是没有特征的)。连续的黑色或白色像素组被认为是一致的模式,可以被解释为角或边。如果像素在黑色和白色像素之间来回切换,那么这个模式就被认为是不均匀的。当使用LBP检测纹理时,您可以在一个图像补丁上测量一个LBPs的集合,并查看这些LBPs的分布。让我们把LBP应用到一个砖结构上。

skimage 学习第三天:ski官网示例程序总结(2)_第4张图片

The histogram of the LBP result is a good measure to classify textures. Here, we test the histogram distributions against each other using the Kullback-Leibler-Divergence.

def kullback_leibler_divergence(p, q):
    p = np.asarray(p)
    q = np.asarray(q)
    filt = np.logical_and(p != 0, q != 0)
    return np.sum(p[filt] * np.log2(p[filt] / q[filt]))


def match(refs, img):
    best_score = 10
    best_name = None
    lbp = local_binary_pattern(img, n_points, radius, METHOD)
    n_bins = int(lbp.max() + 1)
    hist, _ = np.histogram(lbp, normed=True, bins=n_bins, range=(0, n_bins))
    for name, ref in refs.items():
        ref_hist, _ = np.histogram(ref, normed=True, bins=n_bins,
                                   range=(0, n_bins))
        score = kullback_leibler_divergence(hist, ref_hist)
        if score < best_score:
            best_score = score
            best_name = name
    return best_name


brick = data.load('brick.png')
grass = data.load('grass.png')
wall = data.load('rough-wall.png')

refs = {
    'brick': local_binary_pattern(brick, n_points, radius, METHOD),
    'grass': local_binary_pattern(grass, n_points, radius, METHOD),
    'wall': local_binary_pattern(wall, n_points, radius, METHOD)
}

# classify rotated textures
print('Rotated images matched against references using LBP:')
print('original: brick, rotated: 30deg, match result: ',
      match(refs, rotate(brick, angle=30, resize=False)))
print('original: brick, rotated: 70deg, match result: ',
      match(refs, rotate(brick, angle=70, resize=False)))
print('original: grass, rotated: 145deg, match result: ',
      match(refs, rotate(grass, angle=145, resize=False)))

skimage 学习第三天:ski官网示例程序总结(2)_第5张图片

17 Image Deconvolution

  • Richardson-Lucy deconvolution 

该算法基于PSF(点扩展函数),其中PSF被描述为光学系统的脉冲响应。模糊的图像通过许多迭代得到了增强,需要手动调整。

skimage 学习第三天:ski官网示例程序总结(2)_第6张图片

# Add Noise to Image
astro_noisy = astro.copy()
#为啥要加噪音后处理?是不是可以把这种先随机噪音再迭代恢复的过程类比下现在的深度?
astro_noisy += (np.random.poisson(lam=25, size=astro.shape) - 10) / 255.

# Restore Image using Richardson-Lucy algorithm
deconvolved_RL = restoration.richardson_lucy(astro_noisy, psf, iterations=30)

  • Unsupervised Wiener
该算法基于数据学习,具有自调的正则化参数。这并不常见,并基于以下出版物1。该算法基于一个迭代的吉布斯采样器,它可以绘制图像的后条件律、噪声功率和图像频率功率的采样。
[1] François Orieux, Jean-François Giovannelli, and Thomas Rodet, “Bayesian estimation of regularization and point spread function parameters for Wiener-Hunt deconvolution”, J. Opt. Soc. Am. A 27, 1593-1607 (2010)

skimage 学习第三天:ski官网示例程序总结(2)_第7张图片
astro = conv2(astro, psf, 'same')
astro += 0.1 * astro.std() * np.random.standard_normal(astro.shape)

deconvolved, _ = restoration.unsupervised_wiener(astro, psf)
# Create mask with three defect regions: left, middle, right respectively
mask = np.zeros(image_orig.shape[:-1])
mask[20:60, 0:20] = 1
mask[160:180, 70:155] = 1
mask[30:60, 170:195] = 1

# Defect image over the same region in each color channel
image_defect = image_orig.copy()
for layer in range(image_defect.shape[-1]):
    image_defect[np.where(mask)] = 0

image_result = inpaint.inpaint_biharmonic(image_defect, mask,
                                          multichannel=True)

18 Inpainting

插图1是重建图像和视频中丢失或破环的部分的过程。重建工作应该以完全自动化的方式进行,利用在非受损区域提供的信息。在这个例子中,我们展示了如何通过基于双调和方程的in绘制算法来绘制假像素的图像——假设2 3 4。

[1] Wikipedia. Inpainting https://en.wikipedia.org/wiki/Inpainting
[2] Wikipedia. Biharmonic equationhttps://en.wikipedia.org/wiki/Biharmonic_equation
[3] N.S.Hoang, S.B.Damelin, “On surface completion and image inpainting by biharmonic functions: numerical aspects”, https://arxiv.org/abs/1707.06567
[4] C. K. Chui and H. N. Mhaskar, MRA Contextual-Recovery Extension of Smooth Functions on Manifolds, Appl. and Comp. Harmonic Anal., 28 (2010), 104-113, DOI: 10.1016/j.acha.2009.04.004
skimage 学习第三天:ski官网示例程序总结(2)_第8张图片


# Create mask with three defect regions: left, middle, right respectively
mask = np.zeros(image_orig.shape[:-1])
mask[20:60, 0:20] = 1
mask[160:180, 70:155] = 1
mask[30:60, 170:195] = 1

# Defect image over the same region in each color channel
image_defect = image_orig.copy()
for layer in range(image_defect.shape[-1]):
    image_defect[np.where(mask)] = 0

image_result = inpaint.inpaint_biharmonic(image_defect, mask,
                                          multichannel=True)

19 Non-local means denoising for preserving textures

在本例中,我们使用非本地方法过滤器来表示宇航员图像的一个细节。非本地意味着算法代替像素的价值平均其他像素值的选择:小补丁以其他像素比较集中在感兴趣的像素,和像素的平均只执行补丁接近当前的补丁。因此,该算法可以恢复纹理的纹理,这将被其他去噪的algoritm所模糊。当fastmode参数为假时,在计算补丁距离时,将空间高斯加权应用于补丁。当快速模式为真时,应用了在补丁上使用均匀空间加权的更快的算法。对于这两种情况,如果提供了噪声标准偏差、sigma,则在计算补贴距离时,会减去预期的噪声方差。这可以使图像质量得到适度的改善。估计西格玛函数可以为非本地方法算法设置h(和可选的西格玛)参数提供一个良好的起点。h是一个常数,它控制着补丁的衰减,作为补丁之间距离的函数。更大的h允许在类似的补丁之间进行更平滑的处理。在这个演示中,h被手动调优,以给出每个变体的近似最佳情况。


skimage 学习第三天:ski官网示例程序总结(2)_第9张图片

# slow algorithm
denoise = denoise_nl_means(noisy, h=1.15 * sigma_est, fast_mode=False,
                           **patch_kw)

20 Structural similarity index

当比较图像时,平均平方误差(MSE)虽然简单,但并不能很好地反映出感知的相似性。 结构相似的目的是通过将纹理考虑到1、2,来解决这个缺点。 这个例子展示了两个对输入图像的修改,每个都有相同的MSE,但是有非常不同的平均结构相似度指数。
[1] Zhou Wang; Bovik, A.C.; ,”Mean squared error: Love it or leave it? A new look at Signal Fidelity Measures,” Signal Processing Magazine, IEEE, vol. 26, no. 1, pp. 98-117, Jan. 2009.
[2] Z. Wang, A. C. Bovik, H. R. Sheikh and E. P. Simoncelli, “Image quality assessment: From error visibility to structural similarity,” IEEE Transactions on Image Processing, vol. 13, no. 4, pp. 600-612, Apr. 2004.
skimage 学习第三天:ski官网示例程序总结(2)_第10张图片

mse_none = mse(img, img)
ssim_none = ssim(img, img, data_range=img.max() - img.min())

21 Radon transform(没看懂。。。。)

在计算机断层扫描中,断层扫描重建的问题是从一组投影中获得一个层析片图像。 投影是通过在二维物体上画出一组平行光线来形成的,将物体的对比在每条射线上的积分分配到投影中的单个像素上。 二维物体的单个投影是一维的。 为了使物体的计算机层析成像重建,必须获得几个投影,每一个都对应于与物体有关的光线的不同角度。 在几个角度上的投影集合称为sin图,它是原始图像的线性变换。 在计算机断层扫描中,反氡转换用于从测量的投影(sin图)中重建二维图像。 反氡转换的实际、准确的实现并不存在,但是有几种好的近似算法可用。 当反氡转换从一组投影中重新构造物体时,(向前)氡转换可用于模拟断层扫描实验。 该脚本执行氡转换来模拟一个层析成像实验,并根据模拟所形成的正弦信号重新构造输入图像。 比较了两种进行反氡转换和重构原始图像的方法:过滤后投影(FBP)和同步代数重建技术(SART)。 关于重建的进一步信息,请看

[1] (1, 2) AC Kak, M Slaney, “Principles of Computerized Tomographic Imaging”, IEEE Press 1988. http://www.slaney.org/pct/pct-toc.html
[2] Wikipedia, Radon transform,http://en.wikipedia.org/wiki/Radon_transform#Relationship_with_the_Fourier_transform
[3] (1, 2) S Kaczmarz, “Angenaeherte Aufloesung von Systemen linearer Gleichungen”, Bulletin International de l’Academie Polonaise des Sciences et des Lettres, 35 pp 355–357 (1937)
[4] AH Andersen, AC Kak, “Simultaneous algebraic reconstruction technique (SART): a superior implementation of the ART algorithm”, Ultrasonic Imaging 6 pp 81–94 (1984)

The forward transform

As our original image, we will use the Shepp-Logan phantom. When calculating the Radon transform, we need to decide how many projection angles we wish to use. As a rule of thumb, the number of projections should be about the same as the number of pixels there are across the object (to see why this is so, consider how many unknown pixel values must be determined in the reconstruction process and compare this to the number of measurements provided by the projections), and we follow that rule here. Below is the original image and its Radon transform, often known as its sinogram
sinogram = radon(image, theta=theta, circle=True)
skimage 学习第三天:ski官网示例程序总结(2)_第11张图片

Reconstruction with the Filtered Back Projection (FBP)

滤波后投影的数学基础是傅里叶片定理2。 它利用傅里叶空间的投影和插值的傅里叶变换得到图像的二维傅里叶变换,然后将图像倒转过来形成重建的图像。 过滤后的投影是执行反氡转换的最快方法之一。 FBP的唯一可调参数是过滤器,它应用于傅里叶变换投影。 它可用于在重建过程中抑制高频噪声。 skimage为过滤器提供了一些不同的选项。
reconstruction_fbp = iradon(sinogram, theta=theta, circle=True)
error = reconstruction_fbp - image
print('FBP rms reconstruction error: %.3g' % np.sqrt(np.mean(error**2)))
skimage 学习第三天:ski官网示例程序总结(2)_第12张图片

你可能感兴趣的:(图像处理,skimage)