📖 Scenario: You have a blurry photo and want to make it clearer by sharpening the image. Sharpening helps to highlight edges and details, making the picture look crisper.
🎯 Goal: Build a simple image sharpening process using a sharpening filter on a small grayscale image represented as a 2D list of pixel values.
📋 What You'll Learn
Create a 2D list called image with exact pixel values
Create a sharpening filter matrix called sharpen_filter
Apply the sharpening filter to the image using convolution
Print the sharpened image as a 2D list
💡 Why This Matters
🌍 Real World
Image sharpening is used in photography and medical imaging to improve picture clarity and highlight important details.
💼 Career
Understanding image processing basics is useful for roles in computer vision, digital photography, and AI that work with visual data.
Progress0 / 4 steps
1
Create the original image data
Create a 3x3 2D list called image with these exact pixel values: [[100, 100, 100], [100, 50, 100], [100, 100, 100]]
Signal Processing
Hint
Use square brackets to create a list of lists. Each inner list is a row of pixels.
2
Create the sharpening filter
Create a 3x3 sharpening filter called sharpen_filter with these exact values: [[0, -1, 0], [-1, 5, -1], [0, -1, 0]]
Signal Processing
Hint
The sharpening filter has a strong center value and negative neighbors.
3
Apply the sharpening filter
Write code to apply the sharpen_filter to the image using convolution. Create a new 3x3 list called sharpened_image where each pixel is calculated by multiplying the filter with the corresponding pixels and summing the result. Ignore edges (keep them same as original). Use variables i and j to loop over the inner pixels.
Signal Processing
Hint
Use nested loops to slide the filter over the image center pixel only. Copy edges as is.
4
Print the sharpened image
Print the sharpened_image list to show the result.
Signal Processing
Hint
Use print(sharpened_image) to show the final sharpened image.
Practice
(1/5)
1. What is the main purpose of image sharpening in signal processing?
easy
A. To reduce the image size
B. To highlight edges and make the image clearer
C. To blur the image for artistic effect
D. To convert the image to grayscale
Solution
Step 1: Understand image sharpening
Image sharpening enhances edges and details to make images clearer.
Step 2: Compare options
Only To highlight edges and make the image clearer describes highlighting edges and clarity, which is the goal of sharpening.
Final Answer:
To highlight edges and make the image clearer -> Option B
Quick Check:
Image sharpening = highlight edges [OK]
Hint: Sharpening means making edges clearer, not blurring [OK]
Common Mistakes:
Confusing sharpening with blurring
Thinking sharpening changes image size
Assuming sharpening converts color formats
2. Which of the following is the correct Python syntax to apply a simple sharpening kernel using convolution with OpenCV?
easy
A. cv2.sharpen(image, kernel)
B. cv2.convolve(image, kernel)
C. cv2.filter2D(image, -1, kernel)
D. cv2.applySharpen(image, kernel)
Solution
Step 1: Recall OpenCV function for convolution
OpenCV uses cv2.filter2D() to apply kernels for filtering images.
Step 2: Check options
Only cv2.filter2D(image, -1, kernel) uses cv2.filter2D with correct parameters; others are invalid functions.
Final Answer:
cv2.filter2D(image, -1, kernel) -> Option C
Quick Check:
OpenCV convolution = filter2D [OK]
Hint: Use cv2.filter2D for custom kernel convolution [OK]
Common Mistakes:
Using non-existent OpenCV functions
Confusing convolution with sharpening function names
Incorrect parameter order
3. Given the following Python code using OpenCV, what will be the output type of sharpened?
ddepth=-1 means output image has same depth as input; 1 is invalid and may cause errors.
Step 2: Validate other code parts
Kernel shape is valid, cv2.imshow supports color, waitKey(0) is correct usage.
Final Answer:
The ddepth parameter should be -1, not 1 -> Option A
Quick Check:
ddepth=-1 for same depth [OK]
Hint: Use ddepth=-1 in filter2D to keep image depth [OK]
Common Mistakes:
Using wrong ddepth value causing errors
Thinking kernel shape is wrong
Misunderstanding cv2.imshow capabilities
5. You want to sharpen an image using unsharp masking. Which sequence of steps correctly applies this method?
hard
A. Directly apply a sharpening kernel without blurring
B. Add noise to the image, then apply a sharpening kernel
C. Convert image to grayscale, then apply a sharpening kernel
D. Blur the image, subtract the blurred from original, then add result back to original
Solution
Step 1: Understand unsharp masking process
Unsharp masking involves blurring the image, subtracting this blur from original to get edges, then adding edges back.
Step 2: Evaluate options
Only Blur the image, subtract the blurred from original, then add result back to original correctly describes this sequence; others miss key steps or add unrelated actions.
Final Answer:
Blur the image, subtract the blurred from original, then add result back to original -> Option D
Quick Check:
Unsharp masking = blur, subtract, add [OK]
Hint: Unsharp masking = blur, subtract, add back edges [OK]
Common Mistakes:
Skipping the blur step
Adding noise instead of subtracting blur
Applying sharpening kernel directly without unsharp steps
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.