0
0
Computer Visionml~10 mins

Histogram computation in Computer Vision - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to compute the histogram of a grayscale image using OpenCV.

Computer Vision
import cv2
image = cv2.imread('image.jpg', 0)
hist = cv2.calcHist([image], [0], None, [256], [0, [1]])
Drag options to blanks, or click blank then click option'
A256
B255
C257
D128
Attempts:
3 left
💡 Hint
Common Mistakes
Using 255 as the upper range causes the last pixel value to be excluded.
Using 128 limits the histogram to half the grayscale range.
2fill in blank
medium

Complete the code to normalize the histogram so that the sum of all bins equals 1.

Computer Vision
hist_norm = hist / [1]
Drag options to blanks, or click blank then click option'
Ahist.sum()
Bhist.max()
Clen(hist)
D256
Attempts:
3 left
💡 Hint
Common Mistakes
Dividing by max() scales the histogram incorrectly.
Dividing by length or fixed number does not normalize properly.
3fill in blank
hard

Fix the error in the code to compute a color histogram for a BGR image.

Computer Vision
image = cv2.imread('color.jpg')
hist = cv2.calcHist([image], [[1]], None, [256], [0, 256])
Drag options to blanks, or click blank then click option'
A3
B0
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using channel 3 causes an index error because only 0,1,2 exist.
Using channel 1 or 2 is valid but not the fix requested.
4fill in blank
hard

Fill both blanks to compute and normalize a histogram for the red channel of a color image.

Computer Vision
image = cv2.imread('color.jpg')
hist = cv2.calcHist([image], [[1]], None, [256], [0, 256])
hist_norm = hist / [2]
Drag options to blanks, or click blank then click option'
A2
Bhist.sum()
C0
Dimage.size
Attempts:
3 left
💡 Hint
Common Mistakes
Using channel 0 or 1 selects wrong color channels.
Dividing by image.size does not normalize histogram counts correctly.
5fill in blank
hard

Fill all three blanks to create a histogram for the green channel, normalize it, and then find the bin with the maximum frequency.

Computer Vision
image = cv2.imread('color.jpg')
hist = cv2.calcHist([image], [[1]], None, [256], [0, 256])
hist_norm = hist / [2]
max_bin = hist_norm.[3]()
Drag options to blanks, or click blank then click option'
A1
Bhist.sum()
Cargmax
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using max() returns the maximum value, not the bin index.
Using wrong channel index selects incorrect color channel.