Professional Documents
Culture Documents
Coding Assignment C++
Coding Assignment C++
small or 0 where as if there is a significant change in neighbourhood pixel values, then this function
would have non-zero values. We detect presence of an edge by noticing how this function value changes.
The above is for intuition on how this works. Follow the steps mentioned below to detect edges of an
image and output image edge.pgm.
q
2
2
Compute values grad(i, j) = hdif (i, j) + vdif (i, j) for all i, j in the image where hdif and vdif
refer to horizontal and vertical gradients and they are computed as
hdif(i,j) = (image[i-1][j-1]-image[i-1][j+1]) + 2(image[i][j-1]-image[i][j+1]) + (image[i+1][j-1]-image[i+1][j+1])
vdif(i,j) = (image[i-1][j-1]-image[i+1][j-1]) + 2(image[i-1][j]-image[i+1][j]) + (image[i-1][j+1]-image[i+1][j+1])
We need to apply similar boundary conditions as we did in averaging part.
Let mgrad = maxi,j grad. Value of pixel (i, j) of edge.pgm equals image[i][j] if grad(i, j) cmgrad,
else 0. You should try out different values of c for which the output images would be different. Output
image for c = 0.1.
Write these pixel values to the file edge.pgm. File edge.pgm should adhere to the specification
mentioned above. Make sure you write other required values to the file before you start to write actual
pixel values.
Submission Instructions
Submit a single .cpp file. Since we will follow automatic evaluation you are requested to adhere to the
submission format. Please remember that you are supposed to output average.pgm and edge.pgm files.
You should write different functions to compute averaging and edge detection.