-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassignment2.html
237 lines (198 loc) · 10 KB
/
assignment2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="description" content="Comp590-computational-photography : ">
<link rel="stylesheet" type="text/css" media="screen" href="stylesheets/stylesheet.css">
<title>Comp590-computational-photography</title>
</head>
<body>
<!-- HEADER -->
<div id="header_wrap" class="outer">
<header class="inner">
<a id="forkme_banner" href="https://github.com/dstantwo/COMP590-Computational-Photography">View on GitHub</a>
<h1 id="project_title"><a href="http://dstantwo.github.io/COMP590-Computational-Photography/">COMP 590 Computational Photography</a></h1>
<h2 id="project_tagline">Assignment 2 Writeup</h2>
</header>
</div>
<!-- MAIN CONTENT -->
<div id="main_content_wrap" class="outer">
<section id="main_content" class="inner">
<h2><a id="welcome-to-github-pages" class="anchor" href="#welcome-to-github-pages" aria-hidden="true"><span class="octicon octicon-link"></span></a>Toy Problem</h2>
<h3><a id="welcome-to-github-pages" class="anchor" href="#welcome-to-github-pages" aria-hidden="true"><span class="octicon octicon-link"></span></a>The Method</h3>
<p>The goal in this assignment was to implement gradient domain processing with a toy example - reconstructing a grayscale image.</p>
<p>
The high level methodology for achieving this involved 3 main steps and the equations:
<uL>
<li>
<code>Av - b = 0</code> or <code>Av = b</code>
</li>
<li>
<code>minimize (v(x+1,y)-v(x,y) - (s(x+1,y)-s(x,y)))^2 </code>
</li>
<li>
<code>minimize (v(x,y+1)-v(x,y) - (s(x,y+1)-s(x,y)))^2</code>
</li>
</uL>
<ol>
<li>
Construct a constraint matrix <code>A</code> where each row represents either <code>v(x+1,y)-v(x,y)</code> or <code>v(x,y+1)-v(x,y)</code>
</li>
<li>
Construct a vector <code>b</code> where each row is either <code>s(x+1,y)-s(x,y)</code> or <code>s(x,y+1)-s(x,y)</code>, and corresponds to the same row in <code>A</code>.
</li>
<li>
Solve for the vector <code>v</code>, which will be the pixel values in the final image that most closely conform to the gradient constraints laid out in <code>A</code> and <code>b</code>.
</li>
</ol>
</p>
<h3>
<a id="designer-templates" class="anchor" href="#designer-templates" aria-hidden="true"><span class="octicon octicon-link"></span></a>Implementation</h3>
<script src="http://gist-it.appspot.com/github/dstantwo/COMP590-Computational-Photography/blob/master/assignment2/part1/assignment2_1_toy.m"></script>
<p>
<strong>Method</strong>
<ol>
<li>
After loading the source image, I begin by creatng a mapping each pixel to a variable number where the variable number of pixel at y,x = im2var(y,x).
</li>
<li>
Next, I initialize the matrix <code>A</code> and vector <code>b</code> with appropriate demesions and values of 0.
</li>
<li>
I then iterate through each pixel in the final image and add a vertical and horizontal gradient constraint for that pixel with respect to the source image. These constraints populate <code>A</code> and <code>b</code>.
</li>
<li>
Next I add a final constraint which adds the correct constant value to <code>v</code>.
</li>
<li>
Finally, I solve for <code>v</code> using <code>v = A\b</code> and reshape into the final image.
</li>
</ol>
<strong>Results</strong>
<li>
<br>
<img src="assignment2/part1/source.jpg" width = "45%">
<img src="assignment2/part1/result.jpg" width = "45%">
<br>
<p>
The source image (left) and the resulting image (right)
</p>
</li>
</p>
<h3>
<a id="authors-and-contributors" class="anchor" href="#authors-and-contributors" aria-hidden="true"><span class="octicon octicon-link"></span></a>Conclusion</h3>
<p>
I achieved the desired result of recerating the source image. After understanding the relation between <img src="http://acberg.com/comp_photog/optimization.jpg" height="40"> and the three equations:
<uL>
<li>
<code>Av - b = 0</code> or <code>Av = b</code>
</li>
<li>
<code>minimize (v(x+1,y)-v(x,y) - (s(x+1,y)-s(x,y)))^2 </code>
</li>
<li>
<code>minimize (v(x,y+1)-v(x,y) - (s(x,y+1)-s(x,y)))^2</code>
</li>
</uL>
implementation was relatively simple.
</p>
<h2><a id="welcome-to-github-pages" class="anchor" href="#welcome-to-github-pages" aria-hidden="true"><span class="octicon octicon-link"></span></a>Main Assignment</h2>
<h3><a id="welcome-to-github-pages" class="anchor" href="#welcome-to-github-pages" aria-hidden="true"><span class="octicon octicon-link"></span></a>The Method</h3>
<p>The goal in this assignment was to compost two different images in matlab using simple cloning, alpha blending, and gradient domain blending</p>
<p>
The high level methodology for achieving this involved 3 main steps:
<ol>
<li>
Construct a binary alpha mask and copy the pixels from the source image where the mask is 1 onto the target image.
</li>
<li>
Smooth the mask and do the same thing.
</li>
<li>
Enlarge the binary mask achieve blending through gradient domain blending insted of alpha blending.
</li>
</ol>
</p>
<h3>
<a id="designer-templates" class="anchor" href="#designer-templates" aria-hidden="true"><span class="octicon octicon-link"></span></a>Implementation</h3>
<script src="http://gist-it.appspot.com/github/dstantwo/COMP590-Computational-Photography/blob/master/assignment2/part1/assignment2_1.m"></script>
<p>
<strong>Method</strong>
<ol>
<li>
After creating a binary alpha mask and then a feathered alpha mask in photoshop, implementing both of the alpha mask based cloning solutions was just a matter of iterating through each pixel in each color channel of the final image and referenceing the value of the mask at the same location to determine which pixel (source or target or wighted average) went there.
</li>
<li>
For this implementation of gradient domain blending, I referenced the walk through slides about gradient domain editing from James Hays at Brown. These had a good description of how to implement the Laplacian, which I used insted of the constraints outlined in the toy problem.
</li>
</ol>
<h4>Results</h4>
<li>
<strong>Binary Alpha Mask</strong>
<br>
<img src="assignment2/part1/moon_source.png" width = "45%">
<img src="assignment2/part1/penguin_source.png" width = "45%">
<img src="assignment2/part1/binary_mask.png" width = "45%">
<img src="assignment2/part1/cloned_image_large.jpg" width = "45%">
<br>
<p>
From upper left to lower right: The target image, the source image, the binary alpha mask, and the cloned image.
</p>
</li>
<li>
<strong>Alpha Mask Blending</strong>
<br>
<img src="assignment2/part1/moon_source.png" width = "45%">
<img src="assignment2/part1/penguin_source.png" width = "45%">
<img src="assignment2/part1/mask_feathered.png" width = "45%">
<img src="assignment2/part1/alpha_blend_image_large.jpg" width = "45%">
<br>
<p>
From upper left to lower right: The target image, the source image, the fethered alpha mask, and the cloned image.
</p>
</li>
<li>
<strong>Gradient Domain Blending</strong>
<br>
<img src="assignment2/part1/moon_source.png" width = "45%">
<img src="assignment2/part1/penguin_source.png" width = "45%">
<img src="assignment2/part1/binary_mask.png" width = "45%">
<img src="assignment2/part1/seamless_cloning_large_v1.jpg" width = "45%">
<br>
<p>
From upper left to lower right: The target image, the source image, the binary alpha mask, and the cloned image.
</p>
</li>
<li>
<strong>Gradient Domain Blending with Tighter Mask</strong>
<br>
<img src="assignment2/part1/moon_source.png" width = "45%">
<img src="assignment2/part1/penguin_source.png" width = "45%">
<img src="assignment2/part1/mask_feathered.png" width = "45%">
<img src="assignment2/part1/seamless_cloning_large.jpg" width = "45%">
<br>
<p>
From upper left to lower right: The target image, the source image, the alpha mask, and the cloned image.
</p>
<p>
NOTE: In order to use the feathered mask as a tighter binary mask in this implementation, I conditioned the population of matrix <code>A</code> and vector <code>b</code> on whether the value at <code>mask_feathered(y,x)</code> was greater than 0.5. By doing this, I was able to treat this feathered mask as a binary alpha mask.
</p>
</li>
</p>
<h3>
<a id="authors-and-contributors" class="anchor" href="#authors-and-contributors" aria-hidden="true"><span class="octicon octicon-link"></span></a>Conclusion</h3>
<p>
All methods of composting were successful with varying degrees of smoothness. I believe the best result to be from using gradient domain blending with a tight mask. In both examples of gradient domain blending, the penguin is perhaps slightly too dark. However, this eems to be a consequence of the lighting in the moon picture rather than an implementation failure. The alpha mask blending example also achieved fairly good results, but could have been improved with a more refined mask.
</p>
</section>
</div>
<!-- FOOTER -->
<div id="footer_wrap" class="outer">
<footer class="inner">
<p class="copyright">Comp590-computational-photography maintained by <a href="https://github.com/dstantwo">dstantwo</a></p>
<p>Published with <a href="https://pages.github.com">GitHub Pages</a></p>
</footer>
</div>
</body>
</html>