天天看點

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 的引入可以取得很好地結果。但是目标圖像的紋理都來自于風格圖像,那麼就得不到在風格圖中沒有的資訊。是以更加适合用于序列圖或者視訊這樣每幀圖像包含的内容相似度較高的情況。

繼續閱讀