Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Usce C + + and please run your program For simplicity, we will use a basic edge detection kernel. The image will be a 2
Usce C and please run your program
For simplicity, we will use a basic "edge detection" kernel. The image will be a D array with grayscale values between black and white The following x kernel is provided in the code.cpp file:
std::vector kernel
;
We want to implement the "Convolution Operation".
Tasks:
In main declare and initialize a D std::vector array, named inputImage, to represent a sample grayscale image. For testing purposes, use the following x image:
std::vector inputImage
;
In main declare a D array, outputImage, to store the output image after filtering.
In the code.cpp file, write a function, printImage that prints the input image to the sout stream. Use Tab t characters to line up the columns. Since this is a conceptual exercise, you will be printing numbers, but the normalized filtered image should show the effects of edge detection.
In the code.cpp file, write a function, applyKernel that takes the input image and applies the x kernel to produce the output image. Use nested loops to traverse the image and apply the kernel. Apply the kernel to each pixel in the image except the boundary pixels. Note that, for boundary pixels, part of the kernel does not overlap with the input image, which would result in outofbounds error. The outer border boundary pixels of the output image should be The boundary pixels are labeled with red color in the D array below.
The function applyKernel implements the
the convolution operation. For each pixel except the borders multiply its value and the values of its neighbors by the corresponding value in the kernel, then sum these values. The result is the new value for that pixel in the output image.
You will need to use four nested loops: two for traversing the image and two more for applying the kernel to the current pixel and its neighbors. Make sure to handle edge cases, literally! Pixels on the border of the image won't have neighbors, so just skip them or handle them in a way that avoids outofbounds array access.
In the code.cpp file, write a function, minMaxNormalization to normalize the image so that the pixel values are between and Use the formula:
newValoldminmaxminnewMaxnewMinnewMin
where OldVal is the original pixel value, min and max are the minimum and maximum values in the output image, newMin is and newMax is for our case.
In main the provided code prints the original, filtered, and normalized images as D arrays to the console. An example is below:
Original Image:
Filtered Image:
Normalized and Filtered Output Image:
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started