Milestone 3 of 8
Select one channel without losing axis meaning
Select a valid channel while keeping a length-one channel axis and rejecting boolean, negative, and out-of-range indexes.
Selecting a channel is not the same as dropping an axis. Keep the result's shape explicit so later operations do not have to guess what a dimension means.
Goal
Select one valid channel from a grayscale or RGB array and return a
(height, width, 1) uint8 array without changing the source.
Operation
Implement:
select_channel(image, channel_index)
Require one non-boolean integer in range. For RGB, index 0 is the first declared channel and index 2 is the third. For grayscale, the only valid index is 0. Do not infer channel names from colors or reorder the source channels.
Deliverables
Extend src/operations.py with channel selection and save exact pixel tables
for one grayscale fixture and each channel of one RGB fixture. Record source
and result shapes and the selected index.
Checks
Check every valid RGB index, the grayscale index, a one-pixel image, and a
pattern where channels contain visibly different values. Reject negative,
out-of-range, non-integer, and boolean indexes. Check that the result has a
length-one channel axis, retains height and width, uses uint8, and is
independent of the source.
Change a result pixel and verify the source channel is unchanged. Confirm that the operation does not alter the source's channel order or metadata.
Workspace
Keep channel selection in src/operations.py. Do not add brightness, masks,
or transformations that interpret a channel semantically.
Hints
HintShape carries meaning
(height, width) could be a grayscale
array or a two-dimensional slice of an RGB array. (height, width, 1) states
that one channel remains.HintCheck the channel before copying
Review
Pick one RGB pixel and follow its selected channel into the result. What does the result shape tell the next operation? Why should a boolean index be rejected even though NumPy can interpret it?
How to check your work
Checks compare selected pixels, shapes, dtype, index validation, and memory independence with the fixtures. Selection keeps values; it does not classify the image.