1. Copy the image file: - Use Gimp or a browser to view fig1.pgm - This is a "pgm" format image file - Here's the data file for fig1.pgm, this is a P2 format file with 97 columns, 128 rows, and max pixel value 255 (white) 2. Perform the following edge detection routines: A. Horizontal differencing: image2[row][col] = abs(image[row][col+1] - Image[row,col]) Note: if (col == cols-1) image2[row][col] = 0; Set the pixels in the last column equal to 0 Your result should look like:B. Vertical differencing: image2[row][col] = abs(image1[row+1][col] - image1[row][col]) Note: if (row == rows-1) image2[row][col] = 0; Set the pixels in the last row equal to 0 Your result should look like:
C. One version of Robert's cross: image2[row][col] = abs(image1[row][col-1] - image1[row][col+1]) + abs(image1[i-1][j] - image1[i+1][j]); Note: if (row == 0 || row == rows-1 || col == 0 || col == cols-1) image2[row][col] = 0; Set the first and last rows and cols to 0 Your result should look like:
Robert's Cross version using sqrt and sqr: image2[row][col]= floor(sqrt(sqr(image1[row][col-1] - image1[row][col+1]) + sqr(image1[row-1][col] - image1[row+1][col]))); Note: if (row == 0 || row == rows-1 || col == 0 || col == cols-1) image2[row][col] = 0; Set the first and last rows and cols to 0
D. Sobel's operator: For this pattern around pixel e: a b c d e f g h i dx = c + 2f + i - a - 2d - g dy = a + 2b + c - g - 2h - i image2[row][col] = (int) sqrt (sqr(dx) + sqr(dy)) Use (int) or floor(x) to truncate the sqrt. If the value is > 255, reset it to 255 so that 255 is the max value Set the first and last rows and cols to 0 Your result should look like:
3. Save each of the previous edge detected images under different file names. Fig1HDiff.pgm - Horizontal Differencing Fig1VDiff.pgm - Vertical Differencing Fig1Roberts.pgm - application of the Robert's cross pattern Fig1Sobel.pgm - application of the Sobel operator pattern Compare the strength of each edge detection algorithm. Is a thicker line like Sobel's result necessarily better than a thinner, sharper line? 4. For Supercompting Applications: Try one or more of these edge detection methods using parallel processes.