pyanime4k 3.0.0__cp310-cp310-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyanime4k might be problematic. Click here for more details.
- pyanime4k/__init__.py +4 -0
- pyanime4k/image_io.py +9 -0
- pyanime4k/info.py +13 -0
- pyanime4k/processor.py +27 -0
- pyanime4k/pyac/__init__.py +1 -0
- pyanime4k/pyac/pyac.cp310-win_amd64.pyd +0 -0
- pyanime4k/upscale.py +29 -0
- pyanime4k-3.0.0.dist-info/METADATA +116 -0
- pyanime4k-3.0.0.dist-info/RECORD +12 -0
- pyanime4k-3.0.0.dist-info/WHEEL +5 -0
- pyanime4k-3.0.0.dist-info/licenses/LICENSE +21 -0
- pyanime4k-3.0.0.dist-info/top_level.txt +1 -0
pyanime4k/__init__.py
ADDED
pyanime4k/image_io.py
ADDED
pyanime4k/info.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from . import pyac
|
|
2
|
+
|
|
3
|
+
def print_model_list():
|
|
4
|
+
for name, description in zip(pyac.specs.ModelNameList, pyac.specs.ModelDescriptionList):
|
|
5
|
+
print(f"{name}\t\t{description}")
|
|
6
|
+
|
|
7
|
+
def print_processor_list():
|
|
8
|
+
for name, description in zip(pyac.specs.ProcessorNameList, pyac.specs.ProcessorDescriptionList):
|
|
9
|
+
print(f"{name}\t\t{description}")
|
|
10
|
+
|
|
11
|
+
def print_device_list():
|
|
12
|
+
for info in pyac.core.Processor.InfoList:
|
|
13
|
+
print(info, end="")
|
pyanime4k/processor.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import numpy
|
|
2
|
+
|
|
3
|
+
from . import pyac
|
|
4
|
+
|
|
5
|
+
class Processor:
|
|
6
|
+
def __init__(self, processor_name: str = "cpu", device_id:int = 0, model_name: str = "acnet-hdn0"):
|
|
7
|
+
self.processor_name = processor_name.lower()
|
|
8
|
+
if self.processor_name == "opencl" :
|
|
9
|
+
processor_type = pyac.core.Processor.OpenCL
|
|
10
|
+
if self.processor_name == "cuda":
|
|
11
|
+
processor_type = pyac.core.Processor.CUDA
|
|
12
|
+
else:
|
|
13
|
+
self.processor_name = "cpu"
|
|
14
|
+
processor_type = pyac.core.Processor.CPU
|
|
15
|
+
|
|
16
|
+
self.processor = pyac.core.Processor(processor_type = processor_type, device = device_id, model = model_name)
|
|
17
|
+
if not self.processor.ok():
|
|
18
|
+
raise RuntimeError(self.processor.error())
|
|
19
|
+
|
|
20
|
+
def __call__(self, src: numpy.ndarray, factor: float = 2.0) -> numpy.ndarray:
|
|
21
|
+
dst = self.processor.process(src = src, factor = factor)
|
|
22
|
+
if not self.processor.ok():
|
|
23
|
+
raise RuntimeError(self.processor.error())
|
|
24
|
+
return dst
|
|
25
|
+
|
|
26
|
+
def __str__(self):
|
|
27
|
+
return f"{self.processor_nam}: {self.processor.name()}"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .pyac import *
|
|
Binary file
|
pyanime4k/upscale.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from itertools import zip_longest, islice
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from .image_io import imread, imwrite
|
|
5
|
+
from .processor import Processor
|
|
6
|
+
|
|
7
|
+
def upscale_images(
|
|
8
|
+
inputs: list,
|
|
9
|
+
outputs: list = [],
|
|
10
|
+
output_suffix: str = "_output",
|
|
11
|
+
factor: float = 2.0,
|
|
12
|
+
processor_name: str = "cpu",
|
|
13
|
+
device_id:int = 0,
|
|
14
|
+
model_name: str = "acnet-hdn0"
|
|
15
|
+
):
|
|
16
|
+
if isinstance(inputs, str):
|
|
17
|
+
inputs = [inputs]
|
|
18
|
+
|
|
19
|
+
processor = Processor(processor_name, device_id, model_name)
|
|
20
|
+
|
|
21
|
+
for input, output in islice(zip_longest(inputs, outputs, fillvalue=None), len(inputs)):
|
|
22
|
+
if output is None:
|
|
23
|
+
input_path = Path(input)
|
|
24
|
+
output = str(input_path.with_stem(input_path.stem + output_suffix))
|
|
25
|
+
|
|
26
|
+
src = imread(input)
|
|
27
|
+
dst = processor(src, factor)
|
|
28
|
+
if not imwrite(output, dst):
|
|
29
|
+
raise IOError(f"Failed to save image to {output}")
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyanime4k
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
License: MIT
|
|
5
|
+
Requires-Python: >=3.8
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Dynamic: license-file
|
|
9
|
+
Dynamic: requires-python
|
|
10
|
+
|
|
11
|
+
# PyAnime4K
|
|
12
|
+
|
|
13
|
+
PyAnime4K is a high performance anime image upscaler based on [Anime4KCPP](https://github.com/TianZerL/Anime4KCPP).
|
|
14
|
+
|
|
15
|
+
# Install
|
|
16
|
+
PyAnime4K can be installed easily through pip.
|
|
17
|
+
```shell
|
|
18
|
+
pip install pyanime4k
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
You can also build the wheel by yourself.
|
|
22
|
+
```shell
|
|
23
|
+
# sudo apt install ocl-icd-opencl-dev cmake build-essential
|
|
24
|
+
get clone https://github.com/TianZerL/pyanime4k.git
|
|
25
|
+
cd pyanime4k
|
|
26
|
+
python setup.py bdist_wheel
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
# Usages
|
|
30
|
+
## Printing Info
|
|
31
|
+
```python
|
|
32
|
+
import pyanime4k
|
|
33
|
+
|
|
34
|
+
# Print supported model
|
|
35
|
+
pyanime4k.print_model_list()
|
|
36
|
+
|
|
37
|
+
# Print supported processor
|
|
38
|
+
pyanime4k.print_processor_list()
|
|
39
|
+
|
|
40
|
+
# Print supported devices for image processing
|
|
41
|
+
pyanime4k.print_device_list()
|
|
42
|
+
```
|
|
43
|
+
## Upscaling Images
|
|
44
|
+
```python
|
|
45
|
+
import pyanime4k
|
|
46
|
+
|
|
47
|
+
# with OpenCL acceleration, if possible
|
|
48
|
+
processor_name = "opencl"
|
|
49
|
+
|
|
50
|
+
# upscale a single image
|
|
51
|
+
pyanime4k.upscale_images("image1.png", processor_name = processor_name)
|
|
52
|
+
|
|
53
|
+
# upscale a list of images
|
|
54
|
+
pyanime4k.upscale_images(["image1.png", "image2.png"], processor_name = processor_name)
|
|
55
|
+
```
|
|
56
|
+
## Manual Upscaling
|
|
57
|
+
```python
|
|
58
|
+
import pyanime4k
|
|
59
|
+
|
|
60
|
+
# Create a processor
|
|
61
|
+
processor = pyanime4k.Processor(
|
|
62
|
+
processor_name="cpu",
|
|
63
|
+
device_id=0,
|
|
64
|
+
model_name="acnet-hdn0"
|
|
65
|
+
)
|
|
66
|
+
# Print processor info
|
|
67
|
+
print(processor)
|
|
68
|
+
# Read an image
|
|
69
|
+
src = pyanime4k.imread("image1.png")
|
|
70
|
+
# Process it
|
|
71
|
+
dst = processor(src=src, factor=2.0)
|
|
72
|
+
# Write to disk
|
|
73
|
+
pyanime4k.imwrite("image1_outout.png", dst)
|
|
74
|
+
```
|
|
75
|
+
## OpenCV
|
|
76
|
+
``` Python
|
|
77
|
+
import cv2, pyanime4k
|
|
78
|
+
|
|
79
|
+
img = cv2.imread("image.png")
|
|
80
|
+
|
|
81
|
+
processor = pyanime4k.Processor(
|
|
82
|
+
processor_name="cpu",
|
|
83
|
+
device_id=0,
|
|
84
|
+
model_name="acnet-hdn0"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
# opencv load image as BGR, but we need an RGB image
|
|
88
|
+
src = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
|
89
|
+
|
|
90
|
+
dst = processor(src)
|
|
91
|
+
|
|
92
|
+
img = cv2.cvtColor(dst, cv2.COLOR_RGB2BGR)
|
|
93
|
+
|
|
94
|
+
cv2.imshow("pyanime4k", img)
|
|
95
|
+
cv2.waitKey()
|
|
96
|
+
```
|
|
97
|
+
## Pillow
|
|
98
|
+
```python
|
|
99
|
+
from PIL import Image
|
|
100
|
+
import numpy, pyanime4k
|
|
101
|
+
|
|
102
|
+
img = Image.open("D:/temp/p1.png")
|
|
103
|
+
|
|
104
|
+
processor = pyanime4k.Processor(
|
|
105
|
+
processor_name="cpu",
|
|
106
|
+
device_id=0,
|
|
107
|
+
model_name="acnet-hdn0"
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
# We need a numpy array
|
|
111
|
+
src = numpy.asarray(img)
|
|
112
|
+
dst = processor(src)
|
|
113
|
+
img = Image.fromarray(dst)
|
|
114
|
+
|
|
115
|
+
img.show()
|
|
116
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
pyanime4k/__init__.py,sha256=a0P3gyxYbvjRm8m3suGuv_VK4wXoMeaqIEcOp7jI3jg,96
|
|
2
|
+
pyanime4k/image_io.py,sha256=SRADSi197gcWcMPPljh5-tV-qBXcl-drRmWua2ff1Vg,258
|
|
3
|
+
pyanime4k/info.py,sha256=nkNPTJM99bnWY-pG7UsfD2Ce_efB3FN-HFxfC6-MM9k,464
|
|
4
|
+
pyanime4k/processor.py,sha256=xLASpJaRnCGA96F0N4uxSmDqLn3CDkqJzUc72tLCMPc,1099
|
|
5
|
+
pyanime4k/upscale.py,sha256=c8tYsFHaH-ujdCXc0WRLdeZZT643TzCIqYvV7b_XFnc,913
|
|
6
|
+
pyanime4k/pyac/__init__.py,sha256=zPAeBR1mdz2q_I3Ruk5uaIptB7DjT8P9G20oGEKFJ1c,21
|
|
7
|
+
pyanime4k/pyac/pyac.cp310-win_amd64.pyd,sha256=p9Mh87OgvlPYZrFR2tkKDrhUpZzANjJB5O3jNdh9dH0,1595904
|
|
8
|
+
pyanime4k-3.0.0.dist-info/licenses/LICENSE,sha256=Y1LqP77JBqrXWO4jJ_2bg6N-hHoU_JGgxQnYqxw1f3U,1085
|
|
9
|
+
pyanime4k-3.0.0.dist-info/METADATA,sha256=arpgdx_uDW3iDXpbGXse_Lxw0ypOu9z4EDK0KDJV29Q,2429
|
|
10
|
+
pyanime4k-3.0.0.dist-info/WHEEL,sha256=grXnj_hjz9AcJWnDGoMAyy0X5GgALMAtIvNbRMBzgmk,96
|
|
11
|
+
pyanime4k-3.0.0.dist-info/top_level.txt,sha256=fPnXpjwQ6pB0I-OoT611DbqcY50uFsaMw4BdYnAmVq0,10
|
|
12
|
+
pyanime4k-3.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 TianZer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pyanime4k
|