# Images are Numpy arrays

A Numpy array is a grid of values, all of the same type. These values contain information about each pixel of the image. It is the primary information stored in the pixels and determines the intensity of light from each point of the image. Because images are Numpy arrays, arithmetic operations can be performed on them like any other array.

• np.set_printoptions(threshold=sys.maxsize): This function determines the way arrays and other Numpy objects are displayed. The objective of the code is to print all the values of the Numpy array. The default setting truncates the printed array.
• np.random.randint(0, 50, (15,15)): This function returns random integers from “low” (inclusive) to “high” (exclusive). The objective of the code is to return random integers from 0(inclusive) to 50(exclusive), with 15 rows and 15 columns.

# Filters are operations performed on images.

Just as we sliced a portion of the image array to produce certain color effects, filters are produced in like manner. Filters can be used to blur images, sharpen images, detect the edges in images, and several others. Basically, filters enhance features in images and can also reduce noise in them.

# Kernels

Kernels are matrices used to produce effects (blurring, sharpening, outlining) in images. They are mostly 2-dimensional arrays and are often used interchangeably with filters. There are 1-dimensional kernels, 3-dimensional kernels, etc. In 3D however, you are likely to hear more of filters than kernels.

# Convolution

Convolution is a mathematical operation that multiplies two arrays of the same dimensionality to produce a new array of the same dimensionality. This is achieved by running or sliding one of the arrays (kernel) across the other array (image array). For every pixel of the image, we slide or map the kernel over it and then multiply each pixel value of the image with the corresponding value of the kernel. Afterward, we take the sum of the product values which are used to replace pixel values of the image. Let’s illustrate;

• ndi.convolve(img_matrix, kernel_matrix, mode=”constant”, cval=0): This function performs a multi-dimensional convolution. The objective of the code is to convolve the img_matrix with the kernel_matrix. The mode=” constant” pads/extends the img_matrix by filling all the values beyond the edge with the same constant value(0), defined by the “cval” parameter.

## Mean Kernel

• filters.gaussian(image): This function performs multi-dimensional Gaussian filtering. The objective of the code is to apply the Gaussian filter to the image.