1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 numpy,
6 scipy,
7 pillow,
8 fetchpatch,
9}:
10
11buildPythonPackage rec {
12 pname = "pyssim";
13 version = "0.6";
14 format = "setuptools";
15
16 propagatedBuildInputs = [
17 numpy
18 scipy
19 pillow
20 ];
21
22 # PyPI tarball doesn't contain test images so let's use GitHub
23 src = fetchFromGitHub {
24 owner = "jterrace";
25 repo = pname;
26 rev = "v${version}";
27 sha256 = "sha256-VvxQTvDTDms6Ccyclbf9P0HEQksl5atPPzHuH8yXTmc=";
28 };
29
30 patches = [
31 # "Replace Image.ANTIALIAS with Image.LANCZOS"
32 # Image.ANTIALIAS has been removed in Pillow 10.0.0,
33 # the version currently in nixpkgs,
34 # and Image.LANCZOS is a drop-in since Pillow 2.7.0.
35 # https://github.com/jterrace/pyssim/pull/45
36 (fetchpatch {
37 url = "https://github.com/jterrace/pyssim/commit/db4296c12ca9c027eb9cd61b52195a78dfcc6711.patch";
38 hash = "sha256-wNp47EFtjXv6jIFX25IErXg83ksmGRNFKNeMFS+tP6s=";
39 })
40 ];
41
42 # Tests are copied from .travis.yml
43 checkPhase = ''
44 $out/bin/pyssim test-images/test1-1.png test-images/test1-1.png | grep 1
45 $out/bin/pyssim test-images/test1-1.png test-images/test1-2.png | grep 0.998
46 $out/bin/pyssim test-images/test1-1.png "test-images/*" | grep -E " 1| 0.998| 0.672| 0.648" | wc -l | grep 4
47 $out/bin/pyssim --cw --width 128 --height 128 test-images/test1-1.png test-images/test1-1.png | grep 1
48 $out/bin/pyssim --cw --width 128 --height 128 test-images/test3-orig.jpg test-images/test3-rot.jpg | grep 0.938
49 '';
50
51 meta = with lib; {
52 description = "Module for computing Structured Similarity Image Metric (SSIM) in Python";
53 mainProgram = "pyssim";
54 homepage = "https://github.com/jterrace/pyssim";
55 license = licenses.mit;
56 maintainers = with maintainers; [ jluttine ];
57 };
58}