Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load an image using scipy.
SciPy
from scipy import [1] image = [1].face()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using scipy.ndimage instead of scipy.misc
Trying to load image without importing misc
✗ Incorrect
The scipy.misc module contains the face() function to load a sample image.
2fill in blank
mediumComplete the code to convert the image to grayscale using skimage.
SciPy
from skimage import [1] gray_image = [1].rgb2gray(image)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using scipy.misc for rgb2gray (it does not have it)
Trying to use ndimage for color conversion
✗ Incorrect
The rgb2gray function is in skimage.color to convert RGB images to grayscale.
3fill in blank
hardFix the error in the code to apply a Gaussian filter to the image.
SciPy
from scipy import ndimage filtered_image = ndimage.[1](image, sigma=3)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Misspelling the function name
Using a non-existent function like gauss_filter
✗ Incorrect
The correct function name is gaussian_filter in scipy.ndimage.
4fill in blank
hardFill both blanks to create a dictionary of pixel intensities for pixels greater than 100.
SciPy
pixel_dict = {pixel: pixel[1]2 for pixel in image.flatten() if pixel [2] 100} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using *2 instead of **2 for squaring
Using < instead of > in the condition
✗ Incorrect
We square the pixel value with **2 and filter pixels greater than 100 with >.
5fill in blank
hardFill all three blanks to create a filtered dictionary with uppercase keys and values greater than 50.
SciPy
filtered_pixels = { [1]: [2] for [1], [2] in pixel_dict.items() if [2] [3] 50} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pixel.upper() as key without defining pixel variable
Using < instead of > in condition
✗ Incorrect
Keys are pixel names, values are value, and we filter values > 50.