IMAGE RESIZING & SEAMCARVING CS16: Introduction to Algorithms & Data Structures Thursday, January 23, 14 1.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 5 Author: Julia Richards and R. Scott Hawley.
1 Copyright © 2010, Elsevier Inc. All rights Reserved Fig 2.1 Chapter 2.
By D. Fisher Geometric Transformations. Reflection, Rotation, or Translation 1.
Business Transaction Management Software for Application Coordination 1 Business Processes and Coordination.
Tutorial 3 – Creating a Multiple-Page Report
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
You will need some paper!
0 - 0.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
Environmental Remote Sensing GEOG 2021
Polygon Scan Conversion – 11b
ZMQS ZMQS
The Advantage Series © 2004 The McGraw-Hill Companies, Inc. All rights reserved Working with Access Microsoft Office Access 2003 Chapter 1.
Calypso Construction Features
1 Clustering of location- based data Mohammad Rezaei May 2013.
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 5. 2 List Utilities Scheme built-in procedures –(list x y z...) –(list-ref lst index) –(length lst) –(append.
CS16: Introduction to Data Structures & Algorithms
BT Wholesale October Creating your own telephone network WHOLESALE CALLS LINE ASSOCIATED.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 10 Arrays and Tile Mapping Starting Out with Games & Graphics.
Chapter Objectives To learn about recursive data structures and recursive methods for a LinkedList class To understand how to use recursion to solve the.
Chapter 17 Linked Lists.
ABC Technology Project
1 Designing Hash Tables Sections 5.3, 5.4, Designing a hash table 1.Hash function: establishing a key with an indexed location in a hash table.
Chapter 9 -- Simplification of Sequential Circuits.
1 An Introduction to Pivot Tables Using Excel 2000.
Creating Tables in a Web Site
Lesson 7: Using Tables Courseware #: 3240
Adobe InDesign CS5 - Illustrated Unit G: Working with Color and Tables.
Working with Web Tables
© S Haughton more than 3?
© Charles van Marrewijk, An Introduction to Geographical Economics Brakman, Garretsen, and Van Marrewijk.
© Charles van Marrewijk, An Introduction to Geographical Economics Brakman, Garretsen, and Van Marrewijk.
VOORBLAD.
Review Pseudo Code Basic elements of Pseudo code
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
Squares and Square Root WALK. Solve each problem REVIEW:
YO-YO Leader Election Lijie Wang
© 2012 National Heart Foundation of Australia. Slide 2.
Past Tense Probe. Past Tense Probe Past Tense Probe – Practice 1.
Chapter 5 Test Review Sections 5-1 through 5-4.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
1 First EMRAS II Technical Meeting IAEA Headquarters, Vienna, 19–23 January 2009.
Addition 1’s to 20.
25 seconds left…...
Shifting, Reflecting, and Stretching Graphs
Copyright © Cengage Learning. All rights reserved.
Test B, 100 Subtraction Facts
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® PowerPoint 2010 © 2011 The McGraw-Hill Companies,
Week 1.
We will resume in: 25 Minutes.
Lesson 15 Working with Tables
A SMALL TRUTH TO MAKE LIFE 100%
1 Unit 1 Kinematics Chapter 1 Day
Chapter 11 Creating Framed Layouts Principles of Web Design, 4 th Edition.
1 PART 1 ILLUSTRATION OF DOCUMENTS  Brief introduction to the documents contained in the envelope  Detailed clarification of the documents content.
How Cells Obtain Energy from Food
Towers of Hanoi
Lecture Roger Sutton CO331 Visual Programming 13: Multi-dimensional Arrays 1.
Improved Seam Carving for Video Retargeting Authors: Michael Rubinstein, Ariel Shamir and Shai Avidan Source: ACM Transactions on Graphics (TOG), Volume.
Kshitij Padalkar 13 th Oct Contents: In one Line… Need Solutions and Other Work Definition and Maths Energy, Seam Pixel Removal Criteria Other Energy.
Dynamic Image Resizing
Presentation transcript:

IMAGE RESIZING & SEAMCARVING CS16: Introduction to Algorithms & Data Structures Thursday, January 23, 14 1

Outline 1) Image Resizing 2) Seamcarve Algorithm 3) Digression: argmin Thursday, January 23, 14 2

Image Resizing Difficult to shrink a photo horizontally without skewing the proportions of the content within Goal is an algorithm that can identify significant aspects of an image Resize a photo by discarding uninteresting areas, maintain proportions of important items Thursday, January 23, 14 3

Image Resizing Thursday, January 23, 14 4 Important elements of the photo should be preserved Repeating areas of the image (water, sand) can be reduced

Image Resizing Thursday, January 23, 14 5 SUCCESS! fail

Image Resizing How to do it? In order to narrow an image, delete unimportant pixels Importance of a pixel can be approximated by looking at how much it varies from its neighbors Thursday, January 23, 14 6

Image Resizing Grayscale 3x3 image with the following pixel intensities Whats the importance of the center pixel? Thursday, January 23, 14 7

Image Resizing Grayscale 3x3 image with the following pixel intensities Whats the importance of the center pixel? =9 Thursday, January 23,

Image Resizing Apply this method to every pixel of an image to determine the most and least important pixels Thursday, January 23, 14 9 Low High

Image Resizing: Approach 1 Remove the least important pixels in order Looks terrible! Not removing the same amount from each row, causing jagged right side Thursday, January 23, 14 10

Image Resizing: Approach 2 Remove n least important pixels in each row Still not great, too much shifting between adjacent rows Thursday, January 23, 14 11

Image Resizing: Approach 3 Remove the column whose total importance is smallest, and repeat Much better! But not perfect… Thursday, January 23, 14 12

Image Resizing The problem: removing an entire column (or an entire row) distorts the image What pixels would we want to remove to resize this image? Thursday, January 23, 14 13

Image Resizing: Seamcarve The solution is a seam: a path from top to bottom that moves left or right by at most one pixel per row In this example, a vertical and horizontal seam is shown Thursday, January 23, 14 14

Image Resizing: Seamcarve Using the seamcarving approach. Near perfection! Thursday, January 23, 14 15

Seamcarve: Another Application User marks the object to be removed as unimportant by artificially deflating the importance of the target pixels These pixels are automatically removed by the algorithm Thursday, January 23, 14 16

The Seamcarve Algorithm function find_least_important_seam(vals) Input: vals, a 2D array of importance values Output: sequence of column-indices, each differing from the last by at most 1, with corresponding pixels being the least-total- importance vertical seam Thursday, January 23, [[ - S - - ], [ S ], [ - S - - ], [ - - S - ]] [1, 0, 1, 2]

Data structures we will need costs - 2D array, filled in from bottom to top costs[row][col] holds the total importance of the lowest cost seam starting from the bottom row and ending at costs[row][col] dirs - 2D array, filled in at the same time as costs dirs[row][col] holds the direction (-1, 0, or 1) of the previous pixel in the lowest cost seam ending at costs[row][col] Thursday, January 23, valscostsdirs costs[row][col] = min(costs[row+1][col-1 to col+1]) + vals[row][col]

Data structures illustrated Thursday, January 23, original image vals costs highlow

Finding the least important seam Once costs has been completely filled in, the cell with the minimum value in the top row of costs will be the first pixel in the least important seam of the entire image. Starting from that pixel, we can use the dirs array to backtrack our way through the rest of the seam and build the final list of column indices. Thursday, January 23, 14 20

Seamcarve Pseudocode function find_least_important_seam(vals): dirs = 2D array with same dimensions as vals costs = 2D array with same dimensions as vals costs[height-1] = vals[height-1] // initialize bottom row of costs for row from height-2 to 0: for col from 0 to width-1: costs[row][col] = vals[row][col] + min(costs[row+1][col-1], costs[row+1][col], costs[row+1][col+1]) dirs[row][col] = -1, 0, or 1 // depending on min // Find least important start pixel min_col = argmin(costs[0]) // Returns index of min in top row // Create seam by tracing from top seam = [] seam[0] = min_col for row from 0 to height-2: seam[row+1] = seam[row] + dirs[row][seam[row]] return seam Thursday, January 23, 14 21

Digression: Whats argmin() ? What does the min() function do? Returns the minimum output value of a function So what about the argmin() function? Given a function f(x), returns the value of x for which f(x) is minimal. Examples: Consider the function f(x) = -1+x 2 min(f) = -1 argmin(f) = 0 Consider the array L = [5, 4, 1, 3, 9] min(L) = 1 argmin(L) = 2 The index of the minimum value Thursday, January 23, 14 22

Readings You might want to check out the original seamcarve paper Final.pdf Final.pdf Dont expect to understand all of it but it has a lot of great examples and is a worthwhile read Thursday, January 23, 14 23