1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 numpy,
6 scipy,
7 pillow,
8 pywavelets,
9 fetchpatch,
10 setuptools,
11}:
12
13buildPythonPackage rec {
14 pname = "pyssim";
15 version = "0.7";
16 pyproject = true;
17
18 build-system = [
19 setuptools
20 ];
21
22 dependencies = [
23 numpy
24 scipy
25 pillow
26 pywavelets
27 ];
28
29 # PyPI tarball doesn't contain test images so let's use GitHub
30 src = fetchFromGitHub {
31 owner = "jterrace";
32 repo = "pyssim";
33 tag = "v${version}";
34 sha256 = "sha256-LDNIugQeRqNsAZ5ZxS/NxHokEAwefpfRutTRpR0IcXk=";
35 };
36
37 patches = [
38 # "Use PyWavelets for continuous wavelet transform"; signal.cwt was removed and broke the build
39 (fetchpatch {
40 url = "https://github.com/jterrace/pyssim/commit/64a58687f261eb397e9c22609b5d48497ef02762.patch?full_index=1";
41 hash = "sha256-u6okuWZgGcYlf/SW0QLrAv0IYuJi7D8RHHEr8DeXKcw=";
42 })
43 ];
44
45 # Tests are copied from .github/workflows/python-package.yml
46 checkPhase = ''
47 runHook preCheck
48 $out/bin/pyssim test-images/test1-1.png test-images/test1-1.png | grep 1
49 $out/bin/pyssim test-images/test1-1.png test-images/test1-2.png | grep 0.998
50 $out/bin/pyssim test-images/test1-1.png "test-images/*" | grep -E " 1| 0.998| 0.672| 0.648" | wc -l | grep 4
51 $out/bin/pyssim --cw --width 128 --height 128 test-images/test1-1.png test-images/test1-1.png | grep 1
52 $out/bin/pyssim --cw --width 128 --height 128 test-images/test3-orig.jpg test-images/test3-rot.jpg | grep 0.938
53 runHook postCheck
54 '';
55
56 meta = {
57 description = "Module for computing Structured Similarity Image Metric (SSIM) in Python";
58 mainProgram = "pyssim";
59 homepage = "https://github.com/jterrace/pyssim";
60 changelog = "https://github.com/jterrace/pyssim/blob/${src.tag}/CHANGES.md";
61 license = lib.licenses.mit;
62 maintainers = with lib.maintainers; [ jluttine ];
63 };
64}