Skip to content

Commit a210559

Browse files
authored
Update proj2.html
1 parent ffd91d7 commit a210559

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

project-2/proj2.html

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
</head>
99
<body>
1010
<header>
11-
<h1>Project 2: Fun with Filters and Frequencies</h1>
11+
<h1>Project 2: Filters and Frequencies</h1>
1212
<div align="center">
1313
<p>
14-
by Daniel Cheng | September 29, 2025
14+
by Daniel Cheng | October 1, 2025
1515
</p>
1616
</div>
1717
</header>
@@ -25,7 +25,7 @@ <h2>Part 1: Filters and Edges</h2>
2525

2626
<!-- 1.1 -->
2727
<article id="part1-1">
28-
<h3>Part 1.1: Convolutions from Scratch!</h3>
28+
<h3>Part 1.1: Convolutions from Scratch</h3>
2929
<p>
3030
Using the definition of convolution:
3131
</p>
@@ -50,7 +50,7 @@ <h3>Part 1.1: Convolutions from Scratch!</h3>
5050
</div>
5151

5252
<p>
53-
To demonstrate an application of convolution, we can convolve an image with the <strong>box filter</strong>, a kernel with entries that sum to 1 that contains only 1 unique value. We can also convolve with the difference operators <img src="images/diff_op.png" alt="diff_op.png" width="25%"> for edge detection. Each kernel computes the difference in the <i>x</i>- or <i>y</i>-direction, so edges where the brightness of the pixel changes significantly will show up as white and black pixels on the output. Using <code>box_9x9</code> = <i>J<sub>9</sub> / 9<sup>2</sup></i> as the box filter, we get the following results:
53+
To demonstrate an application of convolution, we can convolve an image with the <strong>box filter</strong>, a kernel with entries that sum to 1 that contains only 1 unique value. We can also convolve with the difference operators <img src="images/diff_op.png" alt="diff_op.png" width="50%"> for edge detection. Each kernel computes the difference in the <i>x</i>- or <i>y</i>-direction, so edges where the brightness of the pixel changes significantly will show up as white and black pixels on the output. Using <code>box_9x9</code> = <i>J<sub>9</sub> / 9<sup>2</sup></i> as the box filter, we get the following results:
5454
</p>
5555

5656
<div align="center">
@@ -65,6 +65,33 @@ <h3>Part 1.1: Convolutions from Scratch!</h3>
6565
<img src="images/dxdy.png" alt="dxdy.png" width="50%">
6666
</div>
6767

68+
<p>
69+
To handle boundries, we can set all of the padding pixels to 0, similar to the following:
70+
</p>
71+
72+
<pre><code>
73+
if mode == 'valid':
74+
return convolve(img, ker, naive)
75+
elif mode == 'same':
76+
pad_ht = (ker.shape[0] - 1) // 2
77+
pad_wl = (ker.shape[1] - 1) // 2
78+
img_padded = np.zeros((img.shape[0] + ker.shape[0] - 1, img.shape[1] + ker.shape[1] - 1))
79+
img_padded[pad_ht:pad_ht + img.shape[0], pad_wl:pad_wl + img.shape[1]] = img
80+
return convolve(img_padded, ker, naive)
81+
elif mode == 'full':
82+
pad_h = ker.shape[0] - 1
83+
pad_w = ker.shape[1] - 1
84+
img_fpadded = np.zeros((img.shape[0] + 2 * pad_h, img.shape[1] + 2 * pad_w))
85+
img_fpadded[pad_h:pad_h + img.shape[0], pad_w:pad_w + img.shape[1]] = img
86+
return convolve(img_fpadded, ker, naive)
87+
else:
88+
raise ValueError('Unsupported mode: ' + str(mode) + '. Must be one of \'valid\', \'same\', or \'full\'.')
89+
</code></pre>
90+
91+
<p>
92+
A zero-valued pixel, however, is equivalent to a black colored pixel on the image. This means the function would introduce a dark edge if one wants to have the image be the same size after convolving, which is visible above. To prevent this scenario, the safest way is to let the first row/column be the first padding row/column on the top left side, and perform the same with the last row/column on the bottom right side. This process can also be carried out for the 2nd/2nd-to-last row/column, and so on. Compared to other approaches like <code>'wrap'</code>, this method ensures that there won't be significant artifacts by ensuring the padded pixels come from the closest pixels in the image. To implement this method, we can set the <code>boundary</code> variable to <code>'symm'</code> in <code>convolve2d</code>. In comparison, the zero-padding mode is the same as the default mode in <code>convolve2d</code>, which shows how <code>convolve2d</code> has more functionalities than the naive implementation.
93+
</p>
94+
6895
</article>
6996
<hr>
7097

@@ -222,6 +249,7 @@ <h3>Part 2.2: Hybrid Images</h3>
222249
<article id="part2-3">
223250
<h3>Part 2.3 &amp; 2.4: Multiresolution Blending</h3>
224251
<p>
252+
To blend 2 images together, we can first start by creating a Gaussian/Laplacian stack, where at
225253
</p>
226254
</article>
227255
</section>

0 commit comments

Comments
 (0)