PIXELBANKv8.2.1
Menu

Simple Binary Thresholding

Implement a binary thresholding technique to segment a 2D grayscale image based on a given threshold TT. This process involves categorizing each pixel into one of two classes, creating a binary image. The concept of image segmentation is crucial in computer vision, as it enables the separation of objects or regions of interest from the rest of the image, which is vital for various applications. Here's how to approach this:

  1. Iterate over each pixel in the image,
  2. Compare its intensity value to the threshold TT,
  3. Assign a value of 1 if the pixel's intensity is greater than TT, and 0 otherwise.
f(x,y)={1if I(x,y)>T0if I(x,y)Tf(x, y) = \begin{cases} 1 & \text{if } I(x, y) > T \\ 0 & \text{if } I(x, y) \leq T \end{cases}

This technique is widely used in medical imaging applications.

Example:

Input:
image = [[100, 150, 200], [50, 120, 180]]
T = 120
Output:
[[0, 1, 1], [0, 0, 1]]
Reasoning:
  • The given image is a 2D grayscale image with pixel values: [[100, 150, 200], [50, 120, 180]].
  • We apply the threshold T=120T = 120 to each pixel value, comparing it to TT to determine the binary output:
    • Pixel values greater than TT (>120> 120) map to 11
    • Pixel values less than or equal to TT (120\leq 120) map to 00
  • The thresholding process yields the following binary image:
    • First row: 100120100 \leq 120 maps to 00, 150>120150 > 120 maps to 11, 200>120200 > 120 maps to 11, resulting in [0, 1, 1]
    • Second row: 5012050 \leq 120 maps to 00, 120120120 \leq 120 maps to 00, 180>120180 > 120 maps to 11, resulting in [0, 0, 1]
  • The final output is [[0, 1, 1], [0, 0, 1]]

Constraints:

  • image is a 2D list of non-negative numbers
  • T is a numeric threshold
  • Return a 2D binary list (0 or 1)
Editor

Test Results

0/0
Run code to see test results.