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