-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ArchieMeng <[email protected]>
- Loading branch information
1 parent
8bd67e5
commit 167fee3
Showing
2 changed files
with
41 additions
and
10 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
from PIL import Image | ||
from srmd_ncnn_vulkan_python import Srmd | ||
import time | ||
|
||
start_time = time.time() | ||
input_image = Image.open("input.png") | ||
upscaler = Srmd(0) | ||
output_image = upscaler.process(input_image) | ||
output_image.save("output.png") | ||
print(f"Elapsed time: {time.time() - start_time} secs") | ||
import logging | ||
from pathlib import Path | ||
|
||
from PIL import Image, ImageChops, ImageStat | ||
from srmd_ncnn_vulkan_python import SRMD | ||
|
||
tests_path = Path(__file__).parent | ||
images_path = ( | ||
tests_path.parent / "srmd_ncnn_vulkan_python" / "srmd-ncnn-vulkan" / "images" | ||
) | ||
gpu_id = 0 | ||
|
||
|
||
def _calc_image_diff(image0: Image.Image, image1: Image.Image) -> float: | ||
""" | ||
calculate the percentage of differences between two images | ||
:param image0 Image.Image: the first frame | ||
:param image1 Image.Image: the second frame | ||
:rtype float: the percent difference between the two images | ||
""" | ||
difference = ImageChops.difference(image0, image1) | ||
difference_stat = ImageStat.Stat(difference) | ||
percent_diff = sum(difference_stat.mean) / (len(difference_stat.mean) * 255) * 100 | ||
return percent_diff | ||
|
||
|
||
def test_default(): | ||
input_image = Image.open(images_path / "0.jpg") | ||
upscaler = SRMD(gpu_id) | ||
output_image = upscaler.process(input_image) | ||
|
||
test_image = Image.open(tests_path / "0_default.png") | ||
percent_diff = _calc_image_diff(test_image, output_image) | ||
logging.getLogger().info(f"%diff: {percent_diff}") | ||
|
||
test_image.close() | ||
output_image.close() | ||
input_image.close() | ||
|
||
assert percent_diff < 0.5 |