PIXELBANKv8.2.1
Menu

Edge Count Heuristic

Implement a simple edge detection technique to count the number of edges in a grayscale image. This task involves applying a basic heuristic to identify pixels with significant intensity changes.

The concept of edge detection is crucial in computer vision as it helps in identifying boundaries and structures within an image. A grayscale image can be represented as a 2D array of intensity values, where each pixel's value is a scalar between 0 and 255. The absolute difference between neighboring pixels can be used to determine the presence of an edge.

To detect edges, follow these steps:

  1. Iterate over each pixel in the image, excluding border pixels.
  2. For each pixel, calculate the absolute difference with its 4-neighbors.
  3. If any of these differences exceed a given threshold, mark the pixel as an edge.
Edge={1,if I(x,y)I(x,y)>threshold0,otherwise\text{Edge} = \begin{cases} 1, & \text{if } |I(x, y) - I(x', y')| > \text{threshold} \\ 0, & \text{otherwise} \end{cases}

This technique is widely used in image processing applications.

Example:

Input:
count_edges([[0,0,100],[0,0,100],[0,0,100]], 50)
Output:
3
Reasoning:

Middle column pixels have neighbors differing by 100 > 50

Constraints:

  • Image is a 2D grayscale array
  • Threshold is a positive integer
  • Don't count border pixels as edges
  • Return total count of edge pixels
Editor

Test Results

0/0
Run code to see test results.