天天看点

Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance

文章目录

  • Example-Based Style Transfer with Guidance
    • Style Transfer with Guidance
    • Guidance:算法核心
      • 按来源划分
        • Geometry-based Guidance
        • Image-based Guidance
      • 按作用划分
        • Content Guidance
        • Spatial Coherence Guidance
        • Temporal Coherence Guidance
      • Guidance 总结
    • Matching Methods
      • 贪心算法
      • 优化算法
    • 总结

Example-Based Style Transfer with Guidance

基于实例的风格迁移一直是非真实感渲染(NPR)的一项重要手段。最近,神经网络的飞速发展也给予了人们对这个问题极大的关注。神经网络虽可以提供端到端的解决方法,但也存在训练样本和算力需求大以及过程不可控等问题。所以面对某一些具体问题时,神经网络可能并不是最优解。例如19年的 Stylizing Video by Example 用 Style Transfer with Guidance 的非深度方法进行视频的风格迁移,就取得了超过GAN方法的效果。

Style Transfer with Guidance

基于 Guidance 的 Style Transfer 最早由 A.Hertzmann 等在 Image Analogies (算法理解可以参考我之前的博客Image Analogies 笔记)中提出,如下图所示,图像 A 即是一种 Content Guidance ,它可以帮助决定图像 B 中不同的颜色区域该填充什么内容,而该内容对应的具体纹理由 A’ 决定。

Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance

我粗浅地认为基于 Guidance 的风格迁移,实际上是用 Guidance 引导纹理合成 (texture synthesis)。即将风格的迁移细化为了像素的迁移。而产生 Guidance 的目的即是为了帮助找到更理想的风格图像与待生成图像之间的像素对应关系。

Guidance:算法核心

Guidance 的选取直接决定了结果。那么 guidance 该怎么取?

按来源划分

我认为按来源主要分为两种,一种是 geometry-based guidance,另一种是 image-based guidance 。

Geometry-based Guidance

基于几何信息的 Guidance 往往提供较好的引导信息。因为几何信息没有表面纹理信息的干扰,能够很好地传递结构、形状、高光、阴影等信息。而且在有几何模型的情况下,容易提取。如 StyLit: Illumination-Guided Example-Based Stylization of 3D Renderings 中为了进行以光照为引导的风格迁移,使用了如图所示的几种几何信息:

Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance
Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance
  • Full global imllumination render
  • Direct diffuse
  • Direct specluar
  • First two diffuse bounces
  • Diffuse interreflection

而在 Stylizing Animation By Example 中主要使用了如下图所示的几种 guidance:

Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance
  • Orientation field
  • Velocity and Occlusion :Velocity 实际上由两个 channel 组成,V+ 与 V-。V+ 和 V- 分别记录了当前帧与下一帧和上一帧的位置差。若 P 为当前帧的某一像素,则有上一帧对应的像素Pt-1 = P - V-§; Pt-1 + V+(Pt-1) = P; 所以有:
Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance

Image-based Guidance

如果没有几何信息,那么只能巧妙的使用图像特征来构造guidance。如 Stylizing Video by Example 中的 Guidance 如下图所示,是比较典型的 Image-based Guidance,其中有:

Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance
  • Color
  • Mask
  • Position :Position guidance 实际上是使用了 SIFT 特征的 Opitcal flow 组成 SIFT Flow,如下图所示。
    Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance
  • Edge
  • Temp

按作用划分

按来源划分比较直接,但对算法的设计并没有什么指导意义。而按作用划分则更有实际意义。我认为按作用又可以大体上分为 Content guidance 、Spatial coherence guidance、Temporal coherence guidance。

Content Guidance

Content Guidance 是内容的 guidance 如 Stylizing Video by Example 中的 Color 和 Mask, StyLit 中的Full global imllumination render等。Content Guidance 引导内容的填充,更加注重整体。

Spatial Coherence Guidance

Content Guidance 有一定的引导 Spatial Coherence 的作用,但是为了强化该作用,往往都会单独提取特征形成 Spatial Coherence Guidance。如 Stylizing Video by Example 中的 Position 和 Edge。 Stylizing Animation By Example 中的 Orientation。

Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance

在 Stylizing Video by Example 中,很好地阐述了 Spatial Coherence Guidance 的作用。

  • (b) 和 (a) 为有无 Position guidance 的区别,(a) 中没有,则可能左下角挎包的像素匹配到身后的木箱上了。(b) 中加入了Position guidance,限制了像素位置的跳变,能够保持图像的结构,从而产生更加符合的结果。
  • (d) 和 ( c ) 为有无 Edge guidance 的区别,Edge guidance 在文中为高频特征,一般高频特征都在边缘处,所以叫 Edge guidance。它能帮助算法保持清晰的边缘,并且可以再一定程度上抵消光照变化的影响。

Temporal Coherence Guidance

一般只生成单张图片不回考虑 Temporal Coherence,但是生成序列图或者视频的时候为了避免 flickering,一般都会选择加入帧间的限制,即 Temporal Coherence Guidance。

  • Stylizing Animation By Example 中的 Velocity and Occlusion。分两个 channel 来分别记录每个像素与前一帧和后一帧的位置差。
  • Stylizing Video by Example 中则用 SIFT Flow 先预生成该帧,再作为 guidance。

Guidance 总结

Guidance 一般都会从Content 、Spatial Coherence、Temporal Coherence 角度考虑。构造一个能满足上述所有问题的特征使比较困难的,但是好在我们可以使用多个 guidance channel 分别构造上述 guidance。 如果有几何信息则比较好保持图像结构,如果没有智能巧妙地构造特征维持 Spatial Coherence。对于视频和序列图的生成,最好加入帧间约束保证 Temporal Coherence。

Matching Methods

基于 guidance 的 style transfer 大部分都是基于 patch matching 的。利用 guidance 构造好特征,也是为了能够取得更优的 matching 结果。

贪心算法

像 Image Analogies 中采用的就是贪心算法,它对每个像素都寻找最佳匹配,每个像素都是独立的,每个像素的最小误差和即为整体误差。如下图所示:

Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance

优化算法

基于贪心算法的 patch match 可以取得较好的结果,但是很难维持一些高层(high-level)结构。所以有许多人提出了基于优化算法的 patch match。迭代优化是一种现在比较流行的算法,如在 StyLit 中用类似 EM (最大期望)算法的迭代方式优化如下能量表达式:

Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance

其中

Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance
Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance

在第一步通过对对目标图像中的每个像素 q 寻找原图像中的最近邻匹配像素 p 建立NNF(nearest neighbour field),第二步,将原图像 p 的邻域平均值赋给 q。循环上述步骤即可收敛得到更好的结果。

但是这种做法会产生 wash-out effect 如下图所示(我认为主要是因为会有很多不同的 q 匹配到相同的 p 导致的 )

Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance

所以,为了让不同的 q 尽量匹配到不同的 p,也是为了让 p 被均衡使用。作者使用反向 NNF,对每一个原图中的 p 的邻域 patch 在没有匹配对象的目标图像 q 的邻域 patch 中找一个最佳匹配。

Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance

因为原图与目标图像的分布可能差别较大,但是强制匹配就可能会遇到上图所述的问题。这时,对每个 patch 对的匹配误差进行排序后,可以发现误差会陡然增大,整个成双曲线的形式,其拐点就在斜率为 1 的位置,如下图所示。所以设置误差门限 T ,当误差超过 T 的时候就重置原图像,使每个像素 patch 又可以重新使用。

Example-Based Style Transfer with Guidance 总结Example-Based Style Transfer with Guidance

我认为,根据上述约束当算法最终收敛后,实际上相当于目标图像获得的是大块的原图像纹理,所以能得到高保真度。

总结

Example-Based Style Transfer with Guidance 算法流程大体上是用风格图和 guidance 组成特征去进行 patch match,由于各种 guidance 的引入可以取得很好地结果。但是目标图像的纹理都来自于风格图像,那么就得不到在风格图中没有的信息。所以更加适合用于序列图或者视频这样每帧图像包含的内容相似度较高的情况。

继续阅读