0
0
NumPydata~15 mins

Basic image manipulation with arrays in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Basic image manipulation with arrays
📖 Scenario: You have a small grayscale image represented as a 2D array of pixel brightness values. Each value ranges from 0 (black) to 255 (white). You want to perform simple image manipulations using arrays.
🎯 Goal: Learn how to create a numpy array to represent an image, set a brightness threshold, create a mask to highlight bright pixels, and display the result.
📋 What You'll Learn
Use numpy to create and manipulate arrays
Create a 2D numpy array with exact pixel values
Define a brightness threshold variable
Use array operations to create a mask of bright pixels
Print the resulting mask array
💡 Why This Matters
🌍 Real World
Image processing is used in photography, medical imaging, and computer vision to analyze and enhance pictures.
💼 Career
Understanding how to manipulate images as arrays is a key skill for data scientists working with image data or machine learning.
Progress0 / 4 steps
1
Create the image array
Create a 2D numpy array called image with these exact pixel values: [[10, 200, 30], [255, 100, 50], [0, 180, 220]].
NumPy
Need a hint?

Use np.array() to create the 2D array with the exact values.

2
Set the brightness threshold
Create a variable called threshold and set it to 150.
NumPy
Need a hint?

Just assign the number 150 to the variable threshold.

3
Create a mask for bright pixels
Create a variable called bright_mask that is a boolean numpy array. It should be True where image pixels are greater than threshold, and False otherwise.
NumPy
Need a hint?

Use the comparison operator > between image and threshold to get a boolean array.

4
Print the bright pixel mask
Print the variable bright_mask to display the boolean mask array.
NumPy
Need a hint?

Use print(bright_mask) to show the boolean array.