Convolution is an operation used in image processing and machine learning that is performed by applying a filter or a kernel to the source data, in the case of an image, an array of pixels. Convolution is used in blurring, sharpening, edge detection and many other image processing tasks. Let's look at a practical example.

コンボリューション(畳み込み)は、画像処理やマシンラーニングで用いられる演算で、フィルタ(カーネル)を元になるデータ、画像の場合はピクセルの配列に適用することで実行されます。コンボリューションはぼかし、シャープ、エッジ検出など、画像処理で幅広く使用されます。実際の例を見てみましょう。

Blur

ぼかし

First, let's take a look at a demo. On the left is an image of a black circle, and on the right you can see how a filter is applied to blur the same image.

まずはデモを見てみましょう。左には黒い丸の画像があり、右では同じ画像にフィルターをかけてぼかしていく様子が見れます。

https://codepen.io/kynd/pen/wvYwjwe

On a computer, an image is just a sequence of numbers. If black is 0 and white is 1, the table below is an image of a white square on a black background.

コンピュータ上では画像はただの数列です。黒を0、白を1とすると下の表は黒い背景に白い正方形が描かれた画像になります。

0 0 0 0 0
0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0

A filters are also defined as an array. This is the array used in the demo.

フィルターも配列として定義します。 これがデモで使った配列です。

0.1 0.1 0.1
0.1 0.2 0.1
0.1 0.1 0.1

We select one pixel from the image, let’s say the second from the left and the second from the top. We take the surrounding pixels as well and multiply them with the filter.

画像からピクセルをひとつ選びます。ここでは左から2番目、上から2番目のピクセルにします。周囲のピクセルも取り出し、フィルターと掛け合わせます。

Screenshot 2023-04-08 at 11.06.59 PM.png

And we get an array like this.

こんな配列が得られます。