Bird
Raised Fist0
Computer Visionml~20 mins

Cropping images in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Cropping Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the shape of the cropped image?
Given a 100x100 RGB image represented as a NumPy array, what will be the shape of the cropped image after executing the following code?

cropped_img = img[20:70, 30:80]
Computer Vision
import numpy as np
img = np.zeros((100, 100, 3))
cropped_img = img[20:70, 30:80]
A(51, 51, 3)
B(50, 50, 3)
C(49, 49, 3)
D(50, 50)
Attempts:
2 left
💡 Hint
Remember that slicing in Python includes the start index but excludes the end index.
Model Choice
intermediate
1:30remaining
Choosing the best cropping method for data augmentation
You want to augment your image dataset by cropping random patches of size 64x64 from 256x256 images during training. Which method is best to implement this in a deep learning pipeline?
ARandomly select top-left coordinates and crop 64x64 patches on the fly during training.
BUse a fixed crop of the center 64x64 pixels for all images.
CResize images to 64x64 instead of cropping.
DCrop the bottom-right 64x64 pixels for all images.
Attempts:
2 left
💡 Hint
Data augmentation should introduce variety to help the model generalize.
Metrics
advanced
2:00remaining
Effect of cropping on model accuracy
You train two image classifiers on the same dataset. Model A uses full 128x128 images. Model B uses center-cropped 64x64 images. After training, Model A achieves 92% accuracy, Model B achieves 85%. What is the most likely reason for the accuracy drop in Model B?
AModel B used a different optimizer causing lower accuracy.
BCenter cropping introduced noise that confused the model.
CModel B was trained with fewer epochs than Model A.
DCropping reduced the amount of useful information available to the model.
Attempts:
2 left
💡 Hint
Think about what information might be lost when cropping images smaller.
🔧 Debug
advanced
1:30remaining
Why does this cropping code raise an error?
Consider this code snippet:

cropped = img[50:30, 20:70]

Why does this raise an error or produce an unexpected result?
Computer Vision
import numpy as np
img = np.zeros((100, 100, 3))
cropped = img[50:30, 20:70]
AThe start index is greater than the end index in the first slice, resulting in an empty array.
BThe slice syntax is invalid and causes a SyntaxError.
CThe image array does not have enough dimensions for this slicing.
DThe indices are out of bounds causing an IndexError.
Attempts:
2 left
💡 Hint
Check how Python slicing behaves when start > end.
🧠 Conceptual
expert
2:30remaining
Impact of cropping on convolutional neural network feature maps
When you crop input images before feeding them into a convolutional neural network (CNN), how does this affect the spatial dimensions of the feature maps in the early convolutional layers compared to using full images?
AFeature maps will be larger because cropping increases feature resolution.
BFeature maps will have the same spatial dimensions regardless of input size due to padding.
CFeature maps will have smaller spatial dimensions proportional to the cropped input size.
DFeature maps will be one-dimensional vectors after cropping.
Attempts:
2 left
💡 Hint
Consider how input size affects convolution output size.

Practice

(1/5)
1. What does cropping an image do in computer vision?
easy
A. Increases the image resolution
B. Changes the color of the entire image
C. Cuts out a part of the image using row and column ranges
D. Rotates the image by 90 degrees

Solution

  1. Step 1: Understand cropping concept

    Cropping means selecting a smaller part of the image by specifying rows and columns.
  2. Step 2: Compare options with definition

    Only Cuts out a part of the image using row and column ranges describes cutting out part of the image using row and column ranges.
  3. Final Answer:

    Cuts out a part of the image using row and column ranges -> Option C
  4. Quick Check:

    Cropping = cutting part of image [OK]
Hint: Cropping means cutting out part of the image [OK]
Common Mistakes:
  • Confusing cropping with resizing
  • Thinking cropping changes colors
  • Mixing cropping with rotation
2. Which of the following is the correct syntax to crop an image stored in variable img to rows 10 to 50 and columns 20 to 70 in Python?
easy
A. img[10:50, 20:70]
B. img[20:70, 10:50]
C. img[10:50][20:70]
D. img.crop(10,50,20,70)

Solution

  1. Step 1: Recall slicing syntax for images

    Images are sliced as img[row_start:row_end, col_start:col_end].
  2. Step 2: Match given ranges to syntax

    Rows 10 to 50 and columns 20 to 70 means img[10:50, 20:70].
  3. Final Answer:

    img[10:50, 20:70] -> Option A
  4. Quick Check:

    Rows first, columns second in slicing [OK]
Hint: Remember slicing is img[row_start:row_end, col_start:col_end] [OK]
Common Mistakes:
  • Swapping row and column indices
  • Using double brackets instead of comma
  • Using a non-existent crop method
3. Given the code:
import numpy as np
img = np.arange(100).reshape(10,10)
cropped = img[2:5, 3:7]
print(cropped)

What is the output?
medium
A. [[3 4 5 6] [13 14 15 16] [23 24 25 26]]
B. [[23 24 25 26] [33 34 35 36] [43 44 45 46]]
C. [[23 24 25 26 27] [33 34 35 36 37] [43 44 45 46 47]]
D. [[32 33 34 35] [42 43 44 45] [52 53 54 55]]

Solution

  1. Step 1: Understand the image array

    img is a 10x10 array with values from 0 to 99 arranged row-wise.
  2. Step 2: Extract rows 2 to 4 and columns 3 to 6

    Rows 2,3,4 correspond to indices 2,3,4; columns 3,4,5,6 correspond to indices 3 to 6 exclusive of 7.
  3. Step 3: Identify values in cropped

    Row 2: values 20 to 29, columns 3 to 6 are 23,24,25,26
    Row 3: 33,34,35,36
    Row 4: 43,44,45,46
  4. Final Answer:

    [[23 24 25 26] [33 34 35 36] [43 44 45 46]] -> Option B
  5. Quick Check:

    Slice rows 2-5 and cols 3-7 gives these values [OK]
Hint: Check array shape and slicing ranges carefully [OK]
Common Mistakes:
  • Confusing row and column indices
  • Including end index in slice
  • Misreading array reshape order
4. You try to crop an image using cropped = img[50:100, 30:60] but get an IndexError. What is the likely cause?
medium
A. The image variable is not defined
B. The slicing syntax is incorrect
C. The image is grayscale, not color
D. The image has fewer than 100 rows

Solution

  1. Step 1: Understand IndexError cause

    IndexError occurs when slicing beyond array dimensions.
  2. Step 2: Analyze slicing indices

    Rows 50 to 100 means accessing rows starting at 50. If image has fewer rows, this causes error.
  3. Final Answer:

    The image has fewer than 100 rows -> Option D
  4. Quick Check:

    IndexError = slicing outside image size [OK]
Hint: Check image shape before slicing [OK]
Common Mistakes:
  • Assuming syntax error causes IndexError
  • Confusing color channels with rows
  • Not checking if variable is defined
5. You have a 200x200 image and want to crop a centered square of size 100x100. Which code correctly crops this center square?
hard
A. img[50:150, 50:150]
B. img[0:100, 0:100]
C. img[100:200, 100:200]
D. img[25:125, 25:125]

Solution

  1. Step 1: Calculate center start and end indices

    Center of 200x200 is at 100,100. Half of 100 size is 50.
  2. Step 2: Determine crop range

    Start at 100-50=50, end at 100+50=150 for both rows and columns.
  3. Final Answer:

    img[50:150, 50:150] -> Option A
  4. Quick Check:

    Center crop = middle 100 pixels from 200 [OK]
Hint: Center crop start = center - half size [OK]
Common Mistakes:
  • Starting crop at 0 instead of center
  • Using wrong indices for center
  • Cropping smaller or larger than requested