Hue Tint Color Error Converting Tiff To Jpg In Python3 With Pillow
While saving jpg thumbnails from tiff (CMYK) file I'm encountering the following problem: Thumbnail created with color mode conversion from CMYK to RGB gets blue hue: Thumbnai
Solution 1:
The reason why CMYK to RGB got the blue tint is because the conversion used only a very rough formula, probably something like:
red = 1.0 – min (1.0, cyan + black)
green = 1.0 – min (1.0, magenta + black)
blue = 1.0 – min (1.0, yellow + black)
To get the colours you expected you would need to use a proper Colour Management System (CMS), such as LittleCMS. Apparently Pillow is able to work with LCMS but I'm not sure if it's included be default so you would probably need to build Pillow yourself.
Solution 2:
I've finally found the way to convert from CMYK to RGB from within Pillow (PIL) without recurring to external call to ImageMagick.
# first - extract the embedded profile:
tiff_embedded_icc_profile = ImageCms.ImageCmsProfile(io.BytesIO(tiff_img.info.get('icc_profile')))
# second - get the path to desired profile (in my case sRGB)
srgb_profile_path = '/Library/Application Support/Adobe/Color/Profiles/Recommended/sRGB Color Space Profile.icm'# third - perform the conversion (must have LittleCMS installed)
converted_image = ImageCms.profileToProfile(
tiff_img,
inputProfile=tiff_embedded_icc_profile,
outputProfile=srgb_profile_path,
renderingIntent=0,
outputMode='RGB'
)
# finally - save converted image:
converted_image.save(new_name + '.jpg', quality=95, optimize=True)
All colors are preserved.
Post a Comment for "Hue Tint Color Error Converting Tiff To Jpg In Python3 With Pillow"