S332 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

S3 · Lesson 32 · Streaming image pipelines

Processing video one pixel per clock with line buffers instead of frame buffers

A 1080p camera at 60 frames per second delivers 124 million pixels a second, and a filter that looks at each pixel's 3 × 3 neighborhood needs nine pixels for every output. Storing whole frames in DRAM and reading neighborhoods back would need gigabytes per second of bandwidth. Hardware does it differently: pixels arrive in raster order, one per clock, and a few line buffers in on-chip memory hold just the previous rows, so every neighborhood is available as the new pixel arrives. Lesson 31's DSP structures, applied in two dimensions with this memory trick, are how cameras, displays and machine-vision chips process video in real time.

  • The on-chip memory a k×k filter's line buffers need, (k−1)×W×b bits for image width W and b bits per pixel, against image width, for 8-bit pixels.
  • A frame buffer for the same image needs W×H×b bits: hundreds of times more. The readout compares them for a 1080-row image.

Predict

A 3 × 3 filter processes 1920-pixel-wide, 8-bit video. How much on-chip memory do its line buffers need?

Name it

Raster streams

Video arrives as a stream: pixels left to right along a row, rows top to bottom, one pixel per pixel clock, with blanking intervals between rows and frames. 1080p60 has 1920 × 1080 active pixels at 60 frames per second, 124.4 megapixels per second, carried on a 148.5 MHz pixel clock because of the blanking: 2200 × 1125 total per frame.

Line buffers

A k×k window needs the current pixel and the k−1 rows above it. Each row is held in a FIFO-like line buffer of W pixels; as a pixel arrives, it enters the first buffer and the oldest pixel of each buffer moves to the next. Tapping the buffers' outputs gives one column of the window per clock, and a shift register of k columns holds the whole window. Memory: (k−1)Wb bits. Latency: about (k−1)/2 rows plus a few pixels, so the output is a small fraction of a frame behind the input.

Throughput and arithmetic

At one pixel per clock, a general k×k convolution needs k2 multiplies every clock. Separable kernels (a Gaussian, a box) split into a k-tap horizontal and a k-tap vertical pass, 2k multiplies. At 4K60, 498 megapixels per second, designs process two or four pixels per clock to keep the clock rate reasonable.

Edges and frames

At the image's borders the window hangs off the edge. Hardware replicates or mirrors the edge pixels, or marks the output invalid, using row and column counters driven by the stream's sync signals. Operations that need more than a few rows, such as rotations or large resizes, need a frame buffer in DRAM after all, and its bandwidth: W×H×b×f for each pass.

Worked example

Size the line buffers for a 3 × 3 filter on 1920 × 1080, 8-bit video, and for a 5 × 5 filter on 3840 × 2160, 10-bit video.

Show the solution
  1. 1080p, 3 × 3. Two lines of 1920 pixels at 8 bits: 2×1920×8=30720bits which is 3.75 KB.
  2. 4K, 5 × 5. Four lines of 3840 pixels at 10 bits: 4×3840×10=153600bits which is 18.75 KB. Both fit comfortably in on-chip RAM.
  3. Against a full frame. A full 4K frame at 10 bits is 83 Mbit, 10.4 MB: line buffering saves a factor of 540.

Answer 30 720 bits (3.75 KB) for the 1080p filter and 153 600 bits (18.75 KB) for the 4K one.

Worked example

A frame buffer for 1080p60 RGB at 24 bits per pixel is written once and read once per frame. What memory bandwidth does it need?

Show the solution
  1. One frame. 1920×1080×3=6.22MB
  2. Bandwidth. Each frame is written and read, 60 times a second: 2×6.22×60=746MB/s
  3. What it costs. That is a sizable share of a DDR interface, and the latency of DRAM accesses must be hidden with FIFOs. A streaming design that avoids the frame buffer needs none of it.

Answer 746 MB/s.

Worked example

A 7 × 7 Gaussian blur runs on 4K60 video. Compare the multiplies per second for a direct 2D convolution and a separable one.

Show the solution
  1. Pixel rate. 3840×2160×60=498×106 pixels per second.
  2. Direct. 49 multiplies per pixel, 24.4 billion per second.
  3. Separable. 14 per pixel, 7.0 billion per second.
  4. Why it works. Gaussian kernels are separable, so the second is exact, and the 3.5× saving in DSP blocks is why designers check for separability first.

Answer 24.4 billion multiplies a second direct, against 7.0 billion separable.

Check

How much line-buffer memory does a 5 × 5 filter need on a 640-pixel-wide image with 12-bit pixels, in KB (1024 bytes)?

Check

A stream carries 1920 × 720 active pixels at 120 frames per second. How many megapixels per second does a one-pixel-per-clock pipeline process (ignoring blanking)?

Write units the way you normally would: 1.5 MHz, 1500 kHz and 0.0015 GHz are the same answer.

Check

A 5 × 5 separable filter processes 124 million pixels per second.

(a)

How many billion multiplies per second would a direct 2D convolution need?

(b)

And the separable version?

Check

A frame buffer holds 1920 × 1080 images at 4 bytes per pixel, written and read once per frame at 60 frames per second. What bandwidth does it need?

Check

A 5 × 5 window pipeline on a 1920-wide image has a total line time (with blanking) of 4400 pixel clocks. About how many clocks does its output lag the input, counting the (k−1)/2 rows of delay to the window's center?

Check

Which operation can't be done with a few line buffers in a raster-order streaming pipeline?

Check

Model a streaming 3 × 3 box filter. Generate an image img = numpy.random.default_rng(seed).integers(0, 256, (H, W)) with H = 6, W = 8. Write stream_box(img), which reads pixels in raster order one at a time, keeps two line buffers (Python lists) of the previous rows and a 3-column window, and outputs the integer sum of each fully valid 3 × 3 window (no padding), returning an (H - 2) × (W - 2) array. Set out and ref, the same sums computed directly with slicing, and match = bool((out == ref).all()).

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Explain why

A camera team wants to add lens-distortion correction, which moves each output pixel's source by up to 40 rows, to a streaming pipeline that has only small line buffers. Explain the memory implications and options.

Practice

Keep practicing

8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.