Coordinates for Instant Image Cloning

מסמכים קשורים
אתגר קוביות מחייכות תכולה: 12 קוביות חוברת הוראות ופתרונות ספרון הכולל 60 חידות חידות בדרגות קושי שונות תפיסה חזותית וחשיבה לוגית הקדמה המשחק פרצופים

שקופית 1

מצגת של PowerPoint

PowerPoint Presentation

Homework Dry 3

BIG DATA תיאור הקורס המונח Big Data הולך וצובר תאוצה בשנים האחרונות, הוא הופך למגמה רווחת בתעשייה. המשמעות הפרקטית של המונח Big Data הינה טכנולוגיות נ

Overview of new Office 365 plans for SMBs

Slide 1

PowerPoint Presentation

eriktology The Prophets Book of 1 st Kings [1]

סדנת תכנות ב C/C++

ניטול ידני

eriktology The Writings Book of Proverbs [1]

eriktology The Writings Book of Psalms [1]

תרגיל 3 בקורס תוכנה 1

eriktology The Prophets Book of Isaiah [1]

לקוחות וחברים יקרים,

Homework-L9-Skills-1.pub

Why to contact <NORAIL.EMEKREFAIM.GMAIL.COM>

Microsoft PowerPoint - 07_tdd.ppt

PowerPoint Presentation

פיסיקה 1 ב' מרצים: גולן בל, משה שכטר, מיכאל גדלין מועד ב משך המבחן 3 שעות חומר עזר: דף נוסחאות מצורף, מחשבון אסור בהצלחה! חלק א'

טיפול זוגי בגישת AEDP טיפול חווייתי דינמי מואץ Accelarated Experiential Dynamic Psychotherapy

שבוע 4 סינטקס של HACK ASSEMBLY ניתן להשתמש בשלושה אוגרים בלבד:,A,D,M כולם בעלי 16 ביטים. M אינו אוגר ישיר- הוא מסמן את האוגר של ה RAM שאנחנו מצביעים ע

לקוחות וחברים יקרים, הנדון: סקר בדבר תנאים משפטיים של עסקאות הון סיכון שנת 2022 אנו מתכבדים להציג בפניכם תוצאות הסקר לשנת 0210, המנתח תנאים משפטיים של

מקביליות

TEL- AVIV UNIVERSITY SACKLER FACULTY OF MEDICINE THE STANLEY STEYER SCHOOL OF HEALTH PROFESSIONS DEPARTMENT OF NURSING אוניברסיטת תל-אביב הפקולטה לרפו

Microsoft PowerPoint - CE_Candidates_2011.ppt [Compatibility Mode]

תרגול מס' 1

<4D F736F F D20EEE5F4FA20FAF7F6E9F820E4EEF9F4E7E420F9ECE420E4EEF9F4E7E420F9ECE5>

_20

פתרון מוצע לבחינת מה"ט ב_שפת c מועד ב אביב תשע"ט, אפריל 2019 מחברת: גב' זהבה לביא, מכללת אורט רחובות שאלה מספר 1 מוגדרת מחרוזת המורכבת מהספרות 0 עד 9.

ארסמוס+ עדכון

Microsoft PowerPoint - 07_tdd.ppt

הגשה תוך שבוע בשעת התרגול

שקופית 1

מדד מכון גזית-גלוב למחירי דירות GGII רקע כללי מכון גזית-גלוב לחקר נדל"ן במרכז הבינתחומי הרצליה מפרסם לראשונה מדד חודשי למחירי דירות. מדד חדש זה מבוסס

PowerPoint Presentation

א.ד.וי.ריידר של עדי ברדה 1. הורדה והתקנה הורד את האפליקציה WD( )AdvRider מהחנות והתקן. למכשירי אנדרואיד בלבד. 2. הגדרות ראשונות לאחר ההתקנה צריך לבצע

Guide For Examinees Inter-University Psychometric Entrance Test HEBREW PROFICIENCY TEST (YAEL) This test is intended for examinees who take the Psycho

מקביליות

הטכניון מכון טכנולוגי לישראל הפקולטה למדעי המחשב הוראות הגשה: ההגשה בזוגות. הוסיפו שמות, ת.ז., אי-מייל, תא אליו יש להחזיר את התרגיל ואת תשובותיכם לתרג

שעור 6

תורת הקומפילציה

HUJI Syllabus

הליבה של פסיכיאטריה ונחיצות הפסיכיאטריה בחברה חופשית ומתוקנת

מקביליות

Slide 1

Data Analyst Expert 042 שעות תיאור ההכשרה: בעולם העסקי של היום, נתונים, מידע וחיזוי הם העתיד של כל ארגון. כמויות המידע שנאספות בארגונים ובאנושות כולה

(Microsoft PowerPoint \372\347\370\345\372 \341\362\351\343\357 \344\343\351\342\351\350\354\351)

Slide 1

PowerPoint Presentation

מסמך1

<4D F736F F D20FAF8E2E9EC203220E0F7E520EEE020FAF9F2E1>

תהליך הגשה והנחיות כתיבה לעבודת גמר / תזה פרקים הקדמה תהליך הגשת עבודת המחקר ואישורה הנחיות תוכן לעבודת המחקר הנחיות כתיבה לעבודת המחקר הקדמה במסגרת ל

Comp. Arch. Lecture 1

מבוא למדעי המחשב

Slide 1

w-2003

התגוננות בפני כוחות האופל

תרגול 1

עסקאו

מבוא למדעי המחשב

ex1-bash

מטרות הקורס סמינר מחקר רגשות בשירות סמסטר א' תשע"ט דר' אריק חשין הקורס מיועד להקנות מיומנות בחשיבה מחקרית וביצוע מחקר באמצעו

תרגול מס' 4: המתרגם שימוש במחלקות קיימות מחרוזות, קבצים, וקבלת קלט מהמשתמש

דוגמאות שהוצגו בהרצאה 10 בקורס יסודות מערכות פתוחות דוגמה 1 דוגמאות של פונקציות ב- awk שמראות שהעברת פרמטרים של משתנים פשוטים היא by value והעברת פרמט

לימודים קורסים השתלמויות לפורטל המשרות באתר הבוגרים משרות חמות הנדסת חשמל מתמטיקה פיזיקה מדעי המחשב תעשייה וניהול הנדסת מכונות הנדסה ביורפואית הנדסה א

95% בוגרים להשכלה גבוהה 70% דור ראשון במשפחתם יוזמה להקמת בית ספר תיכון על פי מודל ה - Picture Big תמונההגדולהה

Microsoft PowerPoint - Lecture1

PowerPoint Presentation

מבוא לתכנות ב- JAVA תרגול 11

Counting the Omer Leviticus 23:15-16 And from the day on which you bring the sheaf of elevation offering the day after the Sabbath you shall count off

מספר מחברת: עמוד 1 מתוך 11 ת"ז: תשע"א מועד ב סמסטר א' תאריך: 00:11 שעה: 0 שעות הבחינה: משך כל חומר עזר אסור בשימוש בחינה בקורס: מבוא למדעי ה

מהוא לתכנות ב- JAVA מעבדה 3

SI Draft for TC 2101 Approval

מבט על הוראת תלמידים מחוננים ומצטיינים בכיתה רגילה

מבנה מחשבים ספרתיים

מבוא לאסמבלי

PowerPoint Presentation

ח ס פ - י ש י ז ר א מ w w w. p t o r a. c o. i l S a l e p t o r a. c o. i l

מבוא למדעי המחשב

ט ט ט ט ט ט ט ל ל ל Strong Verbs Diagnostics P 3ms P 3fs P 2ms P 2fs P 1cs P 3cp P 2mp P 2fp P 1cp Qal (G) simple active קט ק ט ל ה קט ל ת קט ל ת קט ל

Untitled

תמליל:

אוניברסיטת תל אביב הפקולטה למדעים מדוייקים על שם ריימונד ובברלי סאקלר בית הספר למדעי המחשב עיבוד תמונה מיידי באמצעות קואורדינטות מחושבות מראש חיבור זה הוגש כחלק מהדרישות לקבלת התואר "מוסמך אוניברסיטה" M.Sc. באוניברסיטת תל אביב בית הספר למדעי המחשב על ידי גיל הופר עבודת המחקר לתזה זו נערכה באוניברסיטת תל אביב בהנחייתו של פרופסור דניאל כהן אור, אוניברסיטת תל אביב אוקטובר 2010 1

תקציר פעולות לעריכת תמונות וסרטי וידיאו הפכו בשנים האחרונות לפעולות נפוצות ביותר, המתבצעות ע"י חובבנים ומקצוענים על בסיס יום-יומי. אחת מפעולות העריכה השימושיות ביותר היא פעולת ה"שכפול הרציפה" ) Seamless,(Cloning בה מבקש המשתמש להעתיק חלק מתמונה אחת (תמונת מקור) ולייבא אותה לתוך תמונה אחרת (תמונת יעד), תוך כדי שמירה על רציפות התמונה הנוצרת. בשנים האחרונות הוקדשה תשומת לב רבה בקרב החוקרים בתחומי הגרפיקה הממוחשבת ועיבוד התמונה לצורך שכלול וייעול השיטה הנ"ל. פעולה זאת מתבצעת בד"כ על הנגזרות של תמונות המקור והיעד ע"י פתרון של משוואת Poisson עם תנאי סף מסוג,Dirichlet אשר מבצעת אינטרפולציה רציפה וחלקה של אי-ההתאמות על שפת האיזור המשוכפל, על פני האיזור המשוכפל כולו. בעוד שהניסיון מהשנים האחרונות מלמד כי פעולה זה משיגה תוצאות טובות, ולכן היא שולבה בשלל תוכנות מסחריות (הבולטת ביותר היא Photoshop של חברת,(Adobe לפעולה זו מספר חסרונות, כאשר החסרונות הבולטים ביותר הם זמן ריצה גבוה ודרישות זיכרון ניכרות. בעבודה זאת אנו מציגים גישה אלטרנטיבית, המבוססת על קואורדינטות מחושבות-מראש, בה במקום לפתור מערכת משוואות ליניארית גדולה על מנת לחשב את האינטרפולציה המוזכרת למעלה, ערכו של האינטרפולנט בכל פיקסל פנימי ניתן כצירוף משוקלל של הערכים על שפת האיזור המשוכפל. ספציפית, הגישה שלנו מבוססת על Mean Value,(MVC) Coordinates המהוות הרחבה לקואורדינטות בריצנטריות עבור מצולעים כלליים בדו-מימד. לקואורדינטות אלו מספר תכונות ההופכות אותן למתאימות במיוחד למשימת האינטרפולציה הנדרשת, ובפועל העובדה כי הן מקיימות את תכונת ה Mean Value של פונקציות הרמוניות הופכת את הפתרונות המתקבלים תוך כדי שימוש בקואורדינטות הללו לדומים במיוחד לפתרונות המתקבלים מפתרון משוואת Poisson המקבילה. 2

כמו כן, אנו מנתחים את ביצועי השיטה, הן במימוש על יחידת העיבוד הכללית (CPU) והן על יחידת העיבוד הגרפית (GPU) ומספקים שני ייעולים משמעותיים לשיטה. הייעול הראשון מתבסס על העובדה שהאינטרפולנט המתקבל מהשיטה הוא חלק מאוד הרחק מהשפה, ולכן מספיק לחשבו ברזולוציה הולכת ויורדת באופן אדפטיבי ככל שהמרחק מהשפה גדל. על מנת לממש ייעול זה באופן יעיל, אנו מחשבים את האינטרפולנט מעל רשת משולשים אדפטיבית mesh).(adaptive triangular הייעול השני מתבסס על העובדה שרק מספר קטן של נקודות על השפה משפיע על נקודה ספציפית בתוך האינטרפולנט, ולכן ניתן לחשב את האינטרפולנט באופן יעיל בהרבה אם בוחרים את נקודות ההשפעה עליו באופן מתוחכם יותר. אנו עושים זאת ע"י שימוש בסכמה היררכית לחישוב זה. השימוש בקוארדינטות מחושבות-מראש מהווה יתרון משמעותי בהיבטים של זמן-חישוב, קלות מימוש, דרישות זיכרון ויכולת מקבול חישובים, יתרון המאפשר לנו לבצע שיכפול של חלקי תמונה גדולים בזמן-אמת, ושיכפול קטעי וידיאו באופן אינטראקטיבי. יתרה מכך, אנו מדגימים מספר יישומים והרחבות של השיטה, המאפשרים בין השאר תפירת תמונות פנורמה באופן מהיר במיוחד, וטיפול בפגמים נפוצים הנוצרים מפעולת השכפול. 3

TEL AVIV UNIVERSITY RAYMOND AND BEVERLY SACKLER FACULTY OF EXACT SCIENCES SCHOOL OF COMPUTER SCIENCE Coordinates for Instant Image Cloning Thesis submitted in partial fulfillment of the requirements for the M.Sc. degree of Tel Aviv University By Gil Hoffer The research work for this thesis has been carried out at Tel Aviv University under the supervision of Prof. Daniel Cohen Or, TAU October, 2010 4

Abstract Image and video editing operations have become extremely common in recent years, due to the vast availability of digital cameras and camcorders. These operations are being carried by amateurs, as well as professionals, on a daily basis. One of the most useful image editing operations, which has received considerable research attention in recent years, is the so called seamless cloning operation, in which a source image patch is seamlessly imported into a target image patch. This operation is typically carried out in the gradient domain of the image, by solving a Poisson equation with Dirichlet boundary conditions, which smoothly interpolates the discrepancies between the boundary of the source patch and the target across the entire cloned area. While experience from recent years shows that this operation achieves good results (which led to the incorporation of this operation in commercial tools, such as Adobe TM Photoshop TM ), this operation has some drawbacks - most notably, a long running time and a high memory footprint. In this work we introduce an alternative, coordinate-based approach, where rather than solving a large linear system to perform the aforementioned interpolation, the value of the interpolant at each interior pixel is given by a weighted combination of values along the boundary. More specifically, our approach is based on Mean-Value Coordinates (MVC) which are a form of generalized barycentric coordinates for polygons in 2D. These coordinates have some attributes which render them especially suitable for the required interpolation task. Moreover, as these coordinates respect the mean-value attribute of harmonic functions, the results of the 5

Abstract 6 coordinate-based cloning process are extremely similar to the results of the classic Poisson equation based cloning process. While analysing the performance of the coordinate-based method, both using a CPU implementation and a GPU implementation, we provide two significant optimizations for this method. The first optimization utilizes the fact that the interpolant we calculate is very smooth away from the boundary of the patch, thus it is sufficient to calculate it in lower resolution away from the boundary. This resolution can be reduced adaptively, and we do so by calculating the interpolant on an adaptive triangular mesh. The second optimization utilizes the fact that only a small number of pixels from the boundary actually affect a given pixel inside the interpolant, thus we can calculate the interpolant much more efficiently if we choose the pixels from the boundary which influence the interpolant value at each inner pixel in a more sophisticated manner. In order to do so, we use an hierarchic sampling scheme. The use of coordinates is advantageous in terms of speed, ease of implementation, small memory footprint, and parallelizability, enabling real-time cloning of large regions, and interactive cloning of video streams. The simplicity and inherent efficiency of this method allow us to showcase several other applications, such as image stitching for large panoramas and dealing with some common image cloning artifacts.

Contents 1 Introduction 10 2 Background 14 2.1 Gradient domain methods...................... 14 2.1.1 Discrete Partial Derivatives................. 15 2.1.2 Poisson Equation...................... 16 2.1.3 Boundary Conditions.................... 17 2.1.4 Solving the Poisson equation................ 19 2.2 Mean-Value Coordinates...................... 21 3 Mean-Value Seamless Cloning 25 3.1 Adaptive mesh........................... 28 3.2 Hierarchical boundary sampling.................. 29 4 Implementation and Performance 32 4.1 CPU implementation........................ 32 4.2 GPU implementation........................ 33 4.3 Comparison with previous approaches............... 34 5 Results and Extensions 36 5.1 MVC vs. Poisson.......................... 36 5.2 Instant seamless cloning...................... 37 5.3 Mean-Value Video Cloning..................... 38 7

CONTENTS 8 5.4 MVC Stitching........................... 41 5.5 Selective Boundary Suppression.................. 43 6 Discussion and Conclusions 46 6.1 Limitations............................. 46 6.2 Future Work............................. 47

List of Figures 1.1 Harmonic and MVC based cloning and membranes........ 12 2.1 Dirichlet and Neumann boundary conditions............ 18 2.2 Concealment of the Caracol Falls.................. 22 2.3 Removing the spots from a cheetah................. 22 2.5 Angle definitions for mean-value coordinates........... 23 2.4 Cloning an image onto different backgrounds........... 24 3.1 Visualization of Poisson image cloning formulations....... 26 3.2 Adaptive triangular mesh with hierarchic subsampling...... 30 5.1 Comparison of MVC based and Poisson based object removal.. 37 5.2 Poisson vs. MVC over a highly concave region........... 38 5.3 Seamless cloning results with rotation and scaling......... 39 5.4 Seamless video cloning versus simple composite......... 40 5.5 Seamless video cloning....................... 41 5.6 Set-Up for MVC based image stitching............... 42 5.7 MVC based panoramic stitching.................. 43 5.8 Selective boundary suppression................... 45 9

Chapter 1 Introduction A wide variety of image and video editing tasks may be effectively accomplished by gradient domain techniques, which operate directly on the gradient field of an image [FLW02, PGB03, LZPW04, ADA + 04, MP08]. One of the most useful gradient domain tools is Poisson cloning: seamless insertion of a source image patch into a target image (Figure 1.1). This operation has attracted significant research attention in recent years [PGB03, ADA + 04, WRA04, JSTS06] and it is featured in professional image editing products [Geo04]. All gradient domain techniques eventually solve a large sparse linear system, the Poisson equation. This motivated a number of works proposing fast Poisson solvers for various scenarios [Sze06, Aga07, KH08] and for solving the Poisson equation on the GPU [BFGS03, MP08]. In this work, we introduce a new, coordinate-based approach that performs seamless cloning, as well as a number of other related operations in a direct manner, without ever having to form and solve systems of equations. Our approach is fast, straightforward to implement, and features a small memory footprint. The bulk of the computation may be performed completely in parallel, making it an ideal candidate for a GPU implementation. When performing Poisson cloning, one typically solves the Poisson equation, where the gradients inside the cloned region come from the source patch, and the 10

Chapter. 1: Introduction 11 Dirichlet boundary conditions are prescribed by the target image. Perez et al. [PGB03] observed that solving this Poisson equation is equivalent to solving the Laplace equation with the Dirichlet boundary conditions set to the difference along the boundary between the source patch and the target image. In other words, Poisson cloning constructs a harmonic (or membrane) interpolant that smoothly spreads the discrepancies along the boundary to the entire cloned area. While the gradient field of this membrane has minimal L 2 -norm, there is no evidence that this particular membrane is necessarily optimal from the perceptual standpoint. Thus, our key idea is to construct a different smooth interpolating membrane directly, i.e., without solving a linear system. While the membrane we construct is not identical to the harmonic one, our final results are nevertheless typically indistinguishable from Poisson cloning (Figure 1.1). Specifically, our objective is to find a harmonic-like interpolant to some values along the boundary. Recent advances in the field of transfinite interpolation allow solving this problem using generalized barycentric coordinates. An important instance is Floater s Mean-Value Coordinates (MVC) [Flo03]. These coordinates were specifically designed for constructing smooth harmonic-like interpolants by mimicking the mean-value property of harmonic functions, and they are given by a simple closed-form formula. Thus, the resulting membrane may be evaluated in parallel for any point inside the region at a cost linear in the number of boundary vertices. We further observe that due to the smoothness of the membrane away from the boundary, it is not necessary to evaluate it at each and every pixel inside the cloned area. Instead, it suffices to evaluate the membrane only at the vertices of an adaptive mesh, and obtain the values at the remaining pixels by linear interpolation. A similar optimization was recently utilized by Agarwala [Aga07] to solve large Poisson systems, such as those arising in gradient domain stitching, with a small memory footprint. Another important optimization that we introduce is adaptive hierarchical sampling of the boundary.

Chapter. 1: Introduction 12 This paper is organized as follows. We start by describing the mechanisms behind Poisson Image Editing and current state-of-the-art image cloning techniques in Chapter 2. We also quickly describe the mean-value coordinates in that chapter. Then, we go on to present the use of mean-value coordinates for seamless image cloning in Chapter 3, followed by a description of an efficient implementation on the CPU and on the GPU and comparison to existing approaches in Chapter 4. In Chapter 5 we go on to present a number of applications and extensions of our approach, specifically, we discuss real-time interactive seamless video cloning, seamless stitching of large panoramas, and removal of smudging artifacts that sometimes occur with seamless cloning. We sum up the work and suggest a few ideas for future work in Chapter 6. (a) Source patch (b) Laplace membrane (c) MV membrane (d) Target image (e) Poisson cloning (f) MV cloning Figure 1.1: Poisson cloning smoothly interpolates the error along the boundary of the source and the target regions across the entire cloned region (the resulting membrane is shown in (b)), yielding a seamless composite (e). A qualitatively similar membrane (c) may be achieved via transfinite interpolation, without solving a linear system. (f) Seamless cloning obtained instantly using the mean-value interpolant.

Chapter. 1: Introduction 13 In summary, our specific contributions are: A new, coordinate-based method for seamless cloning, which is easy to implement, features a small memory footprint, and is highly parallelizable. Real-time seamless cloning and healing of still images and video sequences on the CPU, as well as on the GPU. Extensions to related operations, such as seamless stitching. Parts of the work presented in this thesis have already been published [FHL + 09].

Chapter 2 Background 2.1 Gradient domain methods Psychologists have long discovered that the human visual system is much more sensitive to local contrasts than to absolute luminances or to slow changes in the luminance [LM71, Pal99]. This is a feature of the human color perception system which ensures that the perceived color of objects remains relatively constant under varying illumination conditions, helping us in the process of object identification. In particular, slow luminance changes, which are suppressed by the human visual system as part of lightness constancy, may be often superimposed over an image without a noticeable effect. Traditionally in image editing we think of the main entities as mathematical functions; Digital images are usually given over a discrete 2D lattice that samples the color intensities in the scene. While it is very natural to operate on these functions directly, i.e., to explicitly change or set pixel intensities when editing an image, it is rather hard to take advantage of the above lightness constancy properties using these direct image manipulation operations. Instead, it would be easier to take advantage of these properties by manipulating the derivatives of the function which represents the image. In this approach the difference between neighboring pixels are mapped, minimized, and copied and pasted, depending upon the appli- 14

Chapter 2.1 Gradient domain methods 15 cation. Using the derivatives to perform such operations is commonly referred to as working in the gradient domain. Such gradient domain methods have gained significant popularity in recent years, as they are useful to perform a variety of tasks, ranging from shadow removal [Wei01, FHD02], to tone mapping [FLW02], seamless stitching [LZPW04, ADA + 04, Aga07], image cloning [PGB03, Geo04, JSTS06], seamless video editing [WRA04], and recently, gradient domain painting [MP08]. In order to manipulate the derivatives of an image, we must first define some basic notations and mathematical tools we ll use throughout this paper. 2.1.1 Discrete Partial Derivatives Let s start by considering a discrete 2D function f (x,y): N N [0..1] defined on a discrete finite lattice, where x and y are integers. This function represent the image intensities at each pixel. For the sake of simplicity we consider only grayscale values, as employing the same techniques over each one of the RGB channels of the image independently is trivial. One way to define the discrete partial derivatives of f is f x (x,y) = f (x + 1,y) f (x,y) and f y (x,y) = f (x,y + 1) f (x,y). (2.1) If we assume that f (x, y) samples a continuously differentiable function defined on the plane, then it is easy to see, using Talyor expansion, that these formulas approximate its first derivatives. This approximation becomes more accurate as the lattice spacing tends to zero or when the higher-order (second and above) derivatives tend to zero. Although digital images are defined at a fixed resolution and they are discontinuous in their essence, we use the terminology of differential operators to describe their discrete analogs. The particular definition in (2.1), used to approximate the partial derivatives, is not the only one possible, but since it avoids certain numerical complications we will use it throughout our discussion. The vector consisting of these partial derivatives is called the gradient vector. We use the

Chapter 2.1 Gradient domain methods 16 same term for the discrete analog, ( f x (x,y), f y (x,y) ), and also the same notation, f (x,y). Now, we will describe a basic tool which will allow us to define and alter images indirectly, through their derivatives, and not by setting their pixel values directly. This can be done in several ways which are better suited for different applications. Here we describe one of these methods which suites our image editing goals the most, namely - the (homogenous) Poisson Equation. 2.1.2 Poisson Equation The (homogenous) Poisson Equation allows us to reconstruct a function given values for its directional derivatives and some other constraints. Namely, in our discrete 2D scenario we are given with a vector field, i.e., two functions u(x,y) and v(x,y), to define the gradient of an image f (x,y). This vector field is assumed to be arbitrary, however, in most practical scenarios, it is the result of manipulating the gradient field of some input image. Ideally, in this case we would like to find f (x,y) such that f x (x,y) = u(x,y) and f y (x,y) = v(x,y). As this invloves almost two constraints (each yielding a single equation) per pixel (x, y) while there is only one variable per pixel in f (x,y), the resulting system is overconstrained and we are not likely to find any function meeting these constraints. A common and natural way of overcoming this difficulty is to use a least squares optimization to find a function f (x,y) whose gradients are closest to u(x,y) and v(x,y) in the least squares sense. More formally, the function f is defined by the solution of the following minimization problem min f x,y ( fx (x,y) u(x,y) ) 2 + ( fy (x,y) v(x,y) ) 2. (2.2) Differentiating this cost function with respect to all its variables and equating to zero yields the following set of equations (while using the discrete definition for partial derivatives in (2.1)) f (x + 1,y) 2 f (x,y)+ f (x 1,y) + f (x,y + 1) 2 f (x,y) + f (x,y 1) u(x,y) + u(x 1,y) v(x,y) + v(x,y 1) = 0.

Chapter 2.1 Gradient domain methods 17 Denoting f (x+1,y) 2 f (x,y)+ f (x 1,y) by f xx (x,y) and f (x,y+1) 2 f (x,y)+ f (x,y 1) by f yy (x,y), these equations read more compactly as f xx (x,y) + f yy (x,y) = u x (x,y) + v y (x,y), where u x and v y are defined analogously to f x and f y. Since f xx (x,y) and f yy (x,y) approximate the second derivative of f with respect to x and y, this equation can be viewed as the discrete version of the Poisson equation 2 f (x,y) = div ( u(x,y),v(x,y) ), where 2 f (x,y) denotes the discrete Laplacian f xx (x,y) + f yy (x,y) and div is the discrete divergence operator defined by u x (x,y) + v y (x,y). This relation sheds light also on the Laplace equation whose discrete counter-part is 2 f (x,y) = 0. This equation searches for a function f (x, y) with the least variation between neighboring points. Thus, these discrete analogs teach us that the Poisson equation attempts to find a function whose gradients are the closest to some given vector field, appearing in its right hand side, and the Laplace equation looks for a function with a minimal gradient field, both in the least squares sense. Later in this chapter we will give a practical recipe for solving these equations. 2.1.3 Boundary Conditions While examining the homogeneous Poisson and Laplace equations defined above, one quickly notices that there is no one unique solution for them. For instance, any shift of f (x,y) by a constant will always be valid solution for the Laplace Equation. In order to make these solutions unique (and more controllable), we specify boundary conditions, which constrain the solution set of the equations. There are several useful types of boundary conditions, and here we will briefly describe two of them.

Chapter 2.1 Gradient domain methods 18 The Dirichlet (or first type) boundary condition which specify the values the solution f (x,y) needs to take on the boundary of the domain. The Neumann (or second type) boundary condition which specify the values that the normal derivative of the solution ( f ˆn = f (x,y) ˆn) needs to take on the boundary of the domain ( ˆn is the unit vector normal to the boundary at (x,y)). It should be noted that under some assumptions in the discrete settings, these conditions are equivalent, but we won t delve into that. It should also be noted that mixtures of these two boundary conditions exist (for instance, the mixed boundary condition which employs the Dirichlet boundary condition on some parts of the boundary and the Neumann boundary condition on other parts of the boundary, or the Robin boundary condition which specifies a linear combination of Dirichlet and Neumann boundary conditions), but we won t delve into that either. Figure 2.1: A Poisson problem with Dirichlet boundary condition (left), and with Neumann boundary condition (right).

Chapter 2.1 Gradient domain methods 19 2.1.4 Solving the Poisson equation As we have just shown, in order to reconstruct an image from a given gradient field, one must solve the Poisson equation with given boundary conditions. That is, we wish to solve 2 f (x,y) = div ( u(x,y),v(x,y) ), while respecting the boundary conditions f Ω = f Ω (for example when using Dirichlet type boundary conditions, and Ω is the closed boundary of the image we re reconstructing). That is, we need the following equation satisfied inside Ω : f (x + 1,y) 2 f (x,y)+ f (x 1,y) + f (x,y + 1) 2 f (x,y) + f (x,y 1) u(x,y) + u(x 1,y) v(x,y) + v(x,y 1) = 0. Which can be rewritten as: f (x + 1,y) 4 f (x,y) + f (x 1,y) + f (x,y + 1) + f (x,y 1) = u(x,y) u(x 1,y) + v(x,y) v(x,y 1). While on the boundary of Ω we simply require that f (x,y) = f (x,y). Thus, we can construct a sparse equation set which has one equation for each pixel in the image. In order to do so, we must first introduce an alternative indexing for the image, such that we could relate to any pixel in the image by using a single index. If we denote by W,H the width and the height (respectively) of the image, in the alternative indexing, pixel (i, j) is denoted by the single index i + j W. We ll denote the number of pixels (which is also the number of equations and the number of unknowns) by n. Note that n = W H. By assuming that the known pixels are the last K equations in the set (for simplicity of display), and that the known values respectively are c 1...c k, we can

Chapter 2.1 Gradient domain methods 20 write it in matrix notation: 1 1 4 1 1......... 1 1 4 1 1.......... 1 1 4 1 1 0 I K K x 1. x n = div G c 1. c k. (2.3) This system can be solved by using any standard sparse linear system solver (such as [Tol03]). This Poisson-based approach for reconstructing a new image from a modified gradient field (actually reconstructing an image which is closest in the L 2 -norm sense to the gradient field) is quite popular and is used in many recent works. For example, in Poisson cloning [PGB03], the gradient field (sometimes referred to as the guidance field) inside the cloned region is taken from the source image, while the values of the target image along the boundary of the cloned region are used to define the Dirichlet boundary conditions for the equation (see Figure 2.4 for examples of Poisson cloning). Another good example for the usage of Poisson equations for image manipulations can be seen in [ADA + 04], where numerous image editing operations are shown (including panoramic stitching, relighting, object concealment and more). The Poisson-based approach is also used to perform local retouching of images, for instance, for the purpose of concealment of local features (see Figures 2.3, 2.2 for two examples of such local retouching). This kind of retouching is also known as healing and is implemented in Adobe TM Photoshop TM [Geo04]. Solving the Poisson equation for large images is a computational and memory intensive task. Agarwala [Aga07] observed that in the case of gradient domain stitching, one essentially solves for an offset function that is smooth away from

Chapter 2.2 Mean-Value Coordinates 21 the seams. This makes it possible to obtain an accurate solution by constructing a reduced linear system using an adaptive quadtree subdivision of the domain. This method has been shown to be significantly faster and more scalable than general Poisson solvers for stitching large images. We also take advantage of smoothness and use an adaptive mesh to speed up our computation and to make it scalable; however, in contrast to Agarwala we avoid solving a linear system altogether. A common artifact introduced by Poisson based image cloning is a smudging effect which appears at areas of high gradients (as the optimal solution in the L 2 -norm sense will try to smooth this high gradient across the domain). Our coordinate based system will also suffer from such artifacts, which we eliminate by incorporating an additional human-assisted smudge-removal step (see more details in section 5.5). Another approach to handle these artifacts is given in [JSTS06] where an alternative boundary which does not pass through high-gradient areas (if possible) is automatically generated. We can take advantage of this approach and use the selection refinement phase as a preprocessing stage in our coordinate based framework. McCann and Pollard [MP08] describe a fast GPU implementation of a multigrid Poisson solver, with which they achieve real-time interactive performance for gradient domain image editing operations, including seamless cloning. While their system outperforms previous methods, it does involve a substantial memory footprint, and the authors report that performance drops down once this footprint exceeds the available video memory. 2.2 Mean-Value Coordinates Recently, there has been significant interest in using generalized barycentric coordinates for solving transfinite interpolation problems [Wac75, Flo03, War96, DF09], that is, using these coordinates to construct functions over a planar domain in such a way that they match a given function on the boundary. In his

Chapter 2.2 Mean-Value Coordinates 22 Figure 2.2: Concealment of the Caracol Falls. Figure 2.3: Removing the spots from a cheetah. seminal paper, Floater [Flo03] introduced the Mean-Value Coordinates (MVC) which are motivated by the Mean-Value Theorem for harmonic functions. These coordinates approximate a harmonic-like solution to the boundary interpolation problem. They are well-defined over the entire plane for arbitrary planar polygons without self-intersections, smooth (C, except at the polygon vertices where they are C 0 ), and invariant under similarity transformations [HF06]. MVC coordinates have also been extended to 3D polyhedra and used for space deformation [JSW05, FKR05]. Several similar generalized barycentric coordinates have been proposed in recent years, each with its own advantages and disadvantages [JMD + 07, LKCOL07, LLCO08, WBCG09]. In this work, we explore the novel use of MVC as a computationally attractive alternative for solving the Poisson equation in certain image editing tasks.

Chapter 2.2 Mean-Value Coordinates 23 In the remainder of this section, we quickly define the 2D mean-value interpolant, and refer the reader to the references mentioned above for detailed derivations in 2D and in 3D. Consider a closed 2D polygonal boundary curve (with counter-clockwise ordering) P = (p 0,p 1,...,p m = p 0 ), p i R 2. The mean-value coordinates of a point x R 2 with respect to P are given by where λ i (x) = w i m 1 j=0 w, i = 0,...,m 1, (2.4) j w i = tan(α i 1/2) + tan(α i /2), (2.5) p i x and α i is the angle p i,x,p i+1 (see Figure 2.5). Once computed, these coordinates may be used to smoothly interpolate any function f defined at the boundary vertices: m 1 f (x) = i=0 λ i (x) f (p i ). (2.6) p i+1 p i p i 1 α i α i 1 x Figure 2.5: Angle definitions for mean-value coordinates.

Chapter 2.2 Mean-Value Coordinates 24 (b) On the beach. (a) Source patch (c) In the snow. (d) In the desert. Figure 2.4: Seamlessly cloning a polar bear onto different backgrounds using Poisson Image Editing [PGB03]. Note how the surronding background of the polar bear is concealed.

Chapter 3 Mean-Value Seamless Cloning In this chapter we explain in detail how mean-value coordinates may be used to perform instant seamless image cloning. Let S R 2 be the domain of the source image and T R 2 be the domain of the target image for cloning. Let us denote by g : S R, f : T R the source and target image intensities over their respective domains. Let P s S denote the source patch that we would like to clone seamlessly into P t T. We assume that these patches are isomorphic, and that their boundaries, P s and P t, are polygonal curves with the same number of vertices. Poisson cloning computes a function f : P t R by solving the Poisson equation: 2 f = div g w/ Dirichlet boundary conditions f Pt = f. (3.1) In other words, Poisson cloning seeks a function f that agrees with the target image f on the boundary of the target region P t, whose gradient field is as close as possible to that of the source image g. Pérez et al. [PGB03] noted that solving the above Poisson equation is equivalent to solving the Laplace equation (by performing a simple variable substitution f = f g): 2 f = 0, w/ Dirichlet boundary conditions f Pt = f g. (3.2) 25

Chapter. 3: Mean-Value Seamless Cloning 26 The final outcome of the cloning is then simply defined as f = g + f. (3.3) This formulation reveals that Poisson cloning in fact constructs a smooth membrane (a harmonic function) f that interpolates the difference f g between the target and source images on the boundary of P t across the entire region (see Figure 3.1 for visualization of the two alternative formulations). Figure 3.1: A visualization of the two equivilant formulations for Poisson image editing. The original formulation is given in the left, while an alternative Laplace based formulation is given in the right. As stated earlier, we propose to construct a similar smooth interpolating membrane f in an entirely different manner, using mean-value interpolation, as described below. The most obvious advantage of using the mean-value interpolant is that there exists a simple closed-form formula for constructing it, hence eliminating the need to solve a large linear system. Consider a point x P t with boundary P t = (p 0,p 1,...,p m = p 0 ). The meanvalue interpolant obtaining the values f g at the boundary P t is given at point x by m 1 r(x) = i=0 λ i (x)( f g)(p i ), (3.4) where λ i (x), i = 0,...,m 1 are the mean-value coordinates with respect to P t, as defined by equations (2.4 2.5). The result of mean-value cloning is then given,

Chapter. 3: Mean-Value Seamless Cloning 27 similarly to eq. (3.3), by f = g + r. (3.5) Algorithm 1 MVC Seamless Cloning 1: {Preprocessing stage} 2: for each pixel x P s do 3: {Compute the mean-value coordinates of x w.r.t. P s } 4: λ 0 (x),...,λ m 1 (x) = MVC(x,y, P s ) 5: end for 6: for each new P t do 7: {Compute the differences along the boundary} 8: for each vertex p i of P t do 9: diff i = f (p i ) g(p i ) 10: end for 11: for each pixel x P t do 12: {Evaluate the mean-value interpolant at x} 13: r(x) = m 1 i=0 λ i(x) diff i 14: f (x) = g(x) + r(x) 15: end for 16: end for An unoptimized mean-value cloning procedure is given in pseudocode in Alg. 1. This routine precomputes the mean-value coordinates of each pixel inside the source patch P s once the patch is selected and then repeatedly performs mean-value interpolation for each location P t in the target image. It is easy to see that the number of operations is O(nm), where n is the number of pixels in the cloned region, while m is the number of boundary pixels. Since the mean-value coordinates are precomputed and stored, the memory footprint is also O(nm). To make MVC cloning fast and scalable, we introduce two optimizations, which are described below.

Chapter 3.1 Adaptive mesh 28 3.1 Adaptive mesh The mean-value interpolant is very smooth away from the boundary of the cloned region. Thus, for all practical purposes, much of the computation in Alg. 1 may be avoided by constructing an adaptive triangular mesh over P s. We use the CGAL [Cga07] library to generate the adaptive mesh. An example is shown in Figure 3.2. A mesh-based procedure is given in pseudocode in Alg. 2. Once the mesh is available (line 2 in Alg. 2), we only need to compute and store the mean-value coordinates (line 5 in Alg. 2) at each mesh vertex. Likewise, the evaluation of the interpolant (line 14 in Alg. 2) is also only performed at the mesh vertices, and the value of the membrane at each pixel is obtained by linear interpolation of the three values at the vertices of the containing triangle (line 18 in Alg. 2). The number of these vertices is in practice roughly linear in the number of boundary pixels. This reduces the total complexity of computing the coordinates and of evaluating the interpolant to O(m 2 ), enabling interactive performance when cloning regions of moderate size.

Chapter 3.2 Hierarchical boundary sampling 29 Algorithm 2 MVC Seamless Cloning with Adaptive Mesh 1: {Preprocessing stage} 2: M = AdaptiveMesh 3: for each vertex v M do 4: {Compute the mean-value coordinates of v w.r.t. P s } 5: λ 0 (v),...,λ m 1 (v) = MVC(x,y, P s ) 6: end for 7: for each new P t do 8: {Compute the differences along the boundary} 9: for each vertex p i of P t do 10: diff i = f (p i ) g(p i ) 11: end for 12: for each mesh-vertex v M do 13: {Evaluate the mean-value interpolant at v} 14: r(v) = m 1 i=0 λ i(v) diff i 15: end for 16: for each pixel x P t do 17: {use linear interpolation to calculate the membrane value at x} 18: r(x) = interpolate(r, M) 19: f (x) = g(x) + r(x) 20: end for 21: end for 3.2 Hierarchical boundary sampling A further significant speedup is achieved by hierarchically sampling the boundary, rather than using all of the boundary pixels. This idea is inspired by adaptive hierarchical approaches, such as fast particle simulation algorithms [CGR88] and hierarchical radiosity [HSA91]. Similarly to Coulomb potential fields and solid angles, the mean-value weight of each boundary vertex decays quickly with distance.

Chapter 3.2 Hierarchical boundary sampling 30 Thus, an accurate approximation of the membrane may be achieved by sampling the boundary with density that is inversely proportional to the distance, as demonstrated in Figure 3.2. In practice, only a constant number of boundary vertices are used when computing the coordinates and the membrane at each mesh vertex, reducing the total cost of these operations to O(m). Specifically, we first construct a 1D hierarchy over the sequence of boundary pixels. Each coarser level in the hierarchy is obtained by dropping every other point in the previous (finer) level. Note that by this construction, if a vertex is present at some coarse level in the hierarchy, it is also present in all the finer levels. The process stops once the number of points in the coarsest level falls below a predefined constant (16 in our implementation). Figure 3.2: An adaptive triangular mesh constructed over the region to be cloned. The red dots on the boundary show the positions of boundary vertices that were selected by adaptive hierarchical subsampling for the mesh vertex indicated in blue. Next, for each mesh vertex x, we traverse to hierarchy from the top (coarse) level down. Let p k i s,pk i,pk i+s be three consecutive vertices at the k-th level of the

Chapter 3.2 Hierarchical boundary sampling 31 hierarchy, where s is the index step between successive vertices at that level. If each of the following three conditions hold: x p k i > ε dist p k i s,x,p k i < ε ang p k i,x,p k i+s < ε ang then the mean-value weight (2.5) corresponding to p k i at x is sufficiently small and no further refinement of the boundary is necessary around p k i. If this is not the case, denser sampling is required in order to provide a better approximation of the membrane. Therefore, we insert two additional points, and repeat the same test for each of the three vertices at the next (finer) level: p k+1 i s/2, pk+1 i, and p k+1 i+s/2. In our current implementation we set the distance and angle thresholds ε dist and ε ang to: ε dist = # boundary pixels 16 2.5 k and ε ang = 0.75 0.8 k, where k is the current depth in the hierarchy (k = 0 at the coarsest level). While these expressions were found to provide a good tradeoff between speed and visual quality in our experiments, they are not necessarily optimal, and could benefit from further tuning. When given an error function f g on the boundary, care must be taken to avoid aliasing due to subsampling of the boundary. Thus, we progressively lowpass filter f g to obtain adequately band-limited values at each hierarchy level, before computing the interpolants at any of the mesh vertices. With both of the above optimizations in place, the total cost of computing the MV coordinates and of evaluating the membrane (lines 4 and 13 in Alg. 1) becomes roughly linear in the number of boundary pixels O(m), which in practice grows as O( n), where n is the number of cloned pixels. Of course, because we linearly interpolate the membrane values to all n pixels, the asymptotic behavior is still O(n), similarly to Agarwala [Aga07].

Chapter 4 Implementation and Performance We have implemented MVC cloning both on the CPU and on the GPU. Both implementations target the interactive seamless cloning scenario, where the user first selects an image region to clone and then moves it across the target image, while the seamlessly cloned result is instantly generated and displayed at each target position. 4.1 CPU implementation Once a selection has been made, a short pre-processing stage takes place, during which the adaptive mesh is created, and a vector of MVC coordinates is computed and stored with each mesh vertex. We also precompute, for each pixel in the selected region, the index of the mesh triangle containing this pixel and the three barycentric coordinates with respect to the containing triangle. As the region is moved to each new target location, we compute the error f g at each boundary point, evaluate the mean-value membrane r(x) at each mesh vertex, linearly interpolate to each pixel, using the precomputed barycentric coordinates, and finally compute the sum g + r. For a region with 133K interior pixels and 1,562 boundary pixels, the preprocessing stage takes 0.3 seconds (on a single core of an AMD Athlon 2.5GHz). 32

Chapter 4.2 GPU implementation 33 The interactive cloning then proceeds at a rates exceeding 90 updates per second. More timings and statistics are given in Table 4.1. As expected, the number of mesh vertices grows linearly with the length of the boundary, but the number of boundary points sampled by each vertex remains roughly constant, thanks to the adaptive hierarchical subsampling scheme. As cloned regions become larger, the computation of barycentric coordinates eventually dominates preprocessing time, and the cloning time becomes dominated by the linear interpolation step. Thus, for large regions, performing MVC cloning is almost as cheap as performing a linear interpolation at each pixel. The memory footprint is modest, consisting mainly of storing the barycentric coordinates and a mesh triangle index for each pixel. 4.2 GPU implementation MVC cloning is trivially parallelizable, since the membrane evaluation at each mesh vertex is performed completely independently of the other vertices. Our current GPU implementation also uses an adaptive mesh to approximate the membrane, and performs the hierarchical boundary subsampling. The adaptive mesh and the vector of MVC coordinates at each mesh vertex are precomputed on the host CPU as before, but it is no longer necessary to precompute and store the barycentric coordinates of each pixel, further reducing the memory footprint. At each frame, a simple vertex shader (30 lines of GLSL) evaluates the error membrane r(x) at each mesh vertex, the rasterizing hardware linearly interpolates these values to each pixel, and a trivial fragment shader (6 lines of GLSL) computes the final value of g + r. This results in seamless cloning at roughly 134 frames per second on a mobile GPU (NVIDIA GeForce 9600M GT), when cloning a region with 133K interior pixels. The speed advantage of the GPU implementation over the CPU increases with the size of the cloned region (see Table 4.1).

Chapter 4.3 Comparison with previous approaches 34 Table 4.1: Performance statistics for MVC cloning. Times exclude disk I/O and sending the images to the graphics subsystem. Cloning rate is the number of region updates per second. #cloned #bdry #mesh coords prep. cloning rate pixels pixels vertices /vertex time(s) CPU GPU 51,820 1,113 2,063 38.63 0.15 199.0 163 133,408 1,562 2,963 44.21 0.30 92.1 134 465,134 2,683 5,323 45.50 0.63 22.6 82 1,076,572 4,145 8,241 44.59 1.16 9.7 44 4,248,461 8,133 16,369 57.71 3.63 2.7 26 12,328,289 14,005 28,240 58.68 8.99 0.94 4.3 Comparison with previous approaches We are not aware of any existing system that is able to perform seamless cloning on the CPU at the rates reported above. Testimonials by other researchers [PGB03, MP08], as well as our own experiments, indicate that common Poisson solvers on the CPU are able to handle regions with 256 2 pixels at a rate of 3 5 solutions per second. Another possibility, which we have not seen mentioned in the literature, is to precompute a factorization of the Poisson equation matrix during the preprocessing stage, and then quickly compute the solution via back-substitution at each target location. In our experiments, for a region with 125K pixels, computing the back-substitution takes 0.3 seconds. Thus, all of the above are significantly slower than the rates we are able to achieve. McCann and Pollard [MP08] also demonstrate real-time seamless cloning as one of the features of their gradient-domain painting system, reporting rates of 20 multigrid V-cycles per second for a one megapixel image. While the seamless cloning indeed takes place in real time with their system, there is a fair amount

Chapter 4.3 Comparison with previous approaches 35 of noticeable flicker, as the cloned region is dragged about. The flicker may be attributed to two factors: (i) the Poisson equation is solved over the entire image (with Neumann boundary conditions), thus the position of the cloned patch has a global effect on the result; (ii) the result is updated after each V-cycle, which is not always sufficient to achieve complete visual convergence. In fairness, it should be noted that region cloning is but one feature among several supported by the gradient-domain painting system. It is reasonable to assume that a GPUbased multigrid solver would perform better and avoid flicker, if applied to the cloned region only (with Dirichlet boundary conditions). Still, solving the Poisson equation on the GPU is a much more involved task than MVC cloning, and has a significantly larger memory footprint.

Chapter 5 Results and Extensions 5.1 MVC vs. Poisson We have compared MVC cloning to Poisson cloning on a large number of examples, using a variety of images and differently shaped cloning regions. Our conclusion is that although the corresponding membranes are by no means identical, the outcome of the cloning is typically difficult to tell apart visually. Even when (subtle) differences are visible, it is usually difficult to prefer one outcome over another. The differences between the two kinds of membranes tend to be smaller for convex shapes, such as a rectangle or a disk, as demonstrated in Figure 1.1. Cloning more concave regions, such as the one shown in Figure 5.1, typically results in more significant differences between the membranes, but the results are difficult to tell apart. The differences between the membranes become most apparent for extremely concave regions. For example, consider the synthetic example shown in the top row of Figure 5.2. Here, the goal is to fill an omega-shaped hole. While the Laplace membrane succeeds in eliminating the hole with almost no visible trace, MVC interpolation is less successful. The reason is that the MVC membrane in each half of the shape is affected by values along the boundary of the opposite half, despite there being no lines of sight (inside the shape) between the two halves. However, in a more typical scenario with less extreme gradients 36

Chapter 5.2 Instant seamless cloning 37 and some texture, the results become comparable in quality, even though the same concave region is used (Figure 5.2, bottom row). Figure 5.1: Object removal with Poisson cloning (middle) and MVC cloning (right). Top left: original image; bottom left: source patch. The corresponding membranes are visualized using a colormap. Although the visualization reveals some numerical differences between the membranes (RMS difference of about 0.015), it is difficult to see the difference between the resulting images. 5.2 Instant seamless cloning The gains we achieve in performance translate into a significantly different interactive experience for the user. To illustrate this, one should consider a scenario in which the user would like to try out several locations for a patch he s cloning. A user might want to accomplish this by using the Patch tool in Photoshop CS4.

Chapter 5.3 Mean-Value Video Cloning 38 Figure 5.2: Poisson vs. MVC over a highly concave region. Left: input image; Middle: Poisson cloning; Right: MVC cloning. The downside for this is that while the user is dragging the patch around in CS4, no seamless cloning takes place, and thus the user is unable to assess the result of the operation in real time. Also, There is a noticeable delay from the time the patch is dropped in its target position until the final result appears. In contrast, when cloning with our approach, the seamless cloning result is displayed instantly, greatly assisting the user in selecting a suitable target position. As was mentioned earlier, MVC are invariant under similarity transformations. Thus, during an interactive cloning session, the source region may be rotated and scaled without the need to repeat the preprocessing. Again, we found the ability to do this with instant feedback extremely helpful. Two results obtained with the use of such transformations are shown in Figure 5.3. 5.3 Mean-Value Video Cloning Given the speed of MVC cloning, it is only natural to consider applying it to seamless cloning of video. Seamless video cloning has been attempted before by Wang

Chapter 5.3 Mean-Value Video Cloning 39 Figure 5.3: More seamless cloning results, obtained by rotating and scaling the source patch (left: original, right: after cloning). et al. [WRA04], by forming and solving a 3D Poisson equation over the entire 3D space-time volume of the video. Since our goal is to clone interactively, while both the source clip and the target video are continuously playing, we opt instead for a frame-by-frame solution, with temporal smoothing between consecutive interpolating membranes to ensure temporal coherence. In our current implementation, the shape of the source video patch and its position in the source video frames are kept fixed. We store with each mesh vertex (in addition to its MVC coordinates) a set of its membrane values in the last k frames. To form a membrane for the current frame we compute a weighted average of these values, with the weights of older frames decaying with time: t 0.75, where t is the distance in frames between the current frame and the older one. However, for seamless results the membrane must respond quickly to changing discrepan-

Chapter 5.3 Mean-Value Video Cloning 40 cies between the source and the target along the boundary. Thus, the weight of older membranes in the temporal averaging is further reduce at vertices near the boundary (by a factor of 2 d, where d is the normalized distance of a vertex to the boundary). Snapshots from an interactive video cloning session are shown in Figures 5.4 and 5.5; Seamless cloning of video is a much more challenging task than cloning in still images: inserting and removing objects can be a time-consuming and frustrating task. Therefore, the kind of real-time feedback provided by our approach is instrumental to the user s ability to achieve satisfactory results. Figure 5.4: Seamless video cloning: An Orca whale duplicated. A snapshot from the original video is shown (top-left), along with the result of the simple composite created by copying the pixels (top-right). At the bottom, the result of applying MVC based video cloning (A snapshot from an interactive session)

Chapter 5.4 MVC Stitching 41 Figure 5.5: Seamless video cloning: snapshots from an interactive session. A bird is duplicated (top-left), another bird is removed (top-right), a large rock to the left of the bear is removed (bottom). 5.4 MVC Stitching Gradient-domain stitching and seamless cloning are closely related. For example, stitching may be done by setting up a guiding field that uses the gradients of the images being stitched away from the seams, and the average of the gradient at pixels along the seams [Aga07]. Solving the Poisson equation then yields a seamlessly stitched composite. This approach typically uses Neumann boundary conditions, which prescribe the value of the derivative normal to the boundary, and thus result

Chapter 5.4 MVC Stitching 42 in free-floating boundaries. Figure 5.6: The set-up used for MVC based image stitching. A triangular mesh is constructed on the green area, denser near the seam. The values for the membrane constructed using this mesh are constrained to B A on the seam, 0 on the two opposite corners, and unconstrained on all other boundaries of the mesh. Since our MVC cloning machinery is based on interpolation of boundary values across the domain, it is suitable for Dirichlet boundary conditions, rather than Neumann boundary conditions. Nevertheless, it is quite easy to adapt our approach to perform stitching. Suppose that our goal is to stitch together two images A and B along a given seam. This may be accomplished by keeping one image, say B, fixed, and adding to A a smooth offset function, which interpolates the error between the two images along the seam and gradually goes to zero away from the seam. Specifically, we construct a polygonal boundary around image A consisting of the pixels on the seam between the images, as well as the free (unconstrained) corners of A. We set the offset values to the difference B A for each boundary vertex (pixel) along the seam, and to zero at the free corners of A. Note that the pixel values along the free edges of A are not constrained to any particular offset value, and the offsets along these edges vary smoothly between B A at the seam and zero at the free corners (see Figure 5.6 for a visualization of the stitching set-up). This idea

Chapter 5.5 Selective Boundary Suppression 43 Figure 5.7: MVC stitching. Top: composite with seams; Middle: MVC membrane; Bottom: seamlessly stitched panorama. easily extends to any number of images, by computing a similar offset membrane for each image in the composite. Figure 5.7 shows an example result computed using the approach described above. This 7.5 Mpixel image took 3.7 seconds to stitch, which is slightly faster than the times reported by Agarwala [Aga07]. Additional experiments (up to 33 Mpixels) indicated that the cost of stitching with our approach grows linearly with the length of the seams, with stitching rates of above 1 Mpixel per second. The memory footprint is also linear in the length of the seams. Additional timings and statistics are given in Table 5.1. 5.5 Selective Boundary Suppression It is well known that Poisson cloning works best when the error along the boundary of the cloned region is nearly constant, or changes smoothly. When this is not the case, there is a visible smudging of the error from the boundary into the cloned

Chapter 5.5 Selective Boundary Suppression 44 Table 5.1: Performance statistics for stitching. Times exclude disk I/O. #pixels #seam #mesh stitching Mpixels pixels vertices time (s) per sec. 2,055,231 1,595 13,794 2.16 0.95 4,627,196 2,392 21,192 4.19 1.10 8,224,403 3,188 28,633 6.69 1.23 18,502,298 4,781 42,481 13.80 1.34 32,897,612 6,374 49,261 16.95 1.94 area (Figure 5.8). Mixing source and target gradients [PGB03] and optimizing the boundary [JSTS06] offers a solution to this problem in some, but not all, cases. For example, in cases such as the one shown in Figure 5.8, no adjustment of the boundary is able to avoid the problem, since any boundary must cut across the trunk of the tree or the ground on which it stands in the source image. An alternative solution, is to construct a smooth membrane which does not attempt to interpolate large errors on the boundary. A similar workaround has been used in the context of gradient domain fusion [ADA + 04]. Sections of the boundary where the error is too large to be interpolated may be detected automatically, or indicated by the user. In our current implementation, we let the user paint over a portion of the boundary that causes an undesirable artifact in the cloned result. This signals the cloning routine that the marked boundary vertices should not participate in the membrane evaluation. The mean-value weights λ i corresponding to these vertices are then set to zero (and the remaining weights are, of course, re-normalized accordingly). Note that this does not involve recomputing the mesh, or the coordinates at each mesh vertex. Figure 5.8 shows an example of a result obtained in this manner, demonstrating that selective boundary suppression provides the user with more control over the result of the cloning

Chapter 5.5 Selective Boundary Suppression 45 operation and widens the range of scenarios where seamless cloning is possible. Figure 5.8: Selective boundary suppression. Left: source patch with boundary cutting across an object. Right: regular seamless cloning results in smudging (left tree), which is removed via selective boundary suppression (right tree).