Skip to main content

AP CSA FRQ Guide

2012 FRQ 4: GrayImage

Count white pixels in a grayscale image and process pixels by subtracting values from diagonal positions when they exist.

2D Array Image Processing22 minute target2D arraysconstantsmutationbounds

Skills Tested

What this FRQ is really practicing

2D arraysconstantsmutationbounds

Review these topics before attempting the problem.

Starter Approach

How to begin with your own plan

  1. 1Count entries equal to the WHITE constant without changing the image.
  2. 2For eligible positions, subtract the down-two/right-two value and clamp to BLACK.

Attempt the problem before opening the solution.

Common Mistakes

Mistakes to watch for while writing

Changing image values while counting white pixels.
Processing cells without a row + 2, col + 2 neighbor.
Letting pixel values become negative.

Self Check

Review questions before you submit

Traverses the 2D pixel array.

Use row and column loops.

Compares pixels to WHITE.

Use the class constant instead of a magic number when possible.

Uses the row + 2, col + 2 offset for processing.

Only process cells that have that diagonal neighbor.

Clamps negative results to BLACK.

Processed pixel values cannot go below BLACK.

Practice Links

Where to go next