Starting from:

$30

CSCI3290-Assignment 1 Image Sharpening Solved

This aims at practicing the foundation of digital image processing and computer vision, image filtering. Filtering is a technique for modifying or enhancing an image. We can filter an image to emphasize certain features or remove other features. Image processing operations implemented with filtering include smoothing, sharpening, and denoising. We will image sharpening in this assignment.

I.     Algorithms  
Filtering is a neighborhood operation, in which the value of the output image is determined by applying some algorithm to the values of the pixels inside the neighborhood of the corresponding input pixel. A pixel's neighborhood is some set of pixels, defined by their locations relative to that pixel. Linear filtering is filtering in which the value of an output pixel is a linear combination of the values of the pixels in the input pixel's neighborhood. We will use linear filtering technique to do the image sharpening. 

 

• Convolution  
 

Figure 1. Convolution process for a 3 × 3 convolution kernel.

 

Linear filtering of an image is accomplished through an operation called convolution. Convolution is a neighborhood operation in which each output pixel is the weighted sum of neighboring input pixels.

The matrix of weights is called the convolution kernel, also known as the filter. As shown in Figure 1, the computation of the output image pixel value h[i, j] at this location is done as: 

h[i, j]  =  A x P1 + B x P2 + C x P3 + D x P4 + E x P5 + F x P6 + G x P7 + H x P8 + I x P9

To get the whole output image, we should slide the kernel over the whole input image step by step. For example, Figure 2 shows the kernel sliding process of applying a 3x3 kernel (shadow region) on a 4x4 input image (bottom blue region) to get the output image (top green region). 

 

 

Figure 2. Kernel sliding process.

 

• Kernel generation  
Applying different kernels in convolution can achieve different editing effects. In this assignment we will use the Gaussian kernel, specifically, 2D Gaussian kernel. Mathematically, the 2D Gaussian kernel is computed as:

, where x and y are the horizontal and vertical distance to the center of the kernel, respectively; σ is the standard deviation (always positive) that controls the width of the Gaussian kernel. The above equation is used to compute the infinite size gaussian kernels, however, practically we always use finite size kernels, like 3*3 or 5*5. Therefore, we need to normalize the kernel to make the sum of all the kernel elements values to be one. We can do it like this:

1

𝐾(𝑥, 𝑦; σ) =  ∗ 𝐺2𝐷(𝑥, 𝑦; σ),

(𝑖, 𝑗; 𝜎)

where 𝑚 ∗ 𝑛 is the kernel size. In this assignment we only account for the square shape kernel, so 𝑚 == 𝑛 all the time, and we only account for the kernel size to be odd number, like 1, 3, 5, 7, …

 

• Overall pipeline
Having the above definition, we can do the image sharpening by first convolve the input image using a Gaussian kernel to get the smoothed image, then use the input image to minus the smoothed image to get the detail map, and finally add the detail map to the original input image to get the sharpened image. The pseudo-code is as following:

1.  Read the input image by imread() function (provided).

2.  Generate the Gaussian kernel by gaussian_kernel() function (need to be implemented) with the given kernel size and standard deviation σ.

3.  Convolve the input image by conv() function (need to be implemented) with the generated kernel to get the smoothed image.

4.  Generate the sharpened image by sharpen() function (need to be implemented) with the generated smoothed image and original input image like this:

i. crop input_image to get input_image_crop that has the same size with smoothed_image. ii. detail_map = input_image_crop – smoothed_image

iii. sharpened_image = input_image_crop + detail_map iv. return sharpened_image

5.  Write the sharpened image by imwrite() function (provided).
 

This all the procedure of our assignment. There are parameters, standard deviation σ and kernel shape 𝑚 ∗ 𝑚, to control the degree of sharpen effect in the image sharpening process

More products