InterviewDB Experience

Camera Intensity: Compute Pixel Intensity Statistics Across a Camera Feed

Interview Experience

Problem

Given a grayscale image as a 2D array of pixel intensities (0-255), compute the mean, median, and histogram of intensities. Then implement a function that adjusts contrast by stretching the intensity range to fill [0, 255].

python
import numpy as np
from typing import Tuple

def intensity_stats(image: list[list[int]]) -> dict:

**returns**: {"mean": float, "median": float, "histogram": list[int] of length 256}
    pass

def stretch_contrast(image: list[list[int]]) -> list[list[int]]:
    # Linearly maps [min_intensity, max_intensity] -> [0, 255]
    pass

Example:

image = [[0, 128], [64, 192]]
stretch_contrast([[10, 110], [60, 160]])
# min=10, max=160 -> new = (old-10) * 255/150
-> [[0, 170], [85, 255]]

Follow-ups

  1. When is linear contrast stretching inadequate, and how does histogram equalization improve it?
  2. How would you apply this operation in real time to a 30 fps camera stream?
  3. How do you extend intensity stretching to a 3-channel (RGB) image without distorting colors?
  4. What happens when min_intensity == max_intensity (uniform image)?

Full Details

Problem

Given a grayscale image as a 2D array of pixel intensities (0-255), compute the mean, median, and histogram of intensities. Then implement a function that adjusts contrast by stretching the intensity range to fill [0, 255].

python
import numpy as np
from typing import Tuple

def intensity_stats(image: list[list[int]]) -> dict:

**returns**: {"mean": float, "median": float, "histogram": list[int] of length 256}
    pass

def stretch_contrast(image: list[list[int]]) -> list[list[int]]:
    # Linearly maps [min_intensity, max_intensity] -> [0, 255]
    pass

Example:

image = [[0, 128], [64, 192]]
stretch_contrast([[10, 110], [60, 160]])
# min=10, max=160 -> new = (old-10) * 255/150
-> [[0, 170], [85, 255]]

Follow-ups

  1. When is linear contrast stretching inadequate, and how does histogram equalization improve it?
  2. How would you apply this operation in real time to a 30 fps camera stream?
  3. How do you extend intensity stretching to a 3-channel (RGB) image without distorting colors?
  4. What happens when min_intensity == max_intensity (uniform image)?

About This Question

This is a candidate experience report from a verkada interview during the phone round.

It covers the following topics: Arrays, Coding, Phone, Matrix .