Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Seam Carving 算法
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
shhhz
September 29, 2021
0
320
Seam Carving 算法
如何能改变图像大小的同时尽可能保留图片主体? Seam Carving 算法可以解决这个问题。
shhhz
September 29, 2021
Tweet
Share
More Decks by shhhz
See All by shhhz
概率与随机
shhhz
0
53
游戏中的奥秘
shhhz
0
59
正则表达式
shhhz
0
38
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.7k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.3k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
230
Fireside Chat
paigeccino
41
3.8k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
180
ラッコキーワード サービス紹介資料
rakko
1
2.3M
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
440
GraphQLとの向き合い方2022年版
quramy
50
14k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
1.9k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
61
52k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3k
Mobile First: as difficult as doing things right
swwweet
225
10k
Transcript
Seam Carving Algorithm @Rick Sun
Aspect Ratio Changed Crop Original Scale
Content-aware Resizing Seam Carving Original
Example
Humans Vision 落款 富⼠⼭ 波浪
Computer Vision
Pixel Colors
Energy e(x) 192 Energy: 值越⼤,表示该像素与周围像素对比越⼤。 Energy function
Energy Map Energy function
Energy Map
? How to resize? 哪些像素需要被删除?
1. Optimal 依次删除 energy 最小的像素
2. Pixel 每⾏移除等量 energy 最小的像素
3. Seam 每次移除⼀条 energy 之和最小的 seam
3. Seam 什么是连续? 8 连通路径(8-connected path )
Seam Carving Recipe 1. 计算每个像素的 energy, ⽣成 energy map。 2.
找出 seam 并删除。 3. 未达到终⽌条件,回到第 1 步。
Implements Energy Function 01 Find Seam 02
Energy Function 1. 2.
Energy Function 3. Image Kernels RGB -> Grayscale Grayscale =
(R + G + B ) / 3. Grayscale = 0.299R + 0.587G + 0.114B Kernels
Refer: https://setosa.io/ev/image-kernels/
Implements Energy Function 01 Find Seam 02
Find Seam
Find Seam Brute-force search O(w * 3^h) O(w + h)
The greedy approach
Dynamic Programming Those who can not remember the past are
condemned to repeat it.
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.
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
Find Seam
Seam Energies 100 25 130 275 Find Seam interface SeamEnergyCell
{ i: number; j: number; energy: number; prev: SeamEnergyCell | null; } 45 35 50 10
Other Applications Object Label 01 Image Enlarging 02
Object Removal Set energy to -Infinity
Object Protect Set energy to +Infinity
Image Enlarging Repeat Seam Repeat K Seams
Top K Problem Find Top K largest numbers O(n log
n) 1. Sort 2. Heap sort
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)
3. Quick select Top K Problem O( n) K th?
Thanks!