def fix_img_channels(img, out_nc):
    '\n        fix image channels to the expected number\n    '
    if (img.ndim == 2):
        img = np.tile(np.expand_dims(img, axis=2), (1, 1, 3))
    if ((out_nc == 3) and (img.shape[2] == 4)):
        img = bgra2rgb(img)
    elif (img.shape[2] > out_nc):
        img = img[:, :, :out_nc]
    elif ((img.shape[2] == 3) and (out_nc == 4)):
        img = np.dstack((img, np.full(img.shape[:(- 1)], 255, dtype=np.uint8)))
    return img
fix image channels to the expected number
def fix_img_channels(img, out_nc):
    '\n        \n    '
    if (img.ndim == 2):
        img = np.tile(np.expand_dims(img, axis=2), (1, 1, 3))
    if ((out_nc == 3) and (img.shape[2] == 4)):
        img = bgra2rgb(img)
    elif (img.shape[2] > out_nc):
        img = img[:, :, :out_nc]
    elif ((img.shape[2] == 3) and (out_nc == 4)):
        img = np.dstack((img, np.full(img.shape[:(- 1)], 255, dtype=np.uint8)))
    return img