TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Image Histogram

Computer Vision
Easy

Count grayscale pixel intensities and return a compact sparse histogram. Scan every pixel, count each intensity, then return only intensities that appear. Each output entry is a two-element list containing the intensity followed by its count. Sort entries by increasing intensity.

Loading visualization...

Examples

Input: image = [[0, 1], [1, 2]]

Output: [[0, 1], [1, 2], [2, 1]]

Explanation: Intensities zero and two occur once, while intensity one occurs twice.

Input: image = [[128, 128], [128, 128]]

Output: [[128, 4]]

Hint 1

Use a 256-element count list or a dictionary while scanning the pixels.

Hint 2

Build the result in increasing intensity order and skip zero counts.

Requirements

  • Count every pixel exactly once
  • Omit intensities whose count is zero
  • Sort entries by increasing intensity
  • Return a list of two-element intensity and count lists

Constraints

  • The image is a nonempty rectangular list
  • Every pixel is an integer between zero and 255
Try Similar Problems
Histogram EqualizationColor To GrayscaleGaussian Blur KernelConv2d Image FilteringSobel Edge Detection

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

You must run your code first.
PrevNext

Image Histogram

Computer Vision
Easy

Count grayscale pixel intensities and return a compact sparse histogram. Scan every pixel, count each intensity, then return only intensities that appear. Each output entry is a two-element list containing the intensity followed by its count. Sort entries by increasing intensity.

Loading visualization...

Examples

Input: image = [[0, 1], [1, 2]]

Output: [[0, 1], [1, 2], [2, 1]]

Explanation: Intensities zero and two occur once, while intensity one occurs twice.

Input: image = [[128, 128], [128, 128]]

Output: [[128, 4]]

Hint 1

Use a 256-element count list or a dictionary while scanning the pixels.

Hint 2

Build the result in increasing intensity order and skip zero counts.

Requirements

  • Count every pixel exactly once
  • Omit intensities whose count is zero
  • Sort entries by increasing intensity
  • Return a list of two-element intensity and count lists

Constraints

  • The image is a nonempty rectangular list
  • Every pixel is an integer between zero and 255
Try Similar Problems
Histogram EqualizationColor To GrayscaleGaussian Blur KernelConv2d Image FilteringSobel Edge Detection

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

You must run your code first.