Fast-SSIM 1.0.0__tar.gz

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.
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.4
2
+ Name: Fast-SSIM
3
+ Version: 1.0.0
4
+ Summary: Fast SSIM and PSNR algorithms for Python. Up to 30x speedup for SSIM and up to 10x for PSNR.
5
+ Author: Tim Lodemann
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/timminator/Fast-SSIM
8
+ Project-URL: documentation, https://github.com/timminator/Fast-SSIM/blob/master/README.md
9
+ Project-URL: Repository, https://github.com/timminator/Fast-SSIM.git
10
+ Project-URL: Issues, https://github.com/timminator/Fast-SSIM/issues
11
+ Keywords: ssim,psnr,image quality,image comparison,image processing
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: numpy
21
+ Dynamic: license-file
22
+
23
+ <p align="center">
24
+ <h1 align="center">Fast-SSIM</h1>
25
+ <p align="center">
26
+ Speed up your SSIM and PSNR calculations!
27
+ <br />
28
+ </p>
29
+ </p>
30
+
31
+ <br>
32
+
33
+ ## ℹ About
34
+
35
+ This fork wraps the Fast-SSIM project in an easy to use package that can be readily installed via PyPI.
36
+ The Fast-SSIM package can accelerate your SSIM and PSNR calculations by up to 30x and 10x respectively.
37
+
38
+ ## Requirements
39
+
40
+ - Python 3.9 or higher
41
+
42
+ ## How to Install
43
+
44
+ ```
45
+ pip install Fast-SSIM
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ The functionalities are explained in the following code snippet that is also provided in this repo:
51
+
52
+ ```python
53
+ import fast_ssim
54
+ from skimage.io import imread
55
+
56
+ img1_path = r"test_images\0.jpg"
57
+ img2_path = r"test_images\1.jpg"
58
+
59
+ # Load the images into NumPy arrays
60
+ img1 = imread(img1_path)
61
+ img2 = imread(img2_path)
62
+
63
+ ssim_score = fast_ssim.ssim(
64
+ img1, img2,
65
+ data_range=255
66
+ )
67
+ psnr_score = fast_ssim.psnr(
68
+ img1, img2,
69
+ data_range=255
70
+ )
71
+
72
+ print(f"SSIM Score: {ssim_score}")
73
+ print(f"PSNR Score: {psnr_score}")
74
+ ```
75
+
76
+ Output:
77
+ ```
78
+ SSIM Score: 0.9886590838432312
79
+ PSNR Score: 31.11587142944336
80
+ ```
81
+
82
+ ## Original author
83
+
84
+ Chen Yu / [@Chen Yu](https://github.com/chinue)
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ Fast_SSIM.egg-info/PKG-INFO
5
+ Fast_SSIM.egg-info/SOURCES.txt
6
+ Fast_SSIM.egg-info/dependency_links.txt
7
+ Fast_SSIM.egg-info/requires.txt
8
+ Fast_SSIM.egg-info/top_level.txt
9
+ fast_ssim/__init__.py
10
+ fast_ssim/_core.py
11
+ fast_ssim/resources/libssim.so
12
+ fast_ssim/resources/ssim.dll
@@ -0,0 +1 @@
1
+ numpy
@@ -0,0 +1 @@
1
+ fast_ssim
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 chinue
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,84 @@
1
+ Metadata-Version: 2.4
2
+ Name: Fast-SSIM
3
+ Version: 1.0.0
4
+ Summary: Fast SSIM and PSNR algorithms for Python. Up to 30x speedup for SSIM and up to 10x for PSNR.
5
+ Author: Tim Lodemann
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/timminator/Fast-SSIM
8
+ Project-URL: documentation, https://github.com/timminator/Fast-SSIM/blob/master/README.md
9
+ Project-URL: Repository, https://github.com/timminator/Fast-SSIM.git
10
+ Project-URL: Issues, https://github.com/timminator/Fast-SSIM/issues
11
+ Keywords: ssim,psnr,image quality,image comparison,image processing
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: numpy
21
+ Dynamic: license-file
22
+
23
+ <p align="center">
24
+ <h1 align="center">Fast-SSIM</h1>
25
+ <p align="center">
26
+ Speed up your SSIM and PSNR calculations!
27
+ <br />
28
+ </p>
29
+ </p>
30
+
31
+ <br>
32
+
33
+ ## ℹ About
34
+
35
+ This fork wraps the Fast-SSIM project in an easy to use package that can be readily installed via PyPI.
36
+ The Fast-SSIM package can accelerate your SSIM and PSNR calculations by up to 30x and 10x respectively.
37
+
38
+ ## Requirements
39
+
40
+ - Python 3.9 or higher
41
+
42
+ ## How to Install
43
+
44
+ ```
45
+ pip install Fast-SSIM
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ The functionalities are explained in the following code snippet that is also provided in this repo:
51
+
52
+ ```python
53
+ import fast_ssim
54
+ from skimage.io import imread
55
+
56
+ img1_path = r"test_images\0.jpg"
57
+ img2_path = r"test_images\1.jpg"
58
+
59
+ # Load the images into NumPy arrays
60
+ img1 = imread(img1_path)
61
+ img2 = imread(img2_path)
62
+
63
+ ssim_score = fast_ssim.ssim(
64
+ img1, img2,
65
+ data_range=255
66
+ )
67
+ psnr_score = fast_ssim.psnr(
68
+ img1, img2,
69
+ data_range=255
70
+ )
71
+
72
+ print(f"SSIM Score: {ssim_score}")
73
+ print(f"PSNR Score: {psnr_score}")
74
+ ```
75
+
76
+ Output:
77
+ ```
78
+ SSIM Score: 0.9886590838432312
79
+ PSNR Score: 31.11587142944336
80
+ ```
81
+
82
+ ## Original author
83
+
84
+ Chen Yu / [@Chen Yu](https://github.com/chinue)
@@ -0,0 +1,62 @@
1
+ <p align="center">
2
+ <h1 align="center">Fast-SSIM</h1>
3
+ <p align="center">
4
+ Speed up your SSIM and PSNR calculations!
5
+ <br />
6
+ </p>
7
+ </p>
8
+
9
+ <br>
10
+
11
+ ## ℹ About
12
+
13
+ This fork wraps the Fast-SSIM project in an easy to use package that can be readily installed via PyPI.
14
+ The Fast-SSIM package can accelerate your SSIM and PSNR calculations by up to 30x and 10x respectively.
15
+
16
+ ## Requirements
17
+
18
+ - Python 3.9 or higher
19
+
20
+ ## How to Install
21
+
22
+ ```
23
+ pip install Fast-SSIM
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ The functionalities are explained in the following code snippet that is also provided in this repo:
29
+
30
+ ```python
31
+ import fast_ssim
32
+ from skimage.io import imread
33
+
34
+ img1_path = r"test_images\0.jpg"
35
+ img2_path = r"test_images\1.jpg"
36
+
37
+ # Load the images into NumPy arrays
38
+ img1 = imread(img1_path)
39
+ img2 = imread(img2_path)
40
+
41
+ ssim_score = fast_ssim.ssim(
42
+ img1, img2,
43
+ data_range=255
44
+ )
45
+ psnr_score = fast_ssim.psnr(
46
+ img1, img2,
47
+ data_range=255
48
+ )
49
+
50
+ print(f"SSIM Score: {ssim_score}")
51
+ print(f"PSNR Score: {psnr_score}")
52
+ ```
53
+
54
+ Output:
55
+ ```
56
+ SSIM Score: 0.9886590838432312
57
+ PSNR Score: 31.11587142944336
58
+ ```
59
+
60
+ ## Original author
61
+
62
+ Chen Yu / [@Chen Yu](https://github.com/chinue)
@@ -0,0 +1 @@
1
+ from ._core import ssim, psnr
@@ -0,0 +1,98 @@
1
+ import numpy as np
2
+ import ctypes
3
+ import os
4
+
5
+ __version__ = '1.0.0'
6
+
7
+ ssim_dll_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'resources')
8
+ ssim_dll_name = 'ssim.dll' if(os.name=='nt') else 'libssim.so'
9
+
10
+
11
+ class SharedLibraryLoadError(ImportError):
12
+ """Raised when the shared SSIM/PSNR library could not be loaded."""
13
+ pass
14
+
15
+
16
+ class Loader:
17
+ dll = None
18
+
19
+ try:
20
+ dll_path = os.path.join(ssim_dll_path, ssim_dll_name)
21
+ if os.path.exists(dll_path):
22
+ dll = np.ctypeslib.load_library(ssim_dll_name, ssim_dll_path)
23
+ else:
24
+ raise SharedLibraryLoadError(f"Shared library not found at: {dll_path}")
25
+ except Exception as e:
26
+ raise SharedLibraryLoadError(f"Failed to load shared library '{ssim_dll_name}': {e}") from e
27
+
28
+ type_dict = {'int':ctypes.c_int, 'float':ctypes.c_float, 'double':ctypes.c_double, 'void':None,
29
+ 'int32':ctypes.c_int32, 'uint32':ctypes.c_uint32, 'int16':ctypes.c_int16, 'uint16':ctypes.c_uint16,
30
+ 'int8':ctypes.c_int8, 'uint8':ctypes.c_uint8, 'byte':ctypes.c_uint8,
31
+ 'char*':ctypes.c_char_p,
32
+ 'float*':np.ctypeslib.ndpointer(dtype='float32', ndim=1, flags='CONTIGUOUS'),
33
+ 'int*':np.ctypeslib.ndpointer(dtype='int32', ndim=1, flags='CONTIGUOUS'),
34
+ 'byte*':np.ctypeslib.ndpointer(dtype='uint8', ndim=1, flags='CONTIGUOUS')}
35
+
36
+ @staticmethod
37
+ def get_function(res_type='float', func_name='PSNR_Byte', arg_types=['Byte*', 'int', 'int', 'int', 'Byte*']):
38
+ func = Loader.dll.__getattr__(func_name)
39
+ func.restype = Loader.type_dict[res_type]
40
+ func.argtypes = [Loader.type_dict[str.lower(x).replace(' ', '')] for x in arg_types]
41
+ return func
42
+
43
+ @staticmethod
44
+ def had_member(name='dll'):
45
+ return (name in Loader.__dict__.keys())
46
+
47
+
48
+ class DLL:
49
+ @staticmethod
50
+ def had_function(name='PSNR_Byte'):
51
+ return (name in DLL.__dict__.keys())
52
+
53
+ if(Loader.had_member('dll')):
54
+ # float PSNR_Byte(Byte* pDataX, Byte* pDataY, int step, int width, int height, int maxVal);
55
+ PSNR_Byte = Loader.get_function('float', 'PSNR_Byte', ['Byte*', 'Byte*', 'int', 'int', 'int', 'int'])
56
+
57
+ # float PSNR_Float(float* pDataX, float* pDataY, int step, int width, int height, double maxVal);
58
+ PSNR_Float = Loader.get_function('float', 'PSNR_Float', ['float*', 'float*', 'int', 'int', 'int', 'double'])
59
+
60
+ # float SSIM_Byte(Byte* pDataX, Byte* pDataY, int step, int width, int height, int win_size, int maxVal);
61
+ SSIM_Byte = Loader.get_function('float', 'SSIM_Byte', ['Byte*', 'Byte*', 'int', 'int', 'int', 'int', 'int'])
62
+
63
+ # float SSIM_Float(float* pDataX, float* pDataY, int step, int width, int height, int win_size, double maxVal);
64
+ SSIM_Float = Loader.get_function('float', 'SSIM_Float', ['float*', 'float*', 'int', 'int', 'int', 'int', 'double'])
65
+
66
+
67
+ def psnr(x, y, data_range=None):
68
+ if x.ndim == 2:
69
+ h, w = x.shape
70
+ c = 1
71
+ elif x.ndim == 3:
72
+ h, w, c = x.shape
73
+ else:
74
+ raise ValueError(f"Unsupported image dimensions: {x.shape}")
75
+
76
+ x = x.astype('float32') if(x.dtype=='float64') else x
77
+ y = y.astype('float32') if(y.dtype=='float64') else y
78
+ if(DLL.had_function('PSNR_Byte') and x.dtype=='uint8' and y.dtype=='uint8'):
79
+ return DLL.PSNR_Byte(x.reshape([-1]), y.reshape([-1]), w*c, w, h, 255 if(data_range==None) else int(data_range))
80
+ if(DLL.had_function('PSNR_Float') and x.dtype=='float32' and y.dtype=='float32'):
81
+ return DLL.PSNR_Float(x.reshape([-1]), y.reshape([-1]), w*c, w, h, 255.0 if(data_range==None) else float(data_range))
82
+
83
+
84
+ def ssim(x, y, data_range=None, win_size=7):
85
+ if x.ndim == 2:
86
+ h, w = x.shape
87
+ c = 1
88
+ elif x.ndim == 3:
89
+ h, w, c = x.shape
90
+ else:
91
+ raise ValueError(f"Unsupported image dimensions: {x.shape}")
92
+
93
+ x = x.astype('float32') if(x.dtype=='float64') else x
94
+ y = y.astype('float32') if(y.dtype=='float64') else y
95
+ if(DLL.had_function('SSIM_Byte') and x.dtype=='uint8' and y.dtype=='uint8'):
96
+ return DLL.SSIM_Byte(x.reshape([-1]), y.reshape([-1]), w*c, w, h, win_size, 255 if(data_range==None) else int(data_range))
97
+ if(DLL.had_function('SSIM_Float') and x.dtype=='float32' and y.dtype=='float32'):
98
+ return DLL.SSIM_Float(x.reshape([-1]), y.reshape([-1]), w*c, w, h, win_size, 255.0 if(data_range==None) else float(data_range))
@@ -0,0 +1,37 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "Fast-SSIM"
7
+ description = "Fast SSIM and PSNR algorithms for Python. Up to 30x speedup for SSIM and up to 10x for PSNR."
8
+ readme = "README.md"
9
+ license = "MIT"
10
+ license-files = ["LICENSE"]
11
+ keywords = ["ssim", "psnr", "image quality", "image comparison", "image processing"]
12
+ authors = [{name = "Tim Lodemann"}]
13
+ dynamic = ["version"]
14
+ requires-python = ">=3.9"
15
+ classifiers = [
16
+ "Intended Audience :: Developers",
17
+ "Operating System :: Microsoft :: Windows",
18
+ "Operating System :: POSIX :: Linux",
19
+ "Programming Language :: Python :: 3",
20
+ "Topic :: Scientific/Engineering :: Image Processing",
21
+ ]
22
+ dependencies = ["numpy"]
23
+
24
+ [project.urls]
25
+ Homepage = "https://github.com/timminator/Fast-SSIM"
26
+ documentation = "https://github.com/timminator/Fast-SSIM/blob/master/README.md"
27
+ Repository = "https://github.com/timminator/Fast-SSIM.git"
28
+ Issues = "https://github.com/timminator/Fast-SSIM/issues"
29
+
30
+ [tool.setuptools]
31
+ packages = ["fast_ssim"]
32
+
33
+ [tool.setuptools.package-data]
34
+ fast_ssim = ["resources/*ssim.*"]
35
+
36
+ [tool.setuptools.dynamic]
37
+ version = {attr = "fast_ssim._core.__version__"}
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+