Merge branch 'master' into staging
[jackhill/guix/guix.git] / gnu / packages / image-processing.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2017 John Darrington <jmd@gnu.org>
3 ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
4 ;;; Copyright © 2014 Ludovic Courtès <ludo@gnu.org>
5 ;;; Copyright © 2014 Mark H Weaver <mhw@netris.org>
6 ;;; Copyright © 2016 Eric Bavier <bavier@member.fsf.org>
7 ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
8 ;;; Copyright © 2018 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
9 ;;; Copyright © 2018 Lprndn <guix@lprndn.info>
10 ;;; Copyright © 2019 Efraim Flashner <efraim@flashner.co.il>
11 ;;;
12 ;;; This file is part of GNU Guix.
13 ;;;
14 ;;; GNU Guix is free software; you can redistribute it and/or modify it
15 ;;; under the terms of the GNU General Public License as published by
16 ;;; the Free Software Foundation; either version 3 of the License, or (at
17 ;;; your option) any later version.
18 ;;;
19 ;;; GNU Guix is distributed in the hope that it will be useful, but
20 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;;; GNU General Public License for more details.
23 ;;;
24 ;;; You should have received a copy of the GNU General Public License
25 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
26
27 (define-module (gnu packages image-processing)
28 #:use-module ((guix licenses) #:prefix license:)
29 #:use-module (guix packages)
30 #:use-module (guix utils)
31 #:use-module (guix download)
32 #:use-module (guix git-download)
33 #:use-module (guix build-system cmake)
34 #:use-module (guix build-system gnu)
35 #:use-module (gnu packages)
36 #:use-module (gnu packages algebra)
37 #:use-module (gnu packages bison)
38 #:use-module (gnu packages boost)
39 #:use-module (gnu packages compression)
40 #:use-module (gnu packages documentation)
41 #:use-module (gnu packages flex)
42 #:use-module (gnu packages fontutils)
43 #:use-module (gnu packages ghostscript)
44 #:use-module (gnu packages gl)
45 #:use-module (gnu packages glib)
46 #:use-module (gnu packages gnome)
47 #:use-module (gnu packages graphics)
48 #:use-module (gnu packages graphviz)
49 #:use-module (gnu packages gstreamer)
50 #:use-module (gnu packages gtk)
51 #:use-module (gnu packages image)
52 #:use-module (gnu packages imagemagick)
53 #:use-module (gnu packages maths)
54 #:use-module (gnu packages pdf)
55 #:use-module (gnu packages perl)
56 #:use-module (gnu packages photo)
57 #:use-module (gnu packages pkg-config)
58 #:use-module (gnu packages protobuf)
59 #:use-module (gnu packages python)
60 #:use-module (gnu packages python-xyz)
61 #:use-module (gnu packages serialization)
62 #:use-module (gnu packages tls)
63 #:use-module (gnu packages video)
64 #:use-module (gnu packages xiph)
65 #:use-module (gnu packages xml)
66 #:use-module (gnu packages xorg)
67 #:use-module (ice-9 match))
68
69 (define-public dcmtk
70 (package
71 (name "dcmtk")
72 (version "3.6.4")
73 (source
74 (origin
75 (method url-fetch)
76 (uri
77 (string-append "ftp://dicom.offis.de/pub/dicom/offis/software/dcmtk/"
78 "dcmtk" (string-join (string-split version #\.) "")
79 "/dcmtk-" version ".tar.gz"))
80 (sha256
81 (base32 "1h22z8g0kmvhg8lgkbikyzyphhvxvq6018a00yd6i4g0z9ag6gx9"))))
82 (build-system cmake-build-system)
83 (inputs
84 `(;; Our ICU is too recent: “error: ‘UChar’ does not name a type“.
85 ;; ("icu4c" ,icu4c)
86 ("libjpeg" ,libjpeg)
87 ("libpng" ,libpng)
88 ("libtiff" ,libtiff)
89 ("libxml2" ,libxml2)
90 ("openssl" ,openssl)
91 ("zlib" ,zlib)))
92 (native-inputs
93 `(("doxygen" ,doxygen))) ; for HTML documentation
94 (home-page "https://dcmtk.org")
95 (synopsis "Libraries and programs implementing parts of the DICOM standard")
96 (description "DCMTK is a collection of libraries and applications
97 implementing large parts the DICOM standard. It includes software for
98 examining, constructing and converting DICOM image files, handling offline
99 media, sending and receiving images over a network connection, as well as
100 demonstrative image storage and worklist servers.")
101 (license (license:fsf-free
102 "file://COPYRIGHT"
103 "A union of the Apache 2.0 licence and various non-copyleft
104 licences similar to the Modified BSD licence."))))
105
106 (define-public mia
107 (package
108 (name "mia")
109 (version "2.4.6")
110 (source (origin
111 (method url-fetch)
112 (uri (string-append "mirror://sourceforge/mia/mia/"
113 (version-major+minor version)
114 "/mia-" version ".tar.xz"))
115 (sha256
116 (base32
117 "0j4nd5z7i3v199jh7hqqhwd4g7snchizkc7rhzanpvngqg91m1pb"))))
118 (build-system cmake-build-system)
119 (arguments
120 `(#:configure-flags
121 (list "-DMIA_CREATE_NIPYPE_INTERFACES=0"
122 "-DCMAKE_CXX_FLAGS=-fpermissive")))
123 (inputs
124 `(("boost" ,boost)
125 ("dcmtk" ,dcmtk)
126 ("doxygen" ,doxygen)
127 ("eigen" ,eigen)
128 ("fftw" ,fftw)
129 ("fftwf" ,fftwf)
130 ("gsl" ,gsl)
131 ("gts" ,gts)
132 ("hdf5" ,hdf5)
133 ("itpp" ,itpp)
134 ("libjpeg" ,libjpeg)
135 ("libpng" ,libpng)
136 ("libtiff" ,libtiff)
137 ("libxml" ,libxml2)
138 ("libxml++" ,libxml++)
139 ("maxflow" ,maxflow)
140 ("niftilib" ,niftilib)
141 ("nlopt" ,nlopt)
142 ("openexr" ,openexr)
143 ("python-lxml" ,python2-lxml)
144 ("vtk" ,vtk)))
145 (native-inputs
146 `(("pkg-config" ,pkg-config)
147 ("python" ,python-2)))
148 (home-page "http://mia.sourceforge.net")
149 (synopsis "Toolkit for gray scale medical image analysis")
150 (description "MIA provides a combination of command line tools, plug-ins,
151 and libraries that make it possible run image processing tasks interactively
152 in a command shell and to prototype using the shell's scripting language. It
153 is built around a plug-in structure that makes it easy to add functionality
154 without compromising the original code base and it makes use of a wide variety
155 of external libraries that provide additional functionality.")
156 (license license:gpl3+)))
157
158 (define-public vtk
159 (package
160 (name "vtk")
161 (version "8.2.0")
162 (source (origin
163 (method url-fetch)
164 (uri (string-append "https://vtk.org/files/release/"
165 (version-major+minor version)
166 "/VTK-" version ".tar.gz"))
167 (sha256
168 (base32
169 "1fspgp8k0myr6p2a6wkc21ldcswb4bvmb484m12mxgk1a9vxrhrl"))))
170 (build-system cmake-build-system)
171 (arguments
172 '(#:build-type "Release" ;Build without '-g' to save space.
173 ;; -DVTK_USE_SYSTEM_NETCDF:BOOL=TRUE requires netcdf_cxx
174 #:configure-flags '("-DVTK_USE_SYSTEM_EXPAT:BOOL=TRUE"
175 "-DVTK_USE_SYSTEM_FREETYPE:BOOL=TRUE"
176 "-DVTK_USE_SYSTEM_HDF5:BOOL=TRUE"
177 "-DVTK_USE_SYSTEM_JPEG:BOOL=TRUE"
178 "-DVTK_USE_SYSTEM_JSONCPP:BOOL=TRUE"
179 "-DVTK_USE_SYSTEM_LIBXML2:BOOL=TRUE"
180 "-DVTK_USE_SYSTEM_OGGTHEORA:BOOL=TRUE"
181 "-DVTK_USE_SYSTEM_PNG:BOOL=TRUE"
182 "-DVTK_USE_SYSTEM_TIFF:BOOL=TRUE"
183 "-DVTK_USE_SYSTEM_ZLIB:BOOL=TRUE")
184 #:tests? #f)) ;XXX: no "test" target
185 (inputs
186 `(("libXt" ,libxt)
187 ("xorgproto" ,xorgproto)
188 ("libX11" ,libx11)
189 ("libxml2" ,libxml2)
190 ("mesa" ,mesa)
191 ("glu" ,glu)
192 ("expat" ,expat)
193 ("freetype" ,freetype)
194 ("hdf5" ,hdf5)
195 ("jpeg" ,libjpeg)
196 ("jsoncpp" ,jsoncpp)
197 ("libogg" ,libogg)
198 ("libtheora" ,libtheora)
199 ("png" ,libpng)
200 ("tiff" ,libtiff)
201 ("zlib" ,zlib)))
202 (home-page "https://vtk.org/")
203 (synopsis "Libraries for 3D computer graphics")
204 (description
205 "The Visualization Toolkit (VTK) is a C++ library for 3D computer graphics,
206 image processing and visualization. It supports a wide variety of
207 visualization algorithms including: scalar, vector, tensor, texture, and
208 volumetric methods; and advanced modeling techniques such as: implicit
209 modeling, polygon reduction, mesh smoothing, cutting, contouring, and Delaunay
210 triangulation. VTK has an extensive information visualization framework, has
211 a suite of 3D interaction widgets, supports parallel processing, and
212 integrates with various databases on GUI toolkits such as Qt and Tk.")
213 (license license:bsd-3)))
214
215 (define-public opencv
216 (package
217 (name "opencv")
218 (version "3.4.3")
219 (source (origin
220 (method git-fetch)
221 (uri (git-reference
222 (url "https://github.com/opencv/opencv")
223 (commit version)))
224 (file-name (git-file-name name version))
225 (sha256
226 (base32
227 "06bc61r8myym4s8im10brdjfg4wxkrvsbhhl7vr1msdan2xddzi3"))
228 (modules '((guix build utils)))
229 (snippet
230 '(begin
231 ;; Remove external libraries. We have all available in Guix:
232 (delete-file-recursively "3rdparty")
233
234 ;; Milky icon set is non-free:
235 (delete-file-recursively "modules/highgui/src/files_Qt/Milky")
236
237 ;; Some jars found:
238 (for-each delete-file
239 '("modules/java/test/pure_test/lib/junit-4.11.jar"
240 "samples/java/sbt/sbt/sbt-launch.jar"))
241 #t))))
242 (build-system cmake-build-system)
243 (arguments
244 `(#:configure-flags
245 (list "-DWITH_IPP=OFF"
246 "-DWITH_ITT=OFF"
247 "-DWITH_CAROTENE=OFF" ; only visible on arm/aarch64
248 "-DENABLE_PRECOMPILED_HEADERS=OFF"
249
250 ;; CPU-Features:
251 ;; See cmake/OpenCVCompilerOptimizations.cmake
252 ;; (CPU_ALL_OPTIMIZATIONS) for a list of all optimizations
253 ;; BASELINE is the minimum optimization all CPUs must support
254 ;;
255 ;; DISPATCH is the list of optional dispatches.
256 "-DCPU_BASELINE=SSE2"
257
258 ,@(match (%current-system)
259 ("x86_64-linux"
260 '("-DCPU_DISPATCH=NEON;VFPV3;FP16;SSE;SSE2;SSE3;SSSE3;SSE4_1;SSE4_2;POPCNT;AVX;FP16;AVX2;FMA3;AVX_512F;AVX512_SKX"
261 "-DCPU_DISPATCH_REQUIRE=SSE3,SSSE3,SSE4_1,SSE4_2,AVX,AVX2"))
262 ("armhf-linux"
263 '("-DCPU_BASELINE_DISABLE=NEON")) ; causes build failures
264 ("aarch64-linux"
265 '("-DCPU_BASELINE=NEON"
266 "-DCPU_DISPATCH=NEON;VFPV3;FP16"))
267 (_ '()))
268
269 "-DBUILD_PERF_TESTS=OFF"
270 "-DBUILD_TESTS=ON"
271
272 (string-append "-DOPENCV_EXTRA_MODULES_PATH=" (getcwd)
273 "/opencv-contrib/modules")
274
275 ;;Define test data:
276 (string-append "-DOPENCV_TEST_DATA_PATH=" (getcwd)
277 "/opencv-extra/testdata")
278
279 ;; Is ON by default and would try to rebuild 3rd-party protobuf,
280 ;; which we had removed, which would lead to an error:
281 "-DBUILD_PROTOBUF=OFF"
282
283 ;; Rebuild protobuf files, because we have a slightly different
284 ;; version than the included one. If we would not update, we
285 ;; would get a compile error later:
286 "-DPROTOBUF_UPDATE_FILES=ON"
287
288 ;; xfeatures2d disabled, because it downloads extra binaries from
289 ;; https://github.com/opencv/opencv_3rdparty
290 ;; defined in xfeatures2d/cmake/download_{vgg|bootdesc}.cmake
291 ;; Cmp this bug entry:
292 ;; https://github.com/opencv/opencv_contrib/issues/1131
293 "-DBUILD_opencv_xfeatures2d=OFF")
294 #:phases
295 (modify-phases %standard-phases
296 (add-after 'unpack 'disable-broken-tests
297 (lambda _
298 ;; These tests fails with:
299 ;; vtkXOpenGLRenderWindow (0x723990): Could not find a decent config
300 ;; I think we have no OpenGL support with the Xvfb.
301 (substitute* '("modules/viz/test/test_tutorial3.cpp"
302 "modules/viz/test/test_main.cpp"
303 "modules/viz/test/tests_simple.cpp"
304 "modules/viz/test/test_viz3d.cpp")
305 (("(TEST\\(Viz, )([a-z].*\\).*)" all pre post)
306 (string-append pre "DISABLED_" post)))
307
308 ;; This one fails with "unknown file: Failure"
309 ;; But I couldn't figure out which file was missing:
310 (substitute* "../opencv-contrib/modules/face/test/test_face_align.cpp"
311 (("(TEST\\(CV_Face_FacemarkKazemi, )(can_detect_landmarks\\).*)"
312 all pre post)
313 (string-append pre "DISABLED_" post)))
314
315 ;; Failure reason: Bad accuracy
316 ;; Incorrect count of accurate poses [2nd case]: 90.000000 / 94.000000
317 (substitute* "../opencv-contrib/modules/rgbd/test/test_odometry.cpp"
318 (("(TEST\\(RGBD_Odometry_Rgbd, )(algorithmic\\).*)" all pre post)
319 (string-append pre "DISABLED_" post)))
320 #t))
321
322 (add-after 'unpack 'unpack-submodule-sources
323 (lambda* (#:key inputs #:allow-other-keys)
324 (mkdir "../opencv-extra")
325 (mkdir "../opencv-contrib")
326 (copy-recursively (assoc-ref inputs "opencv-extra")
327 "../opencv-extra")
328 (invoke "tar" "xvf"
329 (assoc-ref inputs "opencv-contrib")
330 "--strip-components=1"
331 "-C" "../opencv-contrib")))
332
333 (add-after 'set-paths 'add-ilmbase-include-path
334 (lambda* (#:key inputs #:allow-other-keys)
335 ;; OpenEXR propagates ilmbase, but its include files do not appear
336 ;; in the CPATH, so we need to add "$ilmbase/include/OpenEXR/" to
337 ;; the CPATH to satisfy the dependency on "ImathVec.h".
338 (setenv "CPATH"
339 (string-append (assoc-ref inputs "ilmbase")
340 "/include/OpenEXR"
341 ":" (or (getenv "CPATH") "")))
342 #t))
343 (add-before 'check 'start-xserver
344 (lambda* (#:key inputs #:allow-other-keys)
345 (let ((xorg-server (assoc-ref inputs "xorg-server"))
346 (disp ":1"))
347 (setenv "HOME" (getcwd))
348 (setenv "DISPLAY" disp)
349 ;; There must be a running X server and make check doesn't start one.
350 ;; Therefore we must do it.
351 (zero? (system (format #f "~a/bin/Xvfb ~a &" xorg-server disp)))))))))
352 (native-inputs
353 `(("pkg-config" ,pkg-config)
354 ("xorg-server" ,xorg-server) ; For running the tests
355 ("opencv-extra"
356 ,(origin
357 (method git-fetch)
358 (uri (git-reference
359 (url "https://github.com/opencv/opencv_extra")
360 (commit version)))
361 (file-name (git-file-name "opencv_extra" version))
362 (sha256
363 (base32 "08p5xnq8n1jw8svvz0fnirfg7q8dm3p4a5dl7527s5xj0f9qn7lp"))))
364 ("opencv-contrib"
365 ,(origin
366 (method git-fetch)
367 (uri (git-reference
368 (url "https://github.com/opencv/opencv_contrib")
369 (commit version)))
370 (file-name (git-file-name "opencv_contrib" version))
371 (patches (search-patches "opencv-rgbd-aarch64-test-fix.patch"))
372 (sha256
373 (base32 "1f334glf39nk42mpqq6j732h3ql2mpz89jd4mcl678s8n73nfjh2"))))))
374 (inputs `(("libjpeg" ,libjpeg)
375 ("libpng" ,libpng)
376 ("jasper" ,jasper)
377 ;; ffmpeg 4.0 causes core dumps in tests.
378 ("ffmpeg" ,ffmpeg-3.4)
379 ("libtiff" ,libtiff)
380 ("hdf5" ,hdf5)
381 ("libgphoto2" ,libgphoto2)
382 ("libwebp" ,libwebp)
383 ("zlib" ,zlib)
384 ("gtkglext" ,gtkglext)
385 ("openexr" ,openexr)
386 ("ilmbase" ,ilmbase)
387 ("gtk+" ,gtk+-2)
388 ("python-numpy" ,python-numpy)
389 ("protobuf" ,protobuf)
390 ("vtk" ,vtk)
391 ("python" ,python)))
392 ;; These three CVEs are not a problem of OpenCV, see:
393 ;; https://github.com/opencv/opencv/issues/10998
394 (properties '((lint-hidden-cve . ("CVE-2018-7712"
395 "CVE-2018-7713"
396 "CVE-2018-7714"))))
397 (synopsis "Computer vision library")
398 (description "OpenCV is a library aimed at
399 real-time computer vision, including several hundred computer
400 vision algorithms. It can be used to do things like:
401
402 @itemize
403 @item image and video input and output
404 @item image and video processing
405 @item displaying
406 @item feature recognition
407 @item segmentation
408 @item facial recognition
409 @item stereo vision
410 @item structure from motion
411 @item augmented reality
412 @item machine learning
413 @end itemize\n")
414 (home-page "https://opencv.org/")
415 (license license:bsd-3)))
416
417 (define-public vips
418 (package
419 (name "vips")
420 (version "8.7.4")
421 (source
422 (origin
423 (method url-fetch)
424 (uri (string-append
425 "https://github.com/libvips/libvips/releases/download/v"
426 version "/vips-" version ".tar.gz"))
427 (sha256
428 (base32 "01gjhcrl6zj7mcj1al717v5jsniahplqhz1xkfh2j78vyfl1hxff"))))
429 (build-system gnu-build-system)
430 (native-inputs
431 `(("pkg-config" ,pkg-config)
432 ("gobject-introspection" ,gobject-introspection)))
433 (inputs
434 `(("glib" ,glib)
435 ("libjpeg" ,libjpeg)
436 ("libpng" ,libpng)
437 ("librsvg" ,librsvg)
438 ("libtiff" ,libtiff)
439 ("libexif" ,libexif)
440 ("giflib" ,giflib)
441 ("libgsf" ,libgsf)
442 ("fftw" ,fftw)
443 ("poppler" ,poppler)
444 ("pango" ,pango)
445 ("lcms" ,lcms)
446 ("matio" ,matio)
447 ("libwebp" ,libwebp)
448 ("niftilib" ,niftilib)
449 ("openexr" ,openexr)
450 ("orc" ,orc)
451 ("imagemagick" ,imagemagick)
452 ("libxml2" ,libxml2)
453 ("expat" ,expat)
454 ("hdf5" ,hdf5)))
455 (home-page "https://libvips.github.io/libvips/")
456 (synopsis "Multithreaded image processing system with low memory needs")
457 (description
458 "VIPS is a demand-driven, horizontally threaded image processing library.
459 It's particularly good at processing large images, working with colour,
460 scientific analysis, and general research & development.
461
462 Compared to most image processing libraries VIPS needs little RAM and runs
463 quickly, especially on machines with more than one CPU core. This is primarily
464 due to its architecture which automatically parallelises the image workflows.")
465 (license license:lgpl2.1+)))
466
467 (define-public nip2
468 (package
469 (name "nip2")
470 (version "8.7.1")
471 (source
472 (origin
473 (method url-fetch)
474 (uri (string-append "https://github.com/libvips/nip2/releases/download/v"
475 version "/nip2-" version ".tar.gz" ))
476 (sha256
477 (base32 "0l7n427njif53npqn02gfjjly8y3khbrkzqxp10j5vp9h97psgiw"))))
478 (build-system gnu-build-system)
479 (arguments
480 `(#:phases
481 (modify-phases %standard-phases
482 ;; test_conv.ws keep failing so disabling for now.
483 (add-after 'unpack 'disable-test-conv
484 (lambda _
485 (delete-file "test/workspaces/test_conv.ws")
486 #t))
487 (add-before 'check 'set-home
488 (lambda _
489 (setenv "HOME" "/tmp") #t)))))
490 (inputs
491 `(("vips" ,vips)
492 ("glib" ,glib)
493 ("libtiff" ,libtiff)
494 ("gtk+-2" ,gtk+-2)
495 ("libxml2" ,libxml2)
496 ("libexif" ,libexif)
497 ("libjpeg" ,libjpeg) ; required by vips.pc
498 ("librsvg" ,librsvg)
499 ("fftw" ,fftw)
500 ("libgsf" ,libgsf)
501 ("imagemagick" ,imagemagick)
502 ("orc" ,orc)
503 ("matio" ,matio)
504 ("lcms" ,lcms)
505 ("libwebp" ,libwebp)
506 ("openexr" ,openexr)
507 ("poppler" ,poppler)
508 ("gsl" ,gsl)))
509 (native-inputs
510 `(("flex" ,flex)
511 ("bison" ,bison)
512 ("pkg-config" ,pkg-config)))
513 (home-page "https://github.com/libvips/nip2")
514 (synopsis "Spreadsheet-like GUI for libvips")
515 (description "This package provide a graphical user interface (GUI) for
516 the VIPS image processing library. It's a little like a spreadsheet: you
517 create a set of formula connecting your objects together, and on a change nip2
518 recalculates.")
519 (license license:gpl2+)))