[WIP] texture and content blendig with blend_modes module
This commit is contained in:
parent
6dbe3b6fc9
commit
f2af040c5b
16
poetry.lock
generated
16
poetry.lock
generated
@ -217,6 +217,17 @@ webencodings = "*"
|
||||
css = ["tinycss2 (>=1.1.0,<1.2)"]
|
||||
dev = ["Sphinx (==4.3.2)", "black (==22.3.0)", "build (==0.8.0)", "flake8 (==4.0.1)", "hashin (==0.17.0)", "mypy (==0.961)", "pip-tools (==6.6.2)", "pytest (==7.1.2)", "tox (==3.25.0)", "twine (==4.0.1)", "wheel (==0.37.1)"]
|
||||
|
||||
[[package]]
|
||||
name = "blend-modes"
|
||||
version = "2.1.0"
|
||||
description = "Image processing blend modes"
|
||||
category = "dev"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
|
||||
[package.dependencies]
|
||||
numpy = "*"
|
||||
|
||||
[[package]]
|
||||
name = "celery"
|
||||
version = "5.2.7"
|
||||
@ -2640,7 +2651,7 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools"
|
||||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "~3.8"
|
||||
content-hash = "5a1dbdbda2c93653a6c93bf53a8f63a8ecddde7c8fe0a819f432578e67c8d476"
|
||||
content-hash = "3e371ca37733966c45c92ed64582d89336ee7875950e4487095d15d75c943fdd"
|
||||
|
||||
[metadata.files]
|
||||
aiohttp = [
|
||||
@ -2814,6 +2825,9 @@ bleach = [
|
||||
{file = "bleach-5.0.1-py3-none-any.whl", hash = "sha256:085f7f33c15bd408dd9b17a4ad77c577db66d76203e5984b1bd59baeee948b2a"},
|
||||
{file = "bleach-5.0.1.tar.gz", hash = "sha256:0d03255c47eb9bd2f26aa9bb7f2107732e7e8fe195ca2f64709fcf3b0a4a085c"},
|
||||
]
|
||||
blend-modes = [
|
||||
{file = "blend_modes-2.1.0.tar.gz", hash = "sha256:0a3145e4792e005764b9663f5ce899d30f7c24f4bcff00428907d03dbe068f37"},
|
||||
]
|
||||
celery = [
|
||||
{file = "celery-5.2.7-py3-none-any.whl", hash = "sha256:138420c020cd58d6707e6257b6beda91fd39af7afde5d36c6334d175302c0e14"},
|
||||
{file = "celery-5.2.7.tar.gz", hash = "sha256:fafbd82934d30f8a004f81e8f7a062e31413a23d444be8ee3326553915958c6d"},
|
||||
|
||||
@ -43,6 +43,7 @@ faker = "^16.4.0"
|
||||
pandas = "^1.5.2"
|
||||
pytablewriter = "^0.64.2"
|
||||
dataframe-image = "^0.1.5"
|
||||
blend-modes = "^2.1.0"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
|
||||
59
test/fixtures/page_generation/page.py
vendored
59
test/fixtures/page_generation/page.py
vendored
@ -13,11 +13,12 @@ from pathlib import Path
|
||||
from typing import Tuple, Iterable, List
|
||||
|
||||
import albumentations as A
|
||||
import blend_modes
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import pytest
|
||||
from PIL import Image, ImageOps, ImageFont, ImageDraw
|
||||
from PIL import Image, ImageOps, ImageFont, ImageDraw, ImageEnhance
|
||||
from PIL.Image import Transpose
|
||||
from faker import Faker
|
||||
from loguru import logger
|
||||
@ -45,8 +46,8 @@ random_seed = random.randint(0, 2**32 - 1)
|
||||
# random_seed = 2508340737
|
||||
|
||||
|
||||
random_seed = 2212357755
|
||||
# random_seed = 3400335399
|
||||
# random_seed = 2212357755
|
||||
random_seed = 3400335399
|
||||
|
||||
rnd = random.Random(random_seed)
|
||||
logger.info(f"Random seed: {random_seed}")
|
||||
@ -241,8 +242,8 @@ def texture_name(request):
|
||||
@pytest.fixture(
|
||||
params=[
|
||||
# 30,
|
||||
# 70,
|
||||
150,
|
||||
70,
|
||||
# 150,
|
||||
]
|
||||
)
|
||||
def color_intensity(request):
|
||||
@ -434,7 +435,12 @@ def compute_pasting_coordinates(smaller: Image, larger: Image.Image):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def page_with_opaque_content(blank_page, tinted_blank_page, texture, texture_fn) -> np.ndarray:
|
||||
def page_with_opaque_content(
|
||||
blank_page,
|
||||
tinted_blank_page,
|
||||
texture,
|
||||
texture_fn,
|
||||
) -> Tuple[np.ndarray, Iterable[Rectangle]]:
|
||||
"""Creates a page with content"""
|
||||
page_partitioner = rnd.choice(
|
||||
[
|
||||
@ -474,26 +480,55 @@ def page_with_translucent_content(
|
||||
texture = random_flip(texture)
|
||||
texture = texture_fn(texture)
|
||||
|
||||
page_content = multiply_alpha_where_alpha_channel_is_nonzero(page_content, factor=0.6)
|
||||
page = superimpose_texture_with_transparency(texture, page_content, crop_to_content=False)
|
||||
########## A
|
||||
# page_content = multiply_alpha_where_alpha_channel_is_nonzero(page_content, factor=0.6)
|
||||
# page = superimpose_texture_with_transparency(texture, page_content, crop_to_content=False)
|
||||
########## B
|
||||
# texture.putalpha(255)
|
||||
# # texture.show()
|
||||
# page_content.show()
|
||||
# page = blend(*map(np.array, (page_content, texture)))
|
||||
########## C
|
||||
texture.putalpha(255)
|
||||
page_content.putalpha(255)
|
||||
factor = 1.2
|
||||
enhancer = ImageEnhance.Contrast(texture)
|
||||
texture = enhancer.enhance(factor)
|
||||
|
||||
page = blend_modes.multiply(
|
||||
*map(
|
||||
to_array,
|
||||
(
|
||||
page_content,
|
||||
texture,
|
||||
),
|
||||
),
|
||||
opacity=1,
|
||||
).astype(np.uint8)
|
||||
##########
|
||||
|
||||
return page, boxes
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def page_with_content(
|
||||
# page_with_translucent_content,
|
||||
page_with_opaque_content,
|
||||
page_with_translucent_content,
|
||||
# page_with_opaque_content,
|
||||
) -> np.ndarray:
|
||||
|
||||
# page, boxes = page_with_translucent_content
|
||||
page, boxes = page_with_opaque_content
|
||||
page, boxes = page_with_translucent_content
|
||||
# page, boxes = page_with_opaque_content
|
||||
|
||||
draw_boxes(page, boxes)
|
||||
|
||||
return page
|
||||
|
||||
|
||||
def to_array(image: Image) -> np.ndarray:
|
||||
"""Converts a PIL image to a numpy array."""
|
||||
return np.array(image).astype(np.float32)
|
||||
|
||||
|
||||
def provide_image_format(required_format):
|
||||
def inner(fn):
|
||||
def inner(image, *args, **kwargs):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user