v9.1.1
Menu

Simple Binary Thresholding

easyFREEImage SegmentationComputer Vision 2

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. Each output pixel depends only on the input pixel at the same position (x,y)(x, y), and the result has the same dimensions as the input:

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
  • image is a 2×32 \times 3 grid of grayscale intensities (2 rows, 3 columns), and T =120= 120 is the cut-off between the two classes.
  • Each pixel is judged on its own against the rule f(x,y)=1f(x, y) = 1 when I(x,y)>TI(x, y) > T, otherwise 00. Neighbouring pixels play no part.
  • Row 1: 100≤120⇒0100 \le 120 \Rightarrow 0, 150>120⇒1150 > 120 \Rightarrow 1, 200>120⇒1200 > 120 \Rightarrow 1, giving [0, 1, 1].
  • Row 2: 50≤120⇒050 \le 120 \Rightarrow 0, 120≤120⇒0120 \le 120 \Rightarrow 0, 180>120⇒1180 > 120 \Rightarrow 1, giving [0, 0, 1].
  • The result [[0, 1, 1], [0, 0, 1]] keeps the 2×32 \times 3 shape, but every intensity has collapsed to a class label: 11 marks the bright foreground, 00 the darker background.
  • Notice the middle pixel of row 2: it equals TT exactly, and the comparison is strict, so it lands in class 00. With T=119T = 119 it would flip to 11.

Constraints

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

More from Computer Vision 2

solution.py

Test results

Sign in to run your code against the test cases.