Bird
Raised Fist0
Signal Processingdata~20 mins

Image as 2D signal in Signal Processing - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
2D Signal Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of 2D image array slicing
What is the output of the following code that slices a 2D image array?
Signal Processing
import numpy as np
image = np.array([[10, 20, 30], [40, 50, 60], [70, 80, 90]])
slice_ = image[1:, :2]
print(slice_)
A
[[40 50]
 [70 80]]
B
[[40 50 60]
 [70 80 90]]
C
[[20 30]
 [50 60]]
D
[[50 60]
 [80 90]]
Attempts:
2 left
💡 Hint
Remember that slicing [1:, :2] means rows from index 1 to end and columns from index 0 to 1.
❓ data_output
intermediate
2:00remaining
Shape of a grayscale image array after resizing
Given a grayscale image represented as a 2D NumPy array of shape (256, 256), what will be the shape after resizing it to half the width and height using nearest neighbor?
Signal Processing
import numpy as np
from skimage.transform import resize
image = np.random.randint(0, 256, (256, 256), dtype=np.uint8)
resized_image = resize(image, (128, 128), order=0, preserve_range=True).astype(np.uint8)
print(resized_image.shape)
A(256, 128)
B(128, 256)
C(128, 128)
D(64, 64)
Attempts:
2 left
💡 Hint
Resizing to half width and height means both dimensions are halved.
❓ visualization
advanced
3:00remaining
Visualizing a 2D sine wave as an image
Which option shows the correct code to generate and display a 2D sine wave image pattern using matplotlib?
Signal Processing
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 4 * np.pi, 100)
y = np.linspace(0, 4 * np.pi, 100)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) + np.sin(Y)
plt.imshow(Z, cmap='gray')
plt.colorbar()
plt.show()
A
Z = np.cos(X) + np.cos(Y)
plt.imshow(Z, cmap='jet')
B
Z = np.sin(X * Y)
plt.imshow(Z, cmap='gray')
C
Z = np.sin(X) * np.sin(Y)
plt.imshow(Z, cmap='hot')
D
Z = np.sin(X) + np.sin(Y)
plt.imshow(Z, cmap='gray')
Attempts:
2 left
💡 Hint
The sum of sine waves in X and Y directions creates a grid pattern.
🔧 Debug
advanced
2:00remaining
Identify the error in 2D convolution code
What error does the following code raise when trying to convolve a 2D image with a kernel using scipy.signal.convolve2d?
Signal Processing
import numpy as np
from scipy.signal import convolve2d
image = np.array([[1, 2], [3, 4]])
kernel = np.array([1, 0])
result = convolve2d(image, kernel)
print(result)
AValueError: kernel must be 2D
BTypeError: 'int' object is not iterable
CValueError: object too deep for desired array
DNo error, outputs a 2D array
Attempts:
2 left
💡 Hint
Check the shape of the kernel array passed to convolve2d.
🚀 Application
expert
2:30remaining
Calculate the energy of a 2D signal image
Given a 2D NumPy array representing an image signal, which option correctly calculates the total energy (sum of squared pixel values)?
Signal Processing
import numpy as np
image = np.array([[1, 2], [3, 4]])
Anp.sqrt(np.sum(image))
Bnp.sum(image ** 2)
Cnp.sum(np.abs(image))
Dnp.mean(image ** 2)
Attempts:
2 left
💡 Hint
Energy is the sum of squares of all pixel values.

Practice

(1/5)
1. What does it mean to say an image is a 2D signal?
easy
A. It is a sound wave recorded over time.
B. It is made of pixels arranged in rows and columns.
C. It is a list of numbers without any order.
D. It is a single value representing brightness.

Solution

  1. Step 1: Understand the structure of an image

    An image consists of pixels arranged in a grid with rows and columns.
  2. Step 2: Define 2D signal in context

    A 2D signal means data varies in two dimensions, matching the rows and columns of pixels.
  3. Final Answer:

    It is made of pixels arranged in rows and columns. -> Option B
  4. Quick Check:

    Image = 2D pixel grid [OK]
Hint: Remember: images have width and height as 2D grids [OK]
Common Mistakes:
  • Confusing image with 1D signals like audio
  • Thinking image is just one brightness value
  • Ignoring the grid arrangement of pixels
2. Which of the following is the correct way to represent a grayscale image in Python using a 2D list?
easy
A. image = (0, 255, 128, 64)
B. image = [0, 255, 128, 64]
C. image = {0:255, 1:128}
D. image = [[0, 255], [128, 64]]

Solution

  1. Step 1: Identify 2D structure for image

    A grayscale image is a 2D array where each element is a pixel value.
  2. Step 2: Check each option's structure

    image = [[0, 255], [128, 64]] uses a list of lists, representing rows and columns correctly.
  3. Final Answer:

    image = [[0, 255], [128, 64]] -> Option D
  4. Quick Check:

    2D list = correct image format [OK]
Hint: Use nested lists for rows and columns [OK]
Common Mistakes:
  • Using 1D list instead of 2D
  • Using dictionary which is unordered
  • Using tuple which is immutable but not 2D
3. Given the Python code:
image = [[10, 20], [30, 40]]
brightness_sum = sum(sum(row) for row in image)
print(brightness_sum)

What is the output?
medium
A. 100
B. 40
C. None
D. TypeError

Solution

  1. Step 1: Calculate sum of each row

    First row sum: 10 + 20 = 30; second row sum: 30 + 40 = 70.
  2. Step 2: Sum the row sums

    Total sum = 30 + 70 = 100.
  3. Final Answer:

    100 -> Option A
  4. Quick Check:

    Sum of all pixels = 100 [OK]
Hint: Sum rows first, then sum those results [OK]
Common Mistakes:
  • Summing only one row
  • Confusing nested sums
  • Expecting print to show None
4. Find the error in this code snippet that tries to access the pixel at row 1, column 2:
image = [[5, 10, 15], [20, 25, 30]]
pixel = image[1][2]
print(pixel)
medium
A. IndexError because column 2 does not exist
B. SyntaxError due to wrong brackets
C. No error; output is 30
D. TypeError because image is not a list

Solution

  1. Step 1: Check image dimensions

    Image has 2 rows and 3 columns (indices 0 to 2).
  2. Step 2: Access pixel at row 1, column 2

    image[1][2] accesses second row, third column, which is 30.
  3. Final Answer:

    No error; output is 30 -> Option C
  4. Quick Check:

    Valid index access = 30 [OK]
Hint: Remember indexing starts at 0 in Python [OK]
Common Mistakes:
  • Thinking index 2 is out of range
  • Confusing row and column order
  • Assuming syntax error with brackets
5. You want to increase the brightness of a grayscale image by adding 50 to each pixel value without exceeding 255. Which Python code correctly does this for a 2D list image?
hard
A.
bright_image = [[min(pixel + 50, 255) for pixel in row] for row in image]
B.
bright_image = [pixel + 50 if pixel < 255 else 255 for pixel in image]
C.
bright_image = [[pixel + 50 for pixel in row] for row in image]
D.
bright_image = [[max(pixel + 50, 255) for pixel in row] for row in image]

Solution

  1. Step 1: Understand brightness increase with limit

    We add 50 to each pixel but cap values at 255 to avoid overflow.
  2. Step 2: Analyze each option

    bright_image = [[min(pixel + 50, 255) for pixel in row] for row in image]
    uses min(pixel + 50, 255) to cap values correctly.
    bright_image = [pixel + 50 if pixel < 255 else 255 for pixel in image]
    is wrong because it treats image as 1D.
    bright_image = [[pixel + 50 for pixel in row] for row in image]
    can exceed 255.
    bright_image = [[max(pixel + 50, 255) for pixel in row] for row in image]
    uses max which increases values beyond 255.
  3. Final Answer:

    bright_image = [[min(pixel + 50, 255) for pixel in row] for row in image] -> Option A
  4. Quick Check:

    Use min to cap brightness at 255 [OK]
Hint: Use min(pixel+50, 255) to avoid overflow [OK]
Common Mistakes:
  • Not capping pixel values at 255
  • Treating 2D image as 1D list
  • Using max instead of min for capping
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard