Convert an image to RGB if it isn't already RGB or grayscale

def convert_to_rgb(img):
    """
    Convert an image to RGB if it isn't already RGB or grayscale
    """
    if img.mode == 'CMYK' and HAS_PROFILE_TO_PROFILE:
        profile_dir = os.path.join(os.path.dirname(__file__), 'profiles')
        input_profile = os.path.join(profile_dir, "USWebUncoated.icc")
        output_profile = os.path.join(profile_dir, "sRGB_v4_ICC_preference.icc")
        return profileToProfile(img, input_profile, output_profile, outputMode='RGB')
    return img