def to_grayscale(img, num_output_channels=<NUM_LIT:1>):
if not _is_pil_image(img):<EOL><INDENT>raise TypeError('<STR_LIT>'.format(type(img)))<EOL><DEDENT>if num_output_channels == <NUM_LIT:1>:<EOL><INDENT>img = img.convert('<STR_LIT:L>')<EOL><DEDENT>elif num_output_channels == <NUM_LIT:3>:<EOL><INDENT>img = img.convert('<STR_LIT:L>')<EOL>np_img = np.array(img, dtype=np.uint8)<EOL>np_img = np.dstack([np_img, np_img, np_img])<EOL>img = Image.fromarray(np_img, '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return img<EOL>
Convert image to grayscale version of image.

    Args:
        img (PIL Image): Image to be converted to grayscale.

    Returns:
        PIL Image: Grayscale version of the image.
            if num_output_channels = 1 : returned image is single channel

            if num_output_channels = 3 : returned image is 3 channel with r = g = b