Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Seam Carving 算法

shhhz
September 29, 2021
220

Seam Carving 算法

如何能改变图像大小的同时尽可能保留图片主体? Seam Carving 算法可以解决这个问题。

shhhz

September 29, 2021
Tweet

Transcript

  1. Seam Carving Recipe 1. 计算每个像素的 energy, ⽣成 energy map。 2.

    找出 seam 并删除。 3. 未达到终⽌条件,回到第 1 步。
  2. Energy Function 3. Image Kernels RGB -> Grayscale Grayscale =

    (R + G + B ) / 3. Grayscale = 0.299R + 0.587G + 0.114B Kernels
  3. Dynamic Programming Those who can not remember the past are

    condemned to repeat it. Stairs Problem Go up one step or two steps at a time House Robber Problem • You are a robber who has found a block of houses to rob. • You cannot rob two adjacent houses.
  4. Energy Map Find Seam Seam Energies ? 80+45 seam[i][j] =

    EnergyMap[i][j] + Min(seam[i-1][j-1], seam[i-1][j], seam[i-1][j+1]) 45 405 35 275 1o5 25 100 25 40 5 20
  5. Seam Energies 100 25 130 275 Find Seam interface SeamEnergyCell

    { i: number; j: number; energy: number; prev: SeamEnergyCell | null; } 45 35 50 10
  6. Heap • Max Heap Build Heap Get root Heapify O(

    n) + kO(log n) • Min Heap 8 9 5 Build Heap K Add Heap if lt root 8 9 7 Add Skip O( k) + (n - k)O(log k)