“Return a mask for each channel that identifies the pixels with intensity above a specified threshold. The mask for channel
𝑖
i will be an array with values of 0 or 1. Assume the image is stored as a numpy array with three channels representing the colors ‘red’, ‘green’, and ‘blue’.” i keep getting mismatched error
if channel == 'red':
mask = (image[:, :, 0] > lightness).astype(int)
elif channel == 'green':
mask = (image[:, :, 1] > lightness).astype(int)
elif channel == 'blue':
mask = (image[:, :, 2] > lightness).astype(int)
else:
raise ValueError("Channel must be 'red', 'green', or 'blue'")
return mask
New contributor
rao abdur rehman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.