Question: Hi, my code is keep on getting 31.000 as the answer when I run it when the answer should be -132. I asked for help
Hi, my code is keep on getting 31.000 as the answer when I run it when the answer should be -132. I asked for help here but my issue didn't get solved too well so I am posting again :(. the int main is the tester, and convolve and sobel is the part that I worked on. Please help out.
/** * Exercise - Week 8 * * Please read the comments below, they describe your task in detail. * * Starter code: Mustafa Quraish & Charles Xu */
#include "imgUtils.c" #include
// Image dimensions #define SIZEX 512 #define SIZEY 512
// Kernel size #define K_SIZE 3
// Declaration of the X and Y kernel matrices. double GX[K_SIZE][K_SIZE] = { {1, 0, -1}, {2, 0, -2}, {1, 0, -1}, };
double GY[K_SIZE][K_SIZE] = { {1, 2, 1}, {0, 0, 0}, {-1, -2, -1}, };
/*****************************************************************************/
double convolve(unsigned char inp[SIZEY][SIZEX], int px, int py, double kernel[K_SIZE][K_SIZE]) { double sum = 0; for (int i = 0; i = 0 && x = 0 && y
void sobel(unsigned char inp[SIZEY][SIZEX], unsigned char out[SIZEY][SIZEX]) { /** * Given an input image, perform the Sobel edge detection algorithm and store * the output in `out`. Remember that this boils down to: * * for each pixel in input: * g_x = convolve GX at pixel * g_y = convolve GY at pixel * set corresponding output pixel to sqrt(g_x^2 + g_y^2) * * NOTE: The expression sqrt(g_x^2 + g_y^2) may result in values greater than * 255. In such case, just set it to 255. * NOTE: Note that the 2D array is flipped (Y, X) instead of (X, Y). */ for (int i = 0; i
/*****************************************************************************/
#ifndef __testing__ // You know the drill, don't remove this
int main() { /* Feel free to change the contents INSIDE the main function to help test */
// Initialize the 2D-arrays that will store the values of the pixels unsigned char data[SIZEY][SIZEX]; unsigned char edge[SIZEY][SIZEX];
// We will store the values of the input image readPGM("input.pgm", &data[0][0]);
// Test convolve() double res = convolve(data, 0, 0, GY); if (res != -132.0) { printf("Error: convolve() test 1 output incorrect. "); printf("Expected: %f, Yours: %f ", -132.0, res); exit(1); }
// Pixel somewhere in the middle res = convolve(data, 324, 218, GX); if (res != -21.0) { printf("Error: convolve() test 2 output incorrect. "); printf("Expected: %f, Yours: %f ", -21.0, res); exit(1); }
printf("- convolve() output was correct. ");
// Call the sobel function sobel(data, edge);
// Write the values to the output image writePGM("output.pgm", &edge[0][0]);
// Compare to the expected image readPGM("expected.pgm", &data[0][0]);
for (int i = 0; i
printf("- sobel() output was correct. "); return 0; }
#endif

C:\\Users\\Yoojin\\OneDrive\\Desktop\\C coding\\ExerciseWeek8>a. exe (0, 0) = 31.000000 Error: convolve() test 1 output incorrect. Expected: -132. 000900, Yours: 31. 009000 C:\\Users\\Yoojin\\OneDrive\\Desktop\\C coding\\ExerciseWeek8>
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
