Merge branch 'master' into core-updates
[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 check)
40 #:use-module (gnu packages compression)
41 #:use-module (gnu packages curl)
42 #:use-module (gnu packages documentation)
43 #:use-module (gnu packages flex)
44 #:use-module (gnu packages fontutils)
45 #:use-module (gnu packages geo)
46 #:use-module (gnu packages ghostscript)
47 #:use-module (gnu packages gl)
48 #:use-module (gnu packages glib)
49 #:use-module (gnu packages gnome)
50 #:use-module (gnu packages graphics)
51 #:use-module (gnu packages graphviz)
52 #:use-module (gnu packages gstreamer)
53 #:use-module (gnu packages gtk)
54 #:use-module (gnu packages image)
55 #:use-module (gnu packages imagemagick)
56 #:use-module (gnu packages maths)
57 #:use-module (gnu packages pdf)
58 #:use-module (gnu packages perl)
59 #:use-module (gnu packages photo)
60 #:use-module (gnu packages pkg-config)
61 #:use-module (gnu packages protobuf)
62 #:use-module (gnu packages python)
63 #:use-module (gnu packages python-xyz)
64 #:use-module (gnu packages qt)
65 #:use-module (gnu packages serialization)
66 #:use-module (gnu packages tbb)
67 #:use-module (gnu packages tls)
68 #:use-module (gnu packages video)
69 #:use-module (gnu packages xiph)
70 #:use-module (gnu packages xml)
71 #:use-module (gnu packages xorg)
72 #:use-module (ice-9 match)
73 #:use-module (srfi srfi-1))
74
75 (define-public dcmtk
76 (package
77 (name "dcmtk")
78 (version "3.6.4")
79 (source
80 (origin
81 (method url-fetch)
82 (uri
83 (string-append "ftp://dicom.offis.de/pub/dicom/offis/software/dcmtk/"
84 "dcmtk" (string-join (string-split version #\.) "")
85 "/dcmtk-" version ".tar.gz"))
86 (sha256
87 (base32 "1h22z8g0kmvhg8lgkbikyzyphhvxvq6018a00yd6i4g0z9ag6gx9"))))
88 (build-system cmake-build-system)
89 (inputs
90 `(;; Our ICU is too recent: “error: ‘UChar’ does not name a type“.
91 ;; ("icu4c" ,icu4c)
92 ("libjpeg" ,libjpeg)
93 ("libpng" ,libpng)
94 ("libtiff" ,libtiff)
95 ("libxml2" ,libxml2)
96 ("openssl" ,openssl)
97 ("zlib" ,zlib)))
98 (native-inputs
99 `(("doxygen" ,doxygen))) ; for HTML documentation
100 (home-page "https://dcmtk.org")
101 (synopsis "Libraries and programs implementing parts of the DICOM standard")
102 (description "DCMTK is a collection of libraries and applications
103 implementing large parts the DICOM standard. It includes software for
104 examining, constructing and converting DICOM image files, handling offline
105 media, sending and receiving images over a network connection, as well as
106 demonstrative image storage and worklist servers.")
107 (license (license:fsf-free
108 "file://COPYRIGHT"
109 "A union of the Apache 2.0 licence and various non-copyleft
110 licences similar to the Modified BSD licence."))))
111
112 (define-public mia
113 (package
114 (name "mia")
115 (version "2.4.6")
116 (source (origin
117 (method url-fetch)
118 (uri (string-append "mirror://sourceforge/mia/mia/"
119 (version-major+minor version)
120 "/mia-" version ".tar.xz"))
121 (sha256
122 (base32
123 "0j4nd5z7i3v199jh7hqqhwd4g7snchizkc7rhzanpvngqg91m1pb"))))
124 (build-system cmake-build-system)
125 (arguments
126 `(#:configure-flags
127 (list "-DMIA_CREATE_NIPYPE_INTERFACES=0"
128 "-DCMAKE_CXX_FLAGS=-fpermissive")))
129 (inputs
130 `(("boost" ,boost)
131 ("dcmtk" ,dcmtk)
132 ("doxygen" ,doxygen)
133 ("eigen" ,eigen)
134 ("fftw" ,fftw)
135 ("fftwf" ,fftwf)
136 ("gsl" ,gsl)
137 ("gts" ,gts)
138 ("hdf5" ,hdf5)
139 ("itpp" ,itpp)
140 ("libjpeg" ,libjpeg)
141 ("libpng" ,libpng)
142 ("libtiff" ,libtiff)
143 ("libxml" ,libxml2)
144 ("libxml++" ,libxml++)
145 ("maxflow" ,maxflow)
146 ("niftilib" ,niftilib)
147 ("nlopt" ,nlopt)
148 ("openexr" ,openexr)
149 ("python-lxml" ,python2-lxml)
150 ("vtk" ,vtk)))
151 (native-inputs
152 `(("pkg-config" ,pkg-config)
153 ("python" ,python-2)))
154 (home-page "http://mia.sourceforge.net")
155 (synopsis "Toolkit for gray scale medical image analysis")
156 (description "MIA provides a combination of command line tools, plug-ins,
157 and libraries that make it possible run image processing tasks interactively
158 in a command shell and to prototype using the shell's scripting language. It
159 is built around a plug-in structure that makes it easy to add functionality
160 without compromising the original code base and it makes use of a wide variety
161 of external libraries that provide additional functionality.")
162 (license license:gpl3+)))
163
164 (define-public vtk
165 (package
166 (name "vtk")
167 (version "8.2.0")
168 (source (origin
169 (method url-fetch)
170 (uri (string-append "https://vtk.org/files/release/"
171 (version-major+minor version)
172 "/VTK-" version ".tar.gz"))
173 (sha256
174 (base32
175 "1fspgp8k0myr6p2a6wkc21ldcswb4bvmb484m12mxgk1a9vxrhrl"))))
176 (build-system cmake-build-system)
177 (arguments
178 '(#:build-type "Release" ;Build without '-g' to save space.
179 ;; -DVTK_USE_SYSTEM_NETCDF:BOOL=TRUE requires netcdf_cxx
180 #:configure-flags '("-DVTK_USE_SYSTEM_EXPAT:BOOL=TRUE"
181 "-DVTK_USE_SYSTEM_FREETYPE:BOOL=TRUE"
182 "-DVTK_USE_SYSTEM_HDF5:BOOL=TRUE"
183 "-DVTK_USE_SYSTEM_JPEG:BOOL=TRUE"
184 "-DVTK_USE_SYSTEM_JSONCPP:BOOL=TRUE"
185 "-DVTK_USE_SYSTEM_LIBXML2:BOOL=TRUE"
186 "-DVTK_USE_SYSTEM_OGGTHEORA:BOOL=TRUE"
187 "-DVTK_USE_SYSTEM_PNG:BOOL=TRUE"
188 "-DVTK_USE_SYSTEM_TIFF:BOOL=TRUE"
189 "-DVTK_USE_SYSTEM_ZLIB:BOOL=TRUE")
190 #:tests? #f)) ;XXX: no "test" target
191 (inputs
192 `(("libXt" ,libxt)
193 ("xorgproto" ,xorgproto)
194 ("libX11" ,libx11)
195 ("libxml2" ,libxml2)
196 ("mesa" ,mesa)
197 ("glu" ,glu)
198 ("expat" ,expat)
199 ("freetype" ,freetype)
200 ("hdf5" ,hdf5)
201 ("jpeg" ,libjpeg)
202 ("jsoncpp" ,jsoncpp)
203 ("libogg" ,libogg)
204 ("libtheora" ,libtheora)
205 ("png" ,libpng)
206 ("tiff" ,libtiff)
207 ("zlib" ,zlib)))
208 (home-page "https://vtk.org/")
209 (synopsis "Libraries for 3D computer graphics")
210 (description
211 "The Visualization Toolkit (VTK) is a C++ library for 3D computer graphics,
212 image processing and visualization. It supports a wide variety of
213 visualization algorithms including: scalar, vector, tensor, texture, and
214 volumetric methods; and advanced modeling techniques such as: implicit
215 modeling, polygon reduction, mesh smoothing, cutting, contouring, and Delaunay
216 triangulation. VTK has an extensive information visualization framework, has
217 a suite of 3D interaction widgets, supports parallel processing, and
218 integrates with various databases on GUI toolkits such as Qt and Tk.")
219 (license license:bsd-3)))
220
221 ;; itksnap needs an older variant of VTK.
222 (define-public vtk-6
223 (package (inherit vtk)
224 (version "6.3.0")
225 (source (origin
226 (method url-fetch)
227 (uri (string-append "https://vtk.org/files/release/"
228 (version-major+minor version)
229 "/VTK-" version ".tar.gz"))
230 (sha256
231 (base32
232 "0pla1r5mvkgl4sl213gfdhzrypdgai0h3z5mfgm6p9jz9hsr794j"))))
233 (inputs
234 `(("jsoncpp" ,jsoncpp-for-tensorflow)
235 ,@(alist-delete "jsoncpp" (package-inputs vtk))))))
236
237 (define-public opencv
238 (package
239 (name "opencv")
240 (version "3.4.3")
241 (source (origin
242 (method git-fetch)
243 (uri (git-reference
244 (url "https://github.com/opencv/opencv")
245 (commit version)))
246 (file-name (git-file-name name version))
247 (sha256
248 (base32
249 "06bc61r8myym4s8im10brdjfg4wxkrvsbhhl7vr1msdan2xddzi3"))
250 (modules '((guix build utils)))
251 (snippet
252 '(begin
253 ;; Remove external libraries. We have all available in Guix:
254 (delete-file-recursively "3rdparty")
255
256 ;; Milky icon set is non-free:
257 (delete-file-recursively "modules/highgui/src/files_Qt/Milky")
258
259 ;; Some jars found:
260 (for-each delete-file
261 '("modules/java/test/pure_test/lib/junit-4.11.jar"
262 "samples/java/sbt/sbt/sbt-launch.jar"))
263 #t))))
264 (build-system cmake-build-system)
265 (arguments
266 `(#:configure-flags
267 (list "-DWITH_IPP=OFF"
268 "-DWITH_ITT=OFF"
269 "-DWITH_CAROTENE=OFF" ; only visible on arm/aarch64
270 "-DENABLE_PRECOMPILED_HEADERS=OFF"
271
272 ;; FIXME: OpenEXR requires C++11 or later. Remove this when
273 ;; the default compiler is GCC 7.
274 "-DCMAKE_CXX_FLAGS=-std=gnu++11"
275
276 ;; CPU-Features:
277 ;; See cmake/OpenCVCompilerOptimizations.cmake
278 ;; (CPU_ALL_OPTIMIZATIONS) for a list of all optimizations
279 ;; BASELINE is the minimum optimization all CPUs must support
280 ;;
281 ;; DISPATCH is the list of optional dispatches.
282 "-DCPU_BASELINE=SSE2"
283
284 ,@(match (%current-system)
285 ("x86_64-linux"
286 '("-DCPU_DISPATCH=NEON;VFPV3;FP16;SSE;SSE2;SSE3;SSSE3;SSE4_1;SSE4_2;POPCNT;AVX;FP16;AVX2;FMA3;AVX_512F;AVX512_SKX"
287 "-DCPU_DISPATCH_REQUIRE=SSE3,SSSE3,SSE4_1,SSE4_2,AVX,AVX2"))
288 ("armhf-linux"
289 '("-DCPU_BASELINE_DISABLE=NEON")) ; causes build failures
290 ("aarch64-linux"
291 '("-DCPU_BASELINE=NEON"
292 "-DCPU_DISPATCH=NEON;VFPV3;FP16"))
293 (_ '()))
294
295 "-DBUILD_PERF_TESTS=OFF"
296 "-DBUILD_TESTS=ON"
297
298 (string-append "-DOPENCV_EXTRA_MODULES_PATH=" (getcwd)
299 "/opencv-contrib/modules")
300
301 ;;Define test data:
302 (string-append "-DOPENCV_TEST_DATA_PATH=" (getcwd)
303 "/opencv-extra/testdata")
304
305 ;; Is ON by default and would try to rebuild 3rd-party protobuf,
306 ;; which we had removed, which would lead to an error:
307 "-DBUILD_PROTOBUF=OFF"
308
309 ;; Rebuild protobuf files, because we have a slightly different
310 ;; version than the included one. If we would not update, we
311 ;; would get a compile error later:
312 "-DPROTOBUF_UPDATE_FILES=ON"
313
314 ;; xfeatures2d disabled, because it downloads extra binaries from
315 ;; https://github.com/opencv/opencv_3rdparty
316 ;; defined in xfeatures2d/cmake/download_{vgg|bootdesc}.cmake
317 ;; Cmp this bug entry:
318 ;; https://github.com/opencv/opencv_contrib/issues/1131
319 "-DBUILD_opencv_xfeatures2d=OFF")
320 #:phases
321 (modify-phases %standard-phases
322 (add-after 'unpack 'disable-broken-tests
323 (lambda _
324 ;; These tests fails with:
325 ;; vtkXOpenGLRenderWindow (0x723990): Could not find a decent config
326 ;; I think we have no OpenGL support with the Xvfb.
327 (substitute* '("modules/viz/test/test_tutorial3.cpp"
328 "modules/viz/test/test_main.cpp"
329 "modules/viz/test/tests_simple.cpp"
330 "modules/viz/test/test_viz3d.cpp")
331 (("(TEST\\(Viz, )([a-z].*\\).*)" all pre post)
332 (string-append pre "DISABLED_" post)))
333
334 ;; This one fails with "unknown file: Failure"
335 ;; But I couldn't figure out which file was missing:
336 (substitute* "../opencv-contrib/modules/face/test/test_face_align.cpp"
337 (("(TEST\\(CV_Face_FacemarkKazemi, )(can_detect_landmarks\\).*)"
338 all pre post)
339 (string-append pre "DISABLED_" post)))
340
341 ;; Failure reason: Bad accuracy
342 ;; Incorrect count of accurate poses [2nd case]: 90.000000 / 94.000000
343 (substitute* "../opencv-contrib/modules/rgbd/test/test_odometry.cpp"
344 (("(TEST\\(RGBD_Odometry_Rgbd, )(algorithmic\\).*)" all pre post)
345 (string-append pre "DISABLED_" post)))
346 #t))
347
348 (add-after 'unpack 'unpack-submodule-sources
349 (lambda* (#:key inputs #:allow-other-keys)
350 (mkdir "../opencv-extra")
351 (mkdir "../opencv-contrib")
352 (copy-recursively (assoc-ref inputs "opencv-extra")
353 "../opencv-extra")
354 (invoke "tar" "xvf"
355 (assoc-ref inputs "opencv-contrib")
356 "--strip-components=1"
357 "-C" "../opencv-contrib")))
358
359 (add-after 'set-paths 'add-ilmbase-include-path
360 (lambda* (#:key inputs #:allow-other-keys)
361 ;; OpenEXR propagates ilmbase, but its include files do not appear
362 ;; in the CPATH, so we need to add "$ilmbase/include/OpenEXR/" to
363 ;; the CPATH to satisfy the dependency on "ImathVec.h".
364 (setenv "CPATH"
365 (string-append (assoc-ref inputs "ilmbase")
366 "/include/OpenEXR"
367 ":" (or (getenv "CPATH") "")))
368 #t))
369 (add-before 'check 'start-xserver
370 (lambda* (#:key inputs #:allow-other-keys)
371 (let ((xorg-server (assoc-ref inputs "xorg-server"))
372 (disp ":1"))
373 (setenv "HOME" (getcwd))
374 (setenv "DISPLAY" disp)
375 ;; There must be a running X server and make check doesn't start one.
376 ;; Therefore we must do it.
377 (zero? (system (format #f "~a/bin/Xvfb ~a &" xorg-server disp)))))))))
378 (native-inputs
379 `(("pkg-config" ,pkg-config)
380 ("xorg-server" ,xorg-server) ; For running the tests
381 ("opencv-extra"
382 ,(origin
383 (method git-fetch)
384 (uri (git-reference
385 (url "https://github.com/opencv/opencv_extra")
386 (commit version)))
387 (file-name (git-file-name "opencv_extra" version))
388 (sha256
389 (base32 "08p5xnq8n1jw8svvz0fnirfg7q8dm3p4a5dl7527s5xj0f9qn7lp"))))
390 ("opencv-contrib"
391 ,(origin
392 (method git-fetch)
393 (uri (git-reference
394 (url "https://github.com/opencv/opencv_contrib")
395 (commit version)))
396 (file-name (git-file-name "opencv_contrib" version))
397 (patches (search-patches "opencv-rgbd-aarch64-test-fix.patch"))
398 (sha256
399 (base32 "1f334glf39nk42mpqq6j732h3ql2mpz89jd4mcl678s8n73nfjh2"))))))
400 (inputs `(("libjpeg" ,libjpeg)
401 ("libpng" ,libpng)
402 ("jasper" ,jasper)
403 ;; ffmpeg 4.0 causes core dumps in tests.
404 ("ffmpeg" ,ffmpeg-3.4)
405 ("libtiff" ,libtiff)
406 ("hdf5" ,hdf5)
407 ("libgphoto2" ,libgphoto2)
408 ("libwebp" ,libwebp)
409 ("zlib" ,zlib)
410 ("gtkglext" ,gtkglext)
411 ("openexr" ,openexr)
412 ("ilmbase" ,ilmbase)
413 ("gtk+" ,gtk+-2)
414 ("python-numpy" ,python-numpy)
415 ("protobuf" ,protobuf)
416 ("vtk" ,vtk)
417 ("python" ,python)))
418 ;; These three CVEs are not a problem of OpenCV, see:
419 ;; https://github.com/opencv/opencv/issues/10998
420 (properties '((lint-hidden-cve . ("CVE-2018-7712"
421 "CVE-2018-7713"
422 "CVE-2018-7714"))))
423 (synopsis "Computer vision library")
424 (description "OpenCV is a library aimed at
425 real-time computer vision, including several hundred computer
426 vision algorithms. It can be used to do things like:
427
428 @itemize
429 @item image and video input and output
430 @item image and video processing
431 @item displaying
432 @item feature recognition
433 @item segmentation
434 @item facial recognition
435 @item stereo vision
436 @item structure from motion
437 @item augmented reality
438 @item machine learning
439 @end itemize\n")
440 (home-page "https://opencv.org/")
441 (license license:bsd-3)))
442
443 (define-public vips
444 (package
445 (name "vips")
446 (version "8.7.4")
447 (source
448 (origin
449 (method url-fetch)
450 (uri (string-append
451 "https://github.com/libvips/libvips/releases/download/v"
452 version "/vips-" version ".tar.gz"))
453 (sha256
454 (base32 "01gjhcrl6zj7mcj1al717v5jsniahplqhz1xkfh2j78vyfl1hxff"))))
455 (build-system gnu-build-system)
456 (native-inputs
457 `(("pkg-config" ,pkg-config)
458 ("gobject-introspection" ,gobject-introspection)))
459 (inputs
460 `(("glib" ,glib)
461 ("libjpeg" ,libjpeg)
462 ("libpng" ,libpng)
463 ("librsvg" ,librsvg)
464 ("libtiff" ,libtiff)
465 ("libexif" ,libexif)
466 ("giflib" ,giflib)
467 ("libgsf" ,libgsf)
468 ("fftw" ,fftw)
469 ("poppler" ,poppler)
470 ("pango" ,pango)
471 ("lcms" ,lcms)
472 ("matio" ,matio)
473 ("libwebp" ,libwebp)
474 ("niftilib" ,niftilib)
475 ("openexr" ,openexr)
476 ("orc" ,orc)
477 ("imagemagick" ,imagemagick)
478 ("libxml2" ,libxml2)
479 ("expat" ,expat)
480 ("hdf5" ,hdf5)))
481 (home-page "https://libvips.github.io/libvips/")
482 (synopsis "Multithreaded image processing system with low memory needs")
483 (description
484 "VIPS is a demand-driven, horizontally threaded image processing library.
485 It's particularly good at processing large images, working with colour,
486 scientific analysis, and general research & development.
487
488 Compared to most image processing libraries VIPS needs little RAM and runs
489 quickly, especially on machines with more than one CPU core. This is primarily
490 due to its architecture which automatically parallelises the image workflows.")
491 (license license:lgpl2.1+)))
492
493 (define-public nip2
494 (package
495 (name "nip2")
496 (version "8.7.1")
497 (source
498 (origin
499 (method url-fetch)
500 (uri (string-append "https://github.com/libvips/nip2/releases/download/v"
501 version "/nip2-" version ".tar.gz" ))
502 (sha256
503 (base32 "0l7n427njif53npqn02gfjjly8y3khbrkzqxp10j5vp9h97psgiw"))))
504 (build-system gnu-build-system)
505 (arguments
506 `(#:phases
507 (modify-phases %standard-phases
508 ;; test_conv.ws keep failing so disabling for now.
509 (add-after 'unpack 'disable-test-conv
510 (lambda _
511 (delete-file "test/workspaces/test_conv.ws")
512 #t))
513 (add-before 'check 'set-home
514 (lambda _
515 (setenv "HOME" "/tmp") #t)))))
516 (inputs
517 `(("vips" ,vips)
518 ("glib" ,glib)
519 ("libtiff" ,libtiff)
520 ("gtk+-2" ,gtk+-2)
521 ("libxml2" ,libxml2)
522 ("libexif" ,libexif)
523 ("libjpeg" ,libjpeg) ; required by vips.pc
524 ("librsvg" ,librsvg)
525 ("fftw" ,fftw)
526 ("libgsf" ,libgsf)
527 ("imagemagick" ,imagemagick)
528 ("orc" ,orc)
529 ("matio" ,matio)
530 ("lcms" ,lcms)
531 ("libwebp" ,libwebp)
532 ("openexr" ,openexr)
533 ("poppler" ,poppler)
534 ("gsl" ,gsl)))
535 (native-inputs
536 `(("flex" ,flex)
537 ("bison" ,bison)
538 ("pkg-config" ,pkg-config)))
539 (home-page "https://github.com/libvips/nip2")
540 (synopsis "Spreadsheet-like GUI for libvips")
541 (description "This package provide a graphical user interface (GUI) for
542 the VIPS image processing library. It's a little like a spreadsheet: you
543 create a set of formula connecting your objects together, and on a change nip2
544 recalculates.")
545 (license license:gpl2+)))
546
547 (define-public vxl
548 (package
549 (name "vxl")
550 (version "2.0.2")
551 (source
552 (origin
553 (method git-fetch)
554 (uri (git-reference
555 (url "https://github.com/vxl/vxl.git")
556 (commit (string-append "v" version))))
557 (file-name (git-file-name name version))
558 (sha256
559 (base32 "0949hw57szq8943f1whwqaz591xjmb19kj803hcv74hdai2b0ycg"))
560 (modules '((guix build utils)))
561 ;; TODO: vxl includes an old version of dcmtk. It won't build with
562 ;; version 3.6.x.
563 (snippet
564 '(begin
565 (for-each delete-file-recursively
566 '("v3p/bzlib/"
567 "v3p/geotiff/"
568 "v3p/jpeg/"
569 "v3p/png/"
570 "v3p/tiff/"
571 "v3p/zlib/"))
572 (substitute* "v3p/CMakeLists.txt"
573 (("add_subdirectory\\((tiff|png|jpeg|zlib|bzlib|geotiff)\\)")
574 ""))
575 #t))))
576 (build-system cmake-build-system)
577 (inputs
578 `(("libgeotiff" ,libgeotiff)
579 ("libtiff" ,libtiff)
580 ("libjpeg" ,libjpeg)
581 ("libpng" ,libpng)
582 ("zlib" ,zlib)))
583 (home-page "https://github.com/vxl/vxl/")
584 (synopsis "Collection of C++ libraries for computer vision")
585 (description "VXL (the Vision-something-Libraries) is a collection of C++
586 libraries designed for computer vision research and implementation.")
587 (license license:bsd-3)))
588
589 (define-public vxl-1
590 (package (inherit vxl)
591 (name "vxl")
592 (version "1.18.0")
593 (source
594 (origin
595 (method git-fetch)
596 (uri (git-reference
597 (url "https://github.com/vxl/vxl.git")
598 (commit (string-append "v" version))))
599 (file-name (git-file-name name version))
600 (sha256
601 (base32 "1g4mr2cc58jwm0vasscbd4y5380wj3ahkvq121z4gs83fhavvxgz"))
602 (modules '((guix build utils)))
603 (snippet
604 '(begin
605 (for-each delete-file-recursively
606 '("v3p/bzlib/"
607 "v3p/geotiff/"
608 "v3p/png/"
609 "v3p/tiff/"
610 "v3p/zlib/"))
611 (substitute* "v3p/CMakeLists.txt"
612 (("add_subdirectory\\((tiff|png|jpeg|zlib|bzlib|geotiff)\\)")
613 ""))
614 #t))))
615 (arguments
616 `(#:configure-flags
617 ;; Needed for itk-snap
618 (list "-DVNL_CONFIG_LEGACY_METHODS=ON")))))
619
620 (define-public insight-toolkit
621 (package
622 (name "insight-toolkit")
623 (version "5.0.0")
624 (source
625 (origin
626 (method url-fetch)
627 (uri (string-append "https://github.com/InsightSoftwareConsortium/ITK/"
628 "releases/download/v" version "/InsightToolkit-"
629 version ".tar.xz"))
630 (sha256
631 (base32 "0bs63mk4q8jmx38f031jy5w5n9yy5ng9x8ijwinvjyvas8cichqi"))))
632 (build-system cmake-build-system)
633 (arguments
634 `(#:tests? #f ; tests require network access and external data
635 #:configure-flags
636 '("-DITK_USE_GPU=ON"
637 "-DITK_USE_SYSTEM_LIBRARIES=ON"
638 "-DITK_USE_SYSTEM_GOOGLETEST=ON"
639 "-DITK_BUILD_SHARED=ON"
640 ;; This prevents "GTest::GTest" from being added to the ITK_LIBRARIES
641 ;; variable in the installed CMake files. This is necessary as other
642 ;; packages using insight-toolkit could not be configured otherwise.
643 "-DGTEST_ROOT=gtest")
644 #:phases
645 (modify-phases %standard-phases
646 (add-after 'unpack 'do-not-tune
647 (lambda _
648 (substitute* "CMake/ITKSetStandardCompilerFlags.cmake"
649 (("-mute=native") ""))
650 #t)))))
651 (inputs
652 `(("eigen" ,eigen)
653 ("expat" ,expat)
654 ("fftw" ,fftw)
655 ("fftwf" ,fftwf)
656 ("hdf5" ,hdf5)
657 ("libjpeg" ,libjpeg)
658 ("libpng" ,libpng)
659 ("libtiff" ,libtiff)
660 ("mesa" ,mesa-opencl)
661 ("perl" ,perl)
662 ("python" ,python)
663 ("tbb" ,tbb)
664 ("vxl" ,vxl-1)
665 ("zlib" ,zlib)))
666 (native-inputs
667 `(("googletest" ,googletest)
668 ("pkg-config" ,pkg-config)))
669 (home-page "https://github.com/InsightSoftwareConsortium/ITK/")
670 (synopsis "Scientific image processing, segmentation and registration")
671 (description "The Insight Toolkit (ITK) is a toolkit for N-dimensional
672 scientific image processing, segmentation, and registration. Segmentation is
673 the process of identifying and classifying data found in a digitally sampled
674 representation. Typically the sampled representation is an image acquired
675 from such medical instrumentation as CT or MRI scanners. Registration is the
676 task of aligning or developing correspondences between data. For example, in
677 the medical environment, a CT scan may be aligned with a MRI scan in order to
678 combine the information contained in both.")
679 (license license:asl2.0)))
680
681 (define-public insight-toolkit-4
682 (package (inherit insight-toolkit)
683 (version "4.13.2")
684 (source
685 (origin
686 (method url-fetch)
687 (uri (string-append "https://github.com/InsightSoftwareConsortium/ITK/"
688 "releases/download/v" version "/InsightToolkit-"
689 version ".tar.xz"))
690 (sha256
691 (base32 "19cgfpd63gqrvc3m27m394gy2d7w79g5y6lvznb5qqr49lihbgns"))))
692 (arguments
693 `(#:tests? #f ; tests require network access and external data
694 #:configure-flags
695 '("-DITKV3_COMPATIBILITY=ON" ; needed for itk-snap
696 "-DITK_USE_GPU=ON"
697 "-DITK_USE_SYSTEM_LIBRARIES=ON"
698 "-DITK_USE_SYSTEM_GOOGLETEST=ON"
699 "-DITK_USE_SYSTEM_VXL=ON")))))
700
701 (define-public insight-toolkit-4.12
702 (package (inherit insight-toolkit-4)
703 (version "4.12.2")
704 (source
705 (origin
706 (method url-fetch)
707 (uri (string-append "mirror://sourceforge/itk/itk/4.12/"
708 "InsightToolkit-" version ".tar.xz"))
709 (sha256
710 (base32 "1qw9mxbh083siljygahl4gdfv91xvfd8hfl7ghwii19f60xrvn2w"))))))
711
712 (define-public itk-snap
713 (package
714 (name "itk-snap")
715 (version "3.8.0")
716 (source
717 (origin
718 (method git-fetch)
719 (uri (git-reference
720 (url "https://git.code.sf.net/p/itk-snap/src")
721 (commit (string-append "v" version))))
722 (file-name (git-file-name name version))
723 (sha256
724 (base32 "15i5ixpryfrbf3vrrb5rici8fb585f25k0v1ljds16bp1f1msr4q"))))
725 (build-system cmake-build-system)
726 (arguments
727 `(#:configure-flags
728 (list "-DSNAP_VERSION_GIT_SHA1=release"
729 "-DSNAP_VERSION_GIT_BRANCH=release"
730 "-DSNAP_VERSION_GIT_TIMESTAMP=0"
731 "-DSNAP_PACKAGE_QT_PLUGINS=OFF"
732 "-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
733 "-DCMAKE_CXX_FLAGS=-std=gnu++11 -fpermissive")
734 #:phases
735 (modify-phases %standard-phases
736 ;; During the installation phase all libraries provided by all
737 ;; dependencies will be copied to the lib directory. That's insane,
738 ;; so we disable this.
739 (add-after 'unpack 'do-not-copy-dependencies
740 (lambda _
741 (substitute* "CMakeLists.txt"
742 (("install_qt5_executable\
743 \\(\\$\\{SNAP_MAIN_INSTALL_DIR\\}/\\$\\{SNAP_EXE\\}\\)")
744 ""))
745 #t))
746 (add-after 'unpack 'disable-gui-tests
747 (lambda _
748 ;; The GUI tests just time out.
749 (substitute* "CMakeLists.txt"
750 ((" (Workspace|DiffSpace|ProbeIntensity|RegionCompetition\
751 |RandomForest|RandomForestBailOut)")
752 ""))
753 #t))
754 (add-after 'unpack 'make-reproducible
755 (lambda _
756 (substitute* "CMakeLists.txt"
757 (("TODAY\\(SNAP_VERSION_COMPILE_DATE\\)")
758 "SET(SNAP_VERSION_COMPILE_DATE \"(removed for reproducibility)\")"))
759 #t))
760 (add-after 'unpack 'prepare-submodules
761 (lambda* (#:key inputs #:allow-other-keys)
762 (rmdir "Submodules/c3d")
763 (copy-recursively (assoc-ref inputs "c3d-src")
764 "Submodules/c3d")
765 (substitute* '("Submodules/c3d/adapters/BiasFieldCorrectionN4.cxx"
766 "Submodules/c3d/adapters/ApplyMetric.cxx")
767 (("vcl_") "std::"))
768 (rmdir "Submodules/greedy")
769 (symlink (assoc-ref inputs "greedy-src")
770 "Submodules/greedy")
771 #t))
772 (add-after 'unpack 'fix-includes
773 (lambda _
774 (substitute* "GUI/Model/RegistrationModel.cxx"
775 (("<vnl_symmetric_eigensystem.h>")
776 "<vnl/algo/vnl_symmetric_eigensystem.h>"))
777 #t))
778 (add-before 'check 'prepare-tests
779 (lambda _
780 ;; Needed by at least one test.
781 (setenv "HOME" "/tmp")
782 #t))
783 (add-after 'install 'wrap-executable
784 (lambda* (#:key inputs outputs #:allow-other-keys)
785 (let ((out (assoc-ref outputs "out")))
786 (wrap-program (string-append out "/bin/itksnap")
787 `("QT_PLUGIN_PATH" ":" prefix
788 ,(map (lambda (label)
789 (string-append (assoc-ref inputs label)
790 "/lib/qt5/plugins"))
791 '("qtbase" "qtdeclarative"))))
792 #t))))))
793 (inputs
794 `(("curl" ,curl)
795 ("fftw" ,fftw)
796 ("fftwf" ,fftwf)
797 ("glu" ,glu)
798 ("hdf5" ,hdf5)
799 ("mesa" ,mesa-opencl)
800 ;; This package does not build with either insight-toolkit 5.0.0 and
801 ;; not with 4.13. It really needs to be 4.12.
802 ("itk" ,insight-toolkit-4.12)
803 ("vtk" ,vtk-6)
804 ("qtbase" ,qtbase)
805 ("qtdeclarative" ,qtdeclarative)
806 ("qttools" ,qttools)
807 ("vxl" ,vxl-1)
808 ("zlib" ,zlib)))
809 (native-inputs
810 `(("googletest" ,googletest)
811 ("pkg-config" ,pkg-config)
812 ("c3d-src"
813 ,(let* ((commit "f521358db26e00002c911cc47bf463b043942ad3")
814 (revision "1")
815 (version (git-version "0" revision commit)))
816 (origin
817 (method git-fetch)
818 (uri (git-reference
819 (url "https://github.com/pyushkevich/c3d.git")
820 (commit commit)))
821 (file-name (git-file-name "c3d" version))
822 (sha256
823 (base32
824 "0kyv3rxrxwr8c3sa9zv01lsnhk95b27gx1s870k3yi8qp52h7bx3")))))
825 ;; We are using an arbitrary commit from 2017 because the latest
826 ;; version breaks the build...
827 ("greedy-src"
828 ,(let* ((commit "97e340f7e8e66597599144947775e6039e79a0d3")
829 (revision "1")
830 (version (git-version "0" revision commit)))
831 (origin
832 (method git-fetch)
833 (uri (git-reference
834 (url "https://github.com/pyushkevich/greedy.git")
835 (commit commit)))
836 (file-name (git-file-name "greedy" version))
837 (sha256
838 (base32
839 "0k5bc9za4jrc8z9dj08z1rkcp5xf0gnd1d2jmi1w9ny4vxh2q2ab")))))))
840 (home-page "https://sourceforge.net/p/itk-snap/")
841 (synopsis "Medical image segmentation")
842 (description "ITK-SNAP is a tool for segmenting anatomical structures in
843 medical images. It provides an automatic active contour segmentation
844 pipeline, along with supporting a manual segmentation toolbox. ITK-SNAP has a
845 full-featured UI aimed at clinical researchers.")
846 ;; This includes the submodules greedy and c3d.
847 (license license:gpl3+)))