By completing this activity, you will:
- Image Resizing: Scale images to different sizes using OpenCV resize functions
- Color Space Conversion: Transform images between different color representations (BGR, Gray, HSV, RGB)
- Edge Detection: Apply Canny edge detection to identify object boundaries
- Image Filtering: Use Gaussian blur for image smoothing and noise reduction
- Practical Applications: Understand when to use each image processing technique
Before starting the challenge, explore the complete working solution to understand what you are building toward:
bash
jupyter notebook v1-baseline-100percent.ipynb
What to observe:
- Question 1: How to resize large images to smaller dimensions
- Question 2: How to convert images to different color spaces and apply filters
- Bonus Challenge: How to upload and process your own images
- Run all cells (Cell -> Run All) to see all transformations
Once you have explored the baseline, open your challenge notebook:
bash
jupyter notebook activity-14-image-processing.ipynb
Your template comes with 60% working code including:
- File downloads: Automated download of sample images (cats.jpg, outing_large.jpg)
- Library imports: OpenCV and Colab display helpers
- Image loading: Initial cv.imread() calls
- Bonus upload: Google Colab file upload functionality
- Display functions: Working cv2_imshow() examples
- Helper scripts: resize_image.py and convert_image.py for reference
| TODO |
Task |
Difficulty |
Estimated Time |
| 1 |
Rescale Image to 20% |
Easy |
8 minutes |
Concepts: cv.resize(), dimension calculation, interpolation methods
What you'll do:
- Calculate new dimensions (20% of original)
- Use
cv.resize() with INTER_AREA interpolation
- Display the resized image
| TODO |
Task |
Difficulty |
Estimated Time |
| 2 |
Convert Image to Multiple Formats |
Medium |
12 minutes |
Concepts: cv.cvtColor(), cv.Canny(), cv.GaussianBlur(), color spaces
What you'll do:
- Convert to grayscale (for single-channel processing)
- Convert to HSV (for color-based segmentation)
- Convert to RGB (for matplotlib compatibility)
- Apply Canny edge detection (for boundary detection)
- Apply Gaussian blur (for smoothing)
After completing all TODOs, you should be able to:
- ✅ Resize
outing_large.jpg to 20% of its original size
- ✅ Convert
cats.jpg to grayscale, HSV, and RGB color spaces
- ✅ Apply Canny edge detection to find edges in the image
- ✅ Apply Gaussian blur with kernel size (7,7)
- ✅ Display all processed images in Google Colab
For advanced students who want to go beyond:
- Custom Scaling: Try different scale factors (50%, 150%, 200%)
- Multiple Interpolations: Compare INTER_AREA, INTER_LINEAR, INTER_CUBIC
- Edge Parameters: Experiment with different Canny thresholds (e.g., 50/100, 100/200)
- Blur Variations: Try different kernel sizes for Gaussian blur
- Color Segmentation: Use HSV conversion to isolate specific colors
- Upload Processing: Process your own image through all transformations
This activity includes:
| File |
Purpose |
cats.jpg |
Sample image for color conversions (69 KB) |
outing_large.jpg |
Large image for resizing practice (2.5 MB) |
resize_image.py |
Helper script with resize example |
convert_image.py |
Helper script with conversion examples |
- Dimension Order: OpenCV uses (width, height) but image.shape returns (height, width, channels)
- Color Spaces: BGR is OpenCV default; RGB is for matplotlib; HSV is for color segmentation
- Edge Detection: Lower thresholds = more edges; higher thresholds = fewer edges
- Blur Kernel: Must be odd numbers (3,3), (5,5), (7,7), etc.
- Interpolation: Use INTER_AREA for shrinking, INTER_CUBIC for enlarging
| Issue |
Solution |
| Wrong dimensions |
Remember: shape[1] = width, shape[0] = height |
| Blur error |
Kernel size must be odd numbers (7,7) not (8,8) |
| Canny requires grayscale |
Convert to gray first or pass color image directly |
| Image too small/large |
Check scale factor calculation (0.2 = 20%, not 2.0) |
- cv.resize(img, dim, interpolation): Resizes image to specified dimensions
- cv.cvtColor(img, conversion_code): Converts between color spaces
- cv.Canny(img, threshold1, threshold2): Detects edges using Canny algorithm
- cv.GaussianBlur(img, kernel_size, border_type): Applies Gaussian smoothing
- COLOR_BGR2GRAY: Converts BGR (color) to grayscale (single channel)
- COLOR_BGR2HSV: Converts BGR to Hue-Saturation-Value color space
- COLOR_BGR2RGB: Converts BGR (OpenCV) to RGB (standard)
- Resizing: Thumbnail generation, web optimization, memory management
- Grayscale: Simplified processing, text recognition, speed improvement
- HSV: Color-based object detection, skin detection, image segmentation
- Edge Detection: Object recognition, feature extraction, boundary detection
- Blur: Noise reduction, privacy masking, artistic effects
Estimated Completion Time: 20 minutes
Previous Activity: Activity 13 - OpenCV Basics
Next Activity: Activity 15 - Drawing with OpenCV