v9.1.1
Menu

Maximum Brightness Window

mediumFREESliding WindowSliding Window, DequeCV - DSA

Problem Statement

In image analysis, we often need to find the brightest region of a fixed size. Given a 1D array of pixel intensities and a window size k, find the maximum value in each sliding window position.

This is equivalent to applying a max filter (dilation in morphological operations).

Applications

  • Feature detection (finding local maxima)
  • Morphological dilation
  • Finding brightest regions for exposure adjustment

Constraints

  • 1≤len(pixels)≤100001 \leq len(pixels) \leq 10000
  • 1≤k≤len(pixels)1 \leq k \leq len(pixels)
  • 0≤pixels[i]≤2550 \leq pixels[i] \leq 255

Example

Input
pixels = [1, 3, 2, 5, 4, 1, 3], k = 3
Output
[3, 5, 5, 5, 4]
Reasoning
  • Input: pixels is a row of 7 intensities p0,…,p6=1,3,2,5,4,1,3p_0,\dots,p_6 = 1, 3, 2, 5, 4, 1, 3 (each in 00 to 255255), and k =3= 3 is the width of the window that slides one pixel at a time.
  • How many windows: a window of width kk fits in n−k+1=7−3+1=5n - k + 1 = 7 - 3 + 1 = 5 positions, so the output has 5 numbers. Window jj covers pixels pj,pj+1,pj+2p_j, p_{j+1}, p_{j+2}.
  • Math: each output is mj=max⁡(pj,pj+1,pj+2)m_j = \max(p_j, p_{j+1}, p_{j+2}):
    • j=0j=0: max⁡(1,3,2)=3\max(1,3,2) = 3
    • j=1j=1: max⁡(3,2,5)=5\max(3,2,5) = 5
    • j=2j=2: max⁡(2,5,4)=5\max(2,5,4) = 5
    • j=3j=3: max⁡(5,4,1)=5\max(5,4,1) = 5
    • j=4j=4: max⁡(4,1,3)=4\max(4,1,3) = 4
  • Output: [3, 5, 5, 5, 4], the max-filtered (dilated) signal. Notice the bright pixel 55 at index 3 wins every window that contains it (three of them), so one bright spot spreads across kk outputs, exactly what dilation does. Once it leaves, the answer drops to 44, not to the newly entered 33.

Learn this in

More from CV - DSA

solution.py

Test results

Sign in to run your code against the test cases.