1

Edge Detection - Roberts Cross

Unsolved
Computer Vision

Difficulty: 7 | Problem written by mesakarghm

Educational Resource: https://homepages.inf.ed.ac.uk/rbf/HIPR2/roberts.htm


Problem reported in interviews at

Amazon
Apple
Facebook
Google
Netflix

The Roberts Cross operator is used in image processing and computer vision for edge detection. It consists of the use of two filters to get the gradient approximation, and these approximations are then combined to give the gradient magnitude. 

The filter for convolution in X-direction is: 

\(\begin{bmatrix} 0 & 0 & 1\\ 0 & -1 & 0 \\ 0 & 0 & 0 \end{bmatrix} \)

The filter for convolution in Y-direction is: 

\(\begin{bmatrix} 1 & 0 & 0\\ 0 & -1 & 0 \\ 0 & 0 & 0 \end{bmatrix} \)

The intermediate gradient approximations can later be combined to get the gradient magnitude as: 
\(G = \sqrt{G_x ^{2} + G_y^{2} } \)

Write a function edge_detection(image) which takes in an input grayscale image (2D numpy array), performs edge detection using the Roberts Cross method, and returns the resultant image. 

Sample Input:
<class 'numpy.ndarray'>
image: [[ 1 7 119 13 12] [ 11 21 61 81 91] [ 5 66 6 5 5] [ 5 66 166 145 155] [ 5 66 136 145 155]]

Expected Output:
<class 'numpy.ndarray'>
[[ 23 62 121 106 81] [ 64 25 65 123 145] [ 70 135 175 255 162] [ 70 107 118 15 179] [ 8 108 222 237 254]]

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Dolore laudantium excepturi vero, sequi vero perspiciatis aliquam dignissimos inventore perferendis quisquam laudantium dolorem fugiat nihil, modi doloribus dolores error, nemo harum veritatis veniam vero nam voluptate.

Numquam ratione totam, harum explicabo tenetur architecto, dolorem vero eaque nemo sequi beatae molestiae. Accusamus veritatis eveniet esse fugit eos neque quisquam qui.

Asperiores dignissimos omnis quae odio doloremque at veniam, molestias sapiente id atque odio, nobis explicabo iure id nostrum neque ullam expedita eveniet omnis? Aut fugiat ipsum deserunt eius consectetur saepe at consequuntur sequi, dolorum maxime provident voluptatum nobis tempore excepturi assumenda distinctio itaque tenetur aliquam, illum necessitatibus voluptatum expedita, eos quibusdam provident perferendis modi incidunt consequuntur, eos esse repudiandae suscipit officia ex facilis corporis similique atque ratione. Rem eaque debitis consectetur reiciendis non et beatae sint aperiam sequi, expedita provident excepturi sit sapiente, est ipsam atque quasi illo dignissimos praesentium, ea dignissimos expedita excepturi at, accusamus non fugiat.

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)