Given is a greyscale 8 bit input image in the form of a pixel array (a list of pixel rows, with each row represented aga
Posted: Thu May 26, 2022 9:05 am
Given is a greyscale 8 bit input image in the form of a pixel array (a list of pixel rows, with each row represented again as a list). Every pixel contains an integer value between 0 and 255. Write a Python3 function 'computeHorizontalEdges SobelAbsolute (pixel_array, image_width, image_height)' which computes and returns an image of the horizontal edges. The edge image has to use the 3x3 Sobel kernel for the gradient in y direction. Since the result can be positive or negative, for every pixel of the result the absolute value of the result has to be computed additionally (i.e. we treat positive and negative gradients the same). The resulting image has to contain float values. Border handling: Note that when applying the 3x3 Sobel kernel, the filtering procedure has to access pixels that are outside the input image. For this function simply ignore the 1 pixel boundary of the input image. We referred to this case as Borderlgnore in the lecture. We set the output pixels at the outer boundary to zero. You may assume that the Python3 function 'createInitialized Greyscale PixelArray(image_width, image_height)' is available, which creates an empty greyscale array (values 0) as a list of lists of integers. (Please use the skeleton Python code to see the effect of this edge detection code on actual images!) For example: Test Result image_width = 6 image_height = 5 pixel_array = [[30, 70, 20, 30, 20, 30], 0.000 0.000 0.000 0.000 0.000 0.000 0.000 15.000 5.000 5.000 1.250 0.000 0.000 2.500 5.000 2.500 0.000 0.000 0.000 13.750 13.750 2.500 7.500 0.000 0.000 0.000 0.000 0.000 0.000 0.000 [0, 40, 60, 10, 40, 40], [30, 10, 20, 50, 20, 20], [10, 60, 30, 10, 50, 20], [40, 40, 60, 50, 0, 0] ] horizontal_edges = computeHorizontal Edges SobelAbsolute (pixel_array, image_width, image_height) printPixelArray (horizontal_edges) image_width = 6 image_height = 5 pixel_array = [ [0, 0, 0, 0, 0, 0], 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.250 0.125 0.125 0.250 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.250 0.125 0.125 0.250 0.000 0.000 0.000 0.000 0.000 0.000 0.000 [0, 1, 1, 1, 1, 0], [0, 1, 0, 0, 1, 0], [0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0] ] horizontal_edges = computeHorizontalEdgesSobelAbsolute (pixel_array, image_width, image_height) printPixelArray (horizontal_edges)