0
0
Computer Visionml~10 mins

Python CV ecosystem (OpenCV, PIL, torchvision) in Computer Vision - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read an image using OpenCV.

Computer Vision
import cv2
image = cv2.[1]('image.jpg')
Drag options to blanks, or click blank then click option'
Aimread
Bread
Copen
Dload
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cv2.read' instead of 'cv2.imread'.
Trying to use 'open' which is a Python built-in, not OpenCV.
2fill in blank
medium

Complete the code to convert a PIL image to a tensor using torchvision.

Computer Vision
from torchvision import transforms
transform = transforms.ToTensor()
tensor_image = transform([1])
Drag options to blanks, or click blank then click option'
Anumpy_array
Bimage_tensor
Ccv_image
Dpil_image
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a numpy array instead of a PIL image.
Passing an OpenCV image which is a numpy array with BGR channels.
3fill in blank
hard

Fix the error in the code to convert an OpenCV image to RGB format.

Computer Vision
import cv2
image_bgr = cv2.imread('image.jpg')
image_rgb = cv2.[1](image_bgr, cv2.COLOR_BGR2RGB)
Drag options to blanks, or click blank then click option'
AconvertColor
BcvtColor
CchangeColor
DtransformColor
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'convertColor' which does not exist in OpenCV.
Using 'transformColor' which is invalid.
4fill in blank
hard

Fill both blanks to create a PIL image from a numpy array and save it.

Computer Vision
from PIL import Image
import numpy as np
array = np.zeros((100, 100, 3), dtype=np.uint8)
img = Image.[1](array)
img.[2]('output.png')
Drag options to blanks, or click blank then click option'
Afromarray
Bsave
Cshow
Dopen
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Image.open' instead of 'Image.fromarray'.
Using 'img.show()' instead of 'img.save()' to save the image.
5fill in blank
hard

Fill all three blanks to normalize a tensor image using torchvision transforms.

Computer Vision
from torchvision import transforms
normalize = transforms.Normalize(mean=[[1]], std=[[2]])
transform = transforms.Compose([transforms.ToTensor(), normalize])
# Apply transform to PIL image
normalized_tensor = transform(pil_image)
print(normalized_tensor.mean().item() [3] 0)
Drag options to blanks, or click blank then click option'
A0.485, 0.456, 0.406
B0.229, 0.224, 0.225
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping mean and std values.
Using '<' instead of '>' in the print statement.