mirror of
https://github.com/283375/arcaea-offline-ocr.git
synced 2025-04-11 09:30:17 +00:00
refactor!: remove utils.convert_to_srgb
This commit is contained in:
parent
4fd31b1e9b
commit
3400df2d52
@ -1,10 +1,8 @@
|
||||
import io
|
||||
from collections.abc import Iterable
|
||||
from typing import Callable, TypeVar, Union, overload
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
from PIL import Image, ImageCms
|
||||
|
||||
from .types import XYWHRect
|
||||
|
||||
@ -46,25 +44,3 @@ def apply_factor(item, factor: float):
|
||||
return item * factor
|
||||
elif isinstance(item, Iterable):
|
||||
return item.__class__([i * factor for i in item])
|
||||
|
||||
|
||||
def convert_to_srgb(pil_img: Image.Image):
|
||||
"""
|
||||
Convert PIL image to sRGB color space (if possible)
|
||||
and save the converted file.
|
||||
|
||||
https://stackoverflow.com/a/65667797/16484891
|
||||
|
||||
CC BY-SA 4.0
|
||||
"""
|
||||
icc = pil_img.info.get("icc_profile", "")
|
||||
icc_conv = ""
|
||||
|
||||
if icc:
|
||||
io_handle = io.BytesIO(icc) # virtual file
|
||||
src_profile = ImageCms.ImageCmsProfile(io_handle)
|
||||
dst_profile = ImageCms.createProfile("sRGB")
|
||||
img_conv = ImageCms.profileToProfile(pil_img, src_profile, dst_profile)
|
||||
icc_conv = img_conv.info.get("icc_profile", "")
|
||||
|
||||
return img_conv if icc != icc_conv else pil_img
|
||||
|
Loading…
x
Reference in New Issue
Block a user