代写 Image Filtering

Image Filtering
In this section we will describe the inputs and functions your program must implement at a minimum to get full credit on this programming assignment. For this assignment all BMP images will be exactly 256×256 pixels. In addition, the largest kernel used in this assignment is 11×11. Since C/C++ does not like array declarations where the size is a variable, you can declare all of your kernels with fixed 11×11 dimensions. At runtime, you will get N from the command line, so you will just fill in the upper-left NxN elements for your kernels (to create the Sobel, Gaussian, and unsharp filter values). Then, you will always pass an 11×11 kernel to your functions but those functions will only use the upper- left NxN elements.
1. Our overall program will be called filter and implement the three image processing filters described above, allowing the user to choose any 1 filter per run of the program. Your program will take command line arguments to control which filter is applied to the input image:
• ./filter dummy
• ./filter sobel
• ./filter blur
• ./filter unsharp will be a string like ‘tommy.bmp’
The 2nd argument will be the filter to apply: dummy, sobel, blur or unsharp is the size of the kernel to create for the Gaussian (min=3, max=11)
 is the variance parameter in the Gaussian (must be non-zero) is the mix-in parameter in the unsharp equation (0 < alpha <= 1.0) 
 • We have completed the main function for you. But you should read and understand what it is doing. In particular, main performs the following tasks: • Checks that a minimum amount of arguments are provided. 
 • Attempts to open the input file and read in the input image data to an array: 
unsigned char input[SIZE][SIZE][3]. If the file is unable to be opened, 
the program will quit. 
 • Checks the 2nd parameter is one of dummy, sobel, blur or unsharp. Based 
on this argument we determine what other command lines arguments you 
should expect and check. • We then convert the appropriate command line arguments to the appropriate data type and invoke functions to carry out the specific task. 
 • As you create the output image, place it in an array unsigned char output[SIZE][SIZE][3]. main will write that array to the output file name. 
 • The dummy function is complete. You do not need to modify it. It shows you an example of how to declare a kernel and prepare it for use with convolve. It then calls convolve to generate the output image. 
 • Complete the function convolve(unsigned char out[][SIZE][3], unsigned char in[][SIZE][3] , int N, double kernel[][11]) that takes an output array, an input array and a generic kernel of which only NxN is used out of the 11x11 total size. This function should perform the convolution operation of the kernel with the image. Inside this function is where the image will need to be padded. Clamping can also be performed. 
 • Complete the function: void sobel(unsigned char out[][SIZE], unsigned char in[][SIZE]). It is started for you. • You should convolve each of the horizontal direction kernels one at a time producing two resulting arrays. 
 • Then add the two results together (pixel-by-pixel) to produce the final output image. 
 • Implement from scratch a function gaussian(k[][11], int N, double sigma) that 
fills the upper NxN elements of the 11x11 kernel with the normalized Gaussian. This function only generates the kernel to be used. It does NOT actually perform the filtering/convolution. This function should print the kernel to the screen in a nice 2D table format on the screen. This will help you ensure you’ve computed things correctly. 
 • Implement from scratch the gaussian_filter function. To do so use the gaussian() [to produce the kernel] and convolve() functions from the given command line parameters. gaussian_filter should be a function with the prototype gaussian_filter(output [][SIZE][3], input[][SIZE][3], int N, double sigma). N and sigma have the same meaning as for the gaussian() function. 
 • Implement from scratch the unsharp mask filter using the gaussian() and convolve() functions, along with the command line parameters. This should be a function with the prototype unsharp(output[][SIZE][3], input[][SIZE][3], int N, double sigma). 
 • Compile your program fixing any compile time errors. 
 • Run your program on various inputs. Here are some sample command lines: 
 a. ./filter tommy.bmp blur 5 2.0 tommy_blur.bmp
 b. ./filter bw_tile_wikimedia.bmp sobel bw_tile_sobel.bmp
 c. ./filter usc_ucla_wikimedia.bmp unsharp 5 2.0 0.7