Bird
Raised Fist0
Computer Visionml~20 mins

IoU (Intersection over Union) in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
IoU Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
๐Ÿง  Conceptual
intermediate
1:30remaining
Understanding IoU Calculation

Given two bounding boxes, what does the Intersection over Union (IoU) metric measure?

AThe sum of the areas of the two boxes without considering overlap.
BThe ratio of the overlapping area of the two boxes to the total area covered by both boxes combined.
CThe difference between the areas of the two boxes.
DThe ratio of the smaller box area to the larger box area.
Attempts:
2 left
๐Ÿ’ก Hint

Think about how much two boxes overlap compared to their combined size.

โ“ Predict Output
intermediate
2:00remaining
Calculate IoU for Two Boxes

What is the output of the following Python code that calculates IoU for two bounding boxes?

Computer Vision
def iou(box1, box2):
    x_left = max(box1[0], box2[0])
    y_top = max(box1[1], box2[1])
    x_right = min(box1[2], box2[2])
    y_bottom = min(box1[3], box2[3])

    if x_right < x_left or y_bottom < y_top:
        return 0.0

    intersection_area = (x_right - x_left) * (y_bottom - y_top)

    box1_area = (box1[2] - box1[0]) * (box1[3] - box1[1])
    box2_area = (box2[2] - box2[0]) * (box2[3] - box2[1])

    iou_value = intersection_area / float(box1_area + box2_area - intersection_area)
    return round(iou_value, 2)

box1 = [1, 1, 4, 4]
box2 = [2, 2, 5, 5]
print(iou(box1, box2))
A0.14
B0.25
C0.11
D0.29
Attempts:
2 left
๐Ÿ’ก Hint

Calculate intersection and union areas carefully.

โ“ Model Choice
advanced
1:30remaining
Choosing IoU Threshold for Object Detection

In object detection, which IoU threshold is commonly used to decide if a predicted bounding box is a true positive?

A0.1
B0.75
C0.5
D0.9
Attempts:
2 left
๐Ÿ’ก Hint

Think about a balance between strictness and leniency in overlap.

โ“ Metrics
advanced
2:00remaining
Effect of IoU Threshold on Precision and Recall

What happens to precision and recall when the IoU threshold for true positive detection is increased from 0.5 to 0.75?

APrecision increases, recall decreases
BPrecision decreases, recall increases
CBoth precision and recall increase
DBoth precision and recall decrease
Attempts:
2 left
๐Ÿ’ก Hint

Higher IoU threshold means stricter matching.

๐Ÿ”ง Debug
expert
2:30remaining
Debugging IoU Calculation Code

What error does the following IoU calculation code produce when run, and why?

Computer Vision
def iou(box1, box2):
    x_left = min(box1[0], box2[0])
    y_top = min(box1[1], box2[1])
    x_right = max(box1[2], box2[2])
    y_bottom = max(box1[3], box2[3])

    if x_right < x_left or y_bottom < y_top:
        return 0.0

    intersection_area = (x_right - x_left) * (y_bottom - y_top)

    box1_area = (box1[2] - box1[0]) * (box1[3] - box1[1])
    box2_area = (box2[2] - box2[0]) * (box2[3] - box2[1])

    iou_value = intersection_area / float(box1_area + box2_area - intersection_area)
    return iou_value

box1 = [1, 1, 4, 4]
box2 = [2, 2, 5, 5]
print(iou(box1, box2))
AThe code returns IoU greater than 1 because it uses min and max incorrectly for intersection coordinates.
BThe code raises a ZeroDivisionError because intersection_area is zero.
CThe code returns zero because the boxes do not overlap.
DThe code runs correctly and returns the correct IoU.
Attempts:
2 left
๐Ÿ’ก Hint

Check how intersection coordinates are calculated.

Practice

(1/5)
1. What does IoU (Intersection over Union) measure in computer vision?
easy
A. The overlap between two bounding boxes
B. The distance between two points
C. The brightness of an image
D. The number of pixels in an image

Solution

  1. Step 1: Understand IoU definition

    IoU measures how much two areas overlap compared to their total combined area.
  2. Step 2: Identify what IoU compares

    It compares two bounding boxes or regions to see how well they match.
  3. Final Answer:

    The overlap between two bounding boxes -> Option A
  4. Quick Check:

    IoU = Overlap / Union [OK]
Hint: IoU = Overlap area divided by combined area [OK]
Common Mistakes:
  • Confusing IoU with distance metrics
  • Thinking IoU measures brightness or color
  • Assuming IoU can be greater than 1
2. Which of the following is the correct formula for IoU between two boxes A and B?
easy
A. Area(A) + Area(B)
B. Area(A โˆฉ B) / Area(A โˆช B)
C. Area(A โˆช B) / Area(A โˆฉ B)
D. Area(A) - Area(B)

Solution

  1. Step 1: Recall IoU formula

    IoU is defined as the intersection area divided by the union area of two boxes.
  2. Step 2: Match formula to options

    Area(A โˆฉ B) / Area(A โˆช B) correctly shows IoU = Area of intersection over area of union.
  3. Final Answer:

    Area(A โˆฉ B) / Area(A โˆช B) -> Option B
  4. Quick Check:

    IoU = Intersection / Union [OK]
Hint: IoU = Intersection area รท Union area [OK]
Common Mistakes:
  • Swapping numerator and denominator
  • Adding areas instead of dividing
  • Subtracting areas instead of dividing
3. Given two bounding boxes: Box A with area 20, Box B with area 30, and their intersection area is 10, what is the IoU?
medium
A. 0.25
B. 0.33
C. 0.5
D. 0.67

Solution

  1. Step 1: Calculate union area

    Union = Area(A) + Area(B) - Intersection = 20 + 30 - 10 = 40.
  2. Step 2: Calculate IoU

    IoU = Intersection / Union = 10 / 40 = 0.25.
  3. Final Answer:

    0.25 -> Option A
  4. Quick Check:

    IoU = 10/40 = 0.25 [OK]
Hint: IoU = Intersection รท (A + B - Intersection) [OK]
Common Mistakes:
  • Forgetting to subtract intersection in union
  • Using sum of areas as union
  • Mixing up intersection and union values
4. Consider this Python code to compute IoU:
def iou(area_a, area_b, intersection):
    union = area_a + area_b + intersection
    return intersection / union

print(iou(15, 25, 5))
What is the error in this code?
medium
A. Function should return union instead of IoU
B. Intersection should be added twice in union
C. Division should be union divided by intersection
D. Union is calculated incorrectly by adding intersection instead of subtracting

Solution

  1. Step 1: Check union calculation

    Union should be area_a + area_b - intersection, not plus intersection.
  2. Step 2: Identify impact on IoU

    Adding intersection inflates union, making IoU smaller than correct value.
  3. Final Answer:

    Union is calculated incorrectly by adding intersection instead of subtracting -> Option D
  4. Quick Check:

    Union = A + B - Intersection [OK]
Hint: Union = sum of areas minus intersection [OK]
Common Mistakes:
  • Adding intersection instead of subtracting
  • Swapping numerator and denominator
  • Returning union instead of IoU
5. You have two predicted bounding boxes and one ground truth box. Box1 IoU with ground truth is 0.6, Box2 IoU is 0.4. If the threshold for a correct detection is 0.5, which box is considered a correct detection and why?
hard
A. Both boxes are correct because any IoU > 0 counts
B. Only Box2 is correct because it has lower IoU
C. Only Box1 is correct because its IoU is above 0.5
D. Neither box is correct because threshold is 0.7

Solution

  1. Step 1: Understand IoU threshold meaning

    Threshold 0.5 means IoU must be at least 0.5 to count as correct detection.
  2. Step 2: Compare IoU values to threshold

    Box1 IoU = 0.6 > 0.5 (correct), Box2 IoU = 0.4 < 0.5 (incorrect).
  3. Final Answer:

    Only Box1 is correct because its IoU is above 0.5 -> Option C
  4. Quick Check:

    IoU โ‰ฅ 0.5 means correct detection [OK]
Hint: IoU must meet threshold to be correct detection [OK]
Common Mistakes:
  • Ignoring threshold and accepting all IoUs
  • Confusing higher IoU as incorrect
  • Using wrong threshold value
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard