You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: project-2/proj2.html
+32-4Lines changed: 32 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -8,10 +8,10 @@
8
8
</head>
9
9
<body>
10
10
<header>
11
-
<h1>Project 2: Fun with Filters and Frequencies</h1>
11
+
<h1>Project 2: Filters and Frequencies</h1>
12
12
<divalign="center">
13
13
<p>
14
-
by Daniel Cheng | September 29, 2025
14
+
by Daniel Cheng | October 1, 2025
15
15
</p>
16
16
</div>
17
17
</header>
@@ -25,7 +25,7 @@ <h2>Part 1: Filters and Edges</h2>
25
25
26
26
<!-- 1.1 -->
27
27
<articleid="part1-1">
28
-
<h3>Part 1.1: Convolutions from Scratch!</h3>
28
+
<h3>Part 1.1: Convolutions from Scratch</h3>
29
29
<p>
30
30
Using the definition of convolution:
31
31
</p>
@@ -50,7 +50,7 @@ <h3>Part 1.1: Convolutions from Scratch!</h3>
50
50
</div>
51
51
52
52
<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 <imgsrc="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 <imgsrc="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:
54
54
</p>
55
55
56
56
<divalign="center">
@@ -65,6 +65,33 @@ <h3>Part 1.1: Convolutions from Scratch!</h3>
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.
0 commit comments