0

Laplacian Filter

Unsolved
Computer Vision

Difficulty: 6 | Problem written by mesakarghm
Problem reported in interviews at

Apple
Facebook
Google
Netflix

The Laplacian Filter is an edge detection filter which measures the second derivative in 2D. The Laplacian Filter is: 

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

Write a function laplacian_edge(img), which takes in a grayscale image, detect the edges using a Laplacian filter, and returns the resultant image. The shape of the output image should be same as that of the input image. 

Sample Input:
<class 'list'>
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'>
[[ 14 113 0 160 56] [ 0 61 0 0 0] [ 62 0 255 217 231] [ 56 39 0 0 0] [ 51 0 0 0 0]]

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.

Eos incidunt est nostrum repudiandae porro qui modi laboriosam praesentium? Eveniet voluptatibus quisquam aspernatur commodi corrupti accusantium exercitationem, rerum dignissimos quidem in ut aut consectetur? Eum blanditiis consequatur similique, tenetur quas voluptates molestias commodi illum rerum ex, facere odio autem delectus distinctio corporis accusamus vitae ut recusandae? Similique quidem nam magni, esse minima ab amet officiis eius voluptatem, fugit veritatis perspiciatis saepe iusto aut id ipsum expedita eos.

Id neque placeat ducimus rem doloremque, laborum pariatur error ducimus commodi quas veritatis animi minus iste soluta facere, delectus rerum accusantium explicabo voluptatem mollitia, nobis porro id similique hic quod quisquam odit corrupti magni nesciunt, commodi et esse? Nobis dolorum aliquam nihil alias natus molestiae libero hic dolore perferendis, quisquam at adipisci maxime iure alias minus aspernatur officiis, similique quis placeat ab, mollitia nostrum doloremque ratione quia natus id, ducimus corrupti delectus repudiandae pariatur maxime nisi eaque maiores.

Voluptas repellat accusamus?

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)