@staticmethod
def _read_image_and_resize(img_entry: Union[(str, 'numpy.array')], img_width: int, img_height: int, should_resize: bool, num_channels: int, resize_method: str, user_specified_num_channels: int):
    "\n        :param img_entry Union[str, 'numpy.array']: if str file path to the\n                image else numpy.array of the image itself\n        :param img_width: expected width of the image\n        :param img_height: expected height of the image\n        :param should_resize: Should the image be resized?\n        :param resize_method: type of resizing method\n        :param num_channels: expected number of channels in the first image\n        :param user_specified_num_channels: did the user specify num channels?\n        :return: image object\n\n        Helper method to read and resize an image according to model defn.\n        If the user doesn't specify a number of channels, we use the first image\n        in the dataset as the source of truth. If any image in the dataset\n        doesn't have the same number of channels as the first image,\n        raise an exception.\n\n        If the user specifies a number of channels, we try to convert all the\n        images to the specifications by dropping channels/padding 0 channels\n        "
    img = read_image(img_entry)
    img_num_channels = num_channels_in_image(img)
    if (img_num_channels == 1):
        img = img.reshape((img.shape[0], img.shape[1], 1))
    if should_resize:
        img = resize_image(img, (img_height, img_width), resize_method)
    if (user_specified_num_channels is True):
        if ((num_channels == 1) and ((img_num_channels == 3) or (img_num_channels == 4))):
            img = greyscale(img)
            img_num_channels = 1
        img_padded = np.zeros((img_height, img_width, num_channels), dtype=np.uint8)
        min_num_channels = min(num_channels, img_num_channels)
        img_padded[:, :, :min_num_channels] = img[:, :, :min_num_channels]
        img = img_padded
        if (img_num_channels != num_channels):
            logger.warning('Image has {0} channels, where as {1} channels are expected. Dropping/adding channels with 0s as appropriate'.format(img_num_channels, num_channels))
    elif (img_num_channels != num_channels):
        raise ValueError('Image has {0} channels, unlike the first image, which has {1} channels. Make sure all the images have the same number of channels or use the num_channels property in image preprocessing'.format(img_num_channels, num_channels))
    if ((img.shape[0] != img_height) or (img.shape[1] != img_width)):
        raise ValueError('Images are not of the same size. Expected size is {0}, current image size is {1}.Images are expected to be all of the same size or explicit image width and height are expected to be provided. Additional information: https://ludwig-ai.github.io/ludwig-docs/user_guide/#image-features-preprocessing'.format([img_height, img_width, num_channels], img.shape))
    return img
:param img_entry Union[str, 'numpy.array']: if str file path to the
        image else numpy.array of the image itself
:param img_width: expected width of the image
:param img_height: expected height of the image
:param should_resize: Should the image be resized?
:param resize_method: type of resizing method
:param num_channels: expected number of channels in the first image
:param user_specified_num_channels: did the user specify num channels?
:return: image object

Helper method to read and resize an image according to model defn.
If the user doesn't specify a number of channels, we use the first image
in the dataset as the source of truth. If any image in the dataset
doesn't have the same number of channels as the first image,
raise an exception.

If the user specifies a number of channels, we try to convert all the
images to the specifications by dropping channels/padding 0 channels
@staticmethod
def _read_image_and_resize(img_entry: Union[(str, 'numpy.array')], img_width: int, img_height: int, should_resize: bool, num_channels: int, resize_method: str, user_specified_num_channels: int):
    "\n        :param img_entry Union[str, 'numpy.array']: if str file path to the\n                image else numpy.array of the image itself\n        :param img_width: expected width of the image\n        :param img_height: expected height of the image\n        :param should_resize: Should the image be resized?\n        :param resize_method: type of resizing method\n        :param num_channels: expected number of channels in the first image\n        :param user_specified_num_channels: did the user specify num channels?\n        :return: image object\n\n        Helper method to read and resize an image according to model defn.\n        If the user doesn't specify a number of channels, we use the first image\n        in the dataset as the source of truth. If any image in the dataset\n        doesn't have the same number of channels as the first image,\n        raise an exception.\n\n        If the user specifies a number of channels, we try to convert all the\n        images to the specifications by dropping channels/padding 0 channels\n        "
    img = read_image(img_entry)
    img_num_channels = num_channels_in_image(img)
    if (img_num_channels == 1):
        img = img.reshape((img.shape[0], img.shape[1], 1))
    if should_resize:
        img = resize_image(img, (img_height, img_width), resize_method)
    if (user_specified_num_channels is True):
        if ((num_channels == 1) and ((img_num_channels == 3) or (img_num_channels == 4))):
            img = greyscale(img)
            img_num_channels = 1
        img_padded = np.zeros((img_height, img_width, num_channels), dtype=np.uint8)
        min_num_channels = min(num_channels, img_num_channels)
        img_padded[:, :, :min_num_channels] = img[:, :, :min_num_channels]
        img = img_padded
        if (img_num_channels != num_channels):
            logger.warning('Image has {0} channels, where as {1} channels are expected. Dropping/adding channels with 0s as appropriate'.format(img_num_channels, num_channels))
    elif (img_num_channels != num_channels):
        raise ValueError('Image has {0} channels, unlike the first image, which has {1} channels. Make sure all the images have the same number of channels or use the num_channels property in image preprocessing'.format(img_num_channels, num_channels))
    if ((img.shape[0] != img_height) or (img.shape[1] != img_width)):
        raise ValueError('Images are not of the same size. Expected size is {0}, current image size is {1}.Images are expected to be all of the same size or explicit image width and height are expected to be provided. Additional information: https://ludwig-ai.github.io/ludwig-docs/user_guide/#image-features-preprocessing'.format([img_height, img_width, num_channels], img.shape))
    return img