{ "info": { "author": "Gijs van Tulder", "author_email": "gvtulder@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3" ], "description": "Elastic deformations for N-dimensional images (Python, SciPy, NumPy, TensorFlow)\r\n================================================================================\r\n\r\n[![Documentation Status](https://readthedocs.org/projects/elasticdeform/badge/?version=latest)](https://elasticdeform.readthedocs.io/en/latest/?badge=latest)\r\n[![Build Status](https://travis-ci.org/gvtulder/elasticdeform.svg?branch=master)](https://travis-ci.org/gvtulder/elasticdeform)\r\n[![Build status](https://ci.appveyor.com/api/projects/status/air4dambkpcummeh/branch/master?svg=true)](https://ci.appveyor.com/project/gvtulder/elasticdeform/branch/master)\r\n\r\nThis library implements elastic grid-based deformations for N-dimensional images.\r\n\r\nThe elastic deformation approach is described in\r\n* Ronneberger, Fischer, and Brox, \"U-Net: Convolutional Networks for Biomedical\r\n Image Segmentation\" ()\r\n* \u00c7i\u00e7ek et al., \"3D U-Net: Learning Dense Volumetric\r\n Segmentation from Sparse Annotation\" ()\r\n\r\nThe procedure generates a coarse displacement grid with a random displacement\r\nfor each grid point. This grid is then interpolated to compute a displacement for\r\neach pixel in the input image. The input image is then deformed using the\r\ndisplacement vectors and a spline interpolation.\r\n\r\nIn addition to the normal, forward deformation, this package also provides a\r\nfunction that can backpropagate the gradient through the deformation. This makes\r\nit possible to use the deformation as a layer in a convolutional neural network.\r\nFor convenience, a TensorFlow wrapper is provided in `elasticdeform.tf`.\r\n\r\n\r\nInstallation\r\n------------\r\n\r\n```\r\npip install elasticdeform\r\nor\r\npip install git+https://github.com/gvtulder/elasticdeform\r\n```\r\n\r\nThis library requires Python 3 and NumPy development headers.\r\n\r\nOn Windows, try to install the precompiled binaries directly using `pip install elasticdeform`.\r\nIf that does not work, [these precompiled packages](https://www.lfd.uci.edu/~gohlke/pythonlibs/#elasticdeform) might be an alternative option.\r\n\r\n\r\nExamples\r\n--------\r\n\r\nThis basic example deforms an image with a random 3 x 3 deformation grid:\r\n```python\r\nimport numpy, imageio, elasticdeform\r\nX = numpy.zeros((200, 300))\r\nX[::10, ::10] = 1\r\n\r\n# apply deformation with a random 3 x 3 grid\r\nX_deformed = elasticdeform.deform_random_grid(X, sigma=25, points=3)\r\n\r\nimageio.imsave('test_X.png', X)\r\nimageio.imsave('test_X_deformed.png', X_deformed)\r\n```\r\n\r\n### Multiple inputs\r\n\r\nIf you have multiple images, e.g., an image and a segmentation image, you can\r\ndeform both simultaneously by providing a list of inputs. You can specify\r\na different spline order for each input.\r\n```python\r\n# apply deformation to inputs X and Y\r\n[X_deformed, Y_deformed] = elasticdeform.deform_random_grid([X, Y])\r\n\r\n# apply deformation to inputs X and Y,\r\n# with a different interpolation for each input\r\n[X_deformed, Y_deformed] = elasticdeform.deform_random_grid([X, Y], order=[3, 0])\r\n```\r\n\r\n### Multi-channel images\r\n\r\nBy default, a deformation will be applied to every dimension of the input. If you\r\nhave multi-channel images, you can use the `axis` parameter to specify which axes\r\nshould be deformed. The same deformation will be applied for each channel.\r\n\r\nFor example, to deform an RGB image across the first two dimensions, run:\r\n```python\r\nX_deformed = elasticdeform.deform_random_grid(X, axis=(0, 1))\r\n```\r\n\r\nWhen deforming multiple inputs, you can provide a tuple of axes for each input:\r\n```python\r\nX = numpy.random.rand(3, 200, 300)\r\nY = numpy.random.rand(200, 300)\r\n[X_deformed, Y_deformed] = elasticdeform.deform_random_grid([X, Y], axis=[(1, 2), (0, 1)])\r\n```\r\n\r\n### Cropping\r\n\r\nIf you intend to crop a small subpatch from the deformed image, you can provide\r\nthe crop dimensions to the deform function. It will then compute only the cropped\r\noutput pixels, while still computing the deformation grid based on the full image\r\ndimensions. This saves computation time.\r\n```python\r\nX = numpy.random.rand(200, 300)\r\n\r\n# define a crop region\r\ncrop = (slice(50, 150), slice(0, 100))\r\n\r\n# generate a deformation grid\r\ndisplacement = numpy.random.randn(2, 3, 3) * 25\r\n\r\n# deform full image\r\nX_deformed = elasticdeform.deform_grid(X, displacement)\r\n# compute only the cropped region\r\nX_deformed_crop = elasticdeform.deform_grid(X, displacement, crop=crop)\r\n\r\n# the deformation is the same\r\nnumpy.testing.assert_equal(X_deformed[crop], X_deformed_crop)\r\n```\r\n\r\n### Gradient\r\n\r\nThe `deform_grid_gradient` function can be used to backpropagate the gradient of\r\nthe output with respect to the input. Call `deform_grid_gradient` with the\r\nparameters that were used for the forward step.\r\n```python\r\nX = numpy.random.rand(200, 300)\r\n\r\n# generate a deformation grid\r\ndisplacement = numpy.random.randn(2, 3, 3) * 25\r\n\r\n# perform forward deformation\r\nX_deformed = elasticdeform.deform_grid(X, displacement)\r\n\r\n# obtain the gradient w.r.t. X_deformed (e.g., with backpropagation)\r\ndX_deformed = numpy.random.randn(*X_deformed.shape)\r\n\r\n# compute the gradient w.r.t. X\r\ndX = elasticdeform.deform_grid_gradient(dX_deformed, displacement)\r\n```\r\n\r\nNote: The gradient function will assume that the input has the same size as the\r\noutput. If you used the `crop` parameter in the forward phase, it is necessary to\r\nprovide the gradient function with the original, uncropped input shape in the\r\n`X_shape` parameter.\r\n\r\n\r\n### TensorFlow wrapper\r\n\r\nThe `elasticdeform.tf` module provides a wrapper for `deform_grid` in TensorFlow.\r\nThe function uses TensorFlow Tensors as input and output, but otherwise uses\r\nthe same parameters.\r\n```python\r\nimport numpy\r\nimport elasticdeform.tf as etf\r\n\r\ndisplacement_val = numpy.random.randn(2, 3, 3) * 5\r\nX_val = numpy.random.rand(200, 300)\r\ndY_val = numpy.random.rand(200, 300)\r\n\r\n# construct TensorFlow input and top gradient\r\ndisplacement = tf.Variable(displacement_val)\r\nX = tf.Variable(X_val)\r\ndY = tf.Variable(dY_val)\r\n\r\n# the deform_grid function is similar to the plain Python equivalent,\r\n# but it accepts and returns TensorFlow Tensors\r\nX_deformed = etf.deform_grid(X, displacement, order=3)\r\n\r\n# the gradient w.r.t. X can be computed in the normal TensorFlow manner\r\n[dX] = tf.gradients(X_deformed, X, dY)\r\n```\r\n\r\n\r\nLicense information\r\n-------------------\r\n\r\nThis library was written by [Gijs van Tulder](https://vantulder.net/) at the\r\n[Biomedical Imaging Group Rotterdam](https://www.bigr.nl/),\r\nErasmus MC, Rotterdam, the Netherlands\r\n\r\nIt is inspired by a similar, Python-based implementation by\r\n[Florian Calvet](https://github.com/fcalvet/image_tools).\r\nThis C-based implementation gives the same results, but is faster and has\r\na gradient implementation.\r\n\r\nThis C implementation includes a modified version of the `NI_GeometricTransform`\r\nfrom [SciPy's ndimage library](https://github.com/scipy/scipy/blob/28636fbc3f16d562eab7b823546276111f6da98a/scipy/ndimage/src/ni_interpolation.c#L242).\r\n\r\nThis code is made available under the BSD license. See ``LICENSE.txt`` for details.\r\n\r\n* \r\n* \r\n\r\n\r\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/gvtulder/elasticdeform", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "elasticdeform", "package_url": "https://pypi.org/project/elasticdeform/", "platform": "", "project_url": "https://pypi.org/project/elasticdeform/", "project_urls": { "Homepage": "https://github.com/gvtulder/elasticdeform" }, "release_url": "https://pypi.org/project/elasticdeform/0.4.6/", "requires_dist": [ "numpy", "scipy" ], "requires_python": "", "summary": "Elastic deformations for N-D images.", "version": "0.4.6" }, "last_serial": 5850759, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "4ec1b4a6c0c295ef7e1ab4090d8b7767", "sha256": "6f9672dbd836976de0c8621bd23cf2622cbf77d2f55839628b14d2c39760afad" }, "downloads": -1, "filename": "elasticdeform-0.1.0.tar.gz", "has_sig": false, "md5_digest": "4ec1b4a6c0c295ef7e1ab4090d8b7767", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12594, "upload_time": "2018-08-16T15:34:35", "url": "https://files.pythonhosted.org/packages/d4/80/7e8f4dbd82d6c7037545c71b7e2087b11b102c46f9fc2072e5ad28b127c0/elasticdeform-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "ba148c925cd6fb1759d30b8fcd9168d9", "sha256": "b87fc075982402f59030bdfd4130e82ff3a1bb056406b5168541bdd2c89a6f25" }, "downloads": -1, "filename": "elasticdeform-0.2.0.tar.gz", "has_sig": false, "md5_digest": "ba148c925cd6fb1759d30b8fcd9168d9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13606, "upload_time": "2018-08-16T19:21:16", "url": "https://files.pythonhosted.org/packages/fb/68/c658f333653d3eca225aa8714b7284abc9de617c2453ee20bf88d035500b/elasticdeform-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "9b3aa35a8b8cbe9b1137f22db8c8aa19", "sha256": "e8e8267cc839c87002818c584faef98dd66bb1d0d8bbc7d2259d3e2a8958efca" }, "downloads": -1, "filename": "elasticdeform-0.3.0.tar.gz", "has_sig": false, "md5_digest": "9b3aa35a8b8cbe9b1137f22db8c8aa19", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15269, "upload_time": "2018-08-19T00:41:35", "url": "https://files.pythonhosted.org/packages/88/20/f2b74d210c4a6aa09adb3e32addcc820c4f22859ebc86791918ae10b2b1d/elasticdeform-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "66089d54fe51a6620d0673f9c93d832a", "sha256": "e6136a779fb536ef08924e0f23f420487e95e96eae10b8672169e7c2f3e3917b" }, "downloads": -1, "filename": "elasticdeform-0.3.1.tar.gz", "has_sig": false, "md5_digest": "66089d54fe51a6620d0673f9c93d832a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15348, "upload_time": "2018-12-04T12:45:38", "url": "https://files.pythonhosted.org/packages/38/6d/68531b1c963323bedca9897c1dc6b13242ce0e29e2e38646822f115a0d69/elasticdeform-0.3.1.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "5a0f6986f54f2a54cc86b73a441f38dd", "sha256": "3814cdb337e8c66e61a1b29e7d12e1155d0a19bea6fa5064f9b0a7edf7a684d4" }, "downloads": -1, "filename": "elasticdeform-0.4.0.tar.gz", "has_sig": false, "md5_digest": "5a0f6986f54f2a54cc86b73a441f38dd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27195, "upload_time": "2018-12-07T14:33:21", "url": "https://files.pythonhosted.org/packages/54/53/b1db8c74854d43460e34e7b89b9fca6547a52f099970f43c08187809eda9/elasticdeform-0.4.0.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "cb1b65e8fa6b30c7168237145bfab0a7", "sha256": "a93716b8925a151fffd1a67a288db28a0451316a724e8711b7bc18e1e04e6639" }, "downloads": -1, "filename": "elasticdeform-0.4.1.tar.gz", "has_sig": false, "md5_digest": "cb1b65e8fa6b30c7168237145bfab0a7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27309, "upload_time": "2018-12-17T15:15:56", "url": "https://files.pythonhosted.org/packages/4e/0f/ac3bf74bd362523991e6b1ebdd2dc6631004d84a5acc7ed9bcf1583e0dca/elasticdeform-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "56e898414c14caac920cc072d62e2caf", "sha256": "6ef9839d5aae2c75e98fa659b00ddefdc3b4ac3d3edfa96f8f7f7f46fff984fb" }, "downloads": -1, "filename": "elasticdeform-0.4.2.tar.gz", "has_sig": false, "md5_digest": "56e898414c14caac920cc072d62e2caf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27309, "upload_time": "2018-12-17T15:40:02", "url": "https://files.pythonhosted.org/packages/d2/58/cdab5616d360c2bc62e52c06e71e50cf11f2f59d235c8bc7c0baa7a03f30/elasticdeform-0.4.2.tar.gz" } ], "0.4.3": [ { "comment_text": "", "digests": { "md5": "2cdf912c9112590524a2b48b484634c5", "sha256": "a5e45a78ac26b9c0dc930c48c9e687501b619ac184bd13ba2587bdcbc165d09b" }, "downloads": -1, "filename": "elasticdeform-0.4.3.tar.gz", "has_sig": false, "md5_digest": "2cdf912c9112590524a2b48b484634c5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27313, "upload_time": "2018-12-18T13:09:30", "url": "https://files.pythonhosted.org/packages/8c/80/79e03944a0cd4e6bc8e853af0a9e41c8955f697ab945e0fc3ee0bede69a1/elasticdeform-0.4.3.tar.gz" } ], "0.4.4": [ { "comment_text": "", "digests": { "md5": "c1fc44000c69621b0ef492fffdbf07ad", "sha256": "0bb1c1ffb73abee92453a0345f13c3cfc26c5849cf69e486187cc3b1898f9b0d" }, "downloads": -1, "filename": "elasticdeform-0.4.4.tar.gz", "has_sig": false, "md5_digest": "c1fc44000c69621b0ef492fffdbf07ad", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27379, "upload_time": "2019-01-21T17:33:19", "url": "https://files.pythonhosted.org/packages/35/bf/0c44af3eb721d492162a148c8b9de947fa3e16befeaaf57ebe1e50970482/elasticdeform-0.4.4.tar.gz" } ], "0.4.5": [ { "comment_text": "", "digests": { "md5": "093d676fb4c0910e11b14931eb0cbfcc", "sha256": "5eccdaba9731edd1e0536b5f2865989d2cddbf2f5b193b502b22dd680f7b17ac" }, "downloads": -1, "filename": "elasticdeform-0.4.5-cp27-cp27m-win_amd64.whl", "has_sig": false, "md5_digest": "093d676fb4c0910e11b14931eb0cbfcc", "packagetype": "bdist_wheel", "python_version": "cp27", "requires_python": null, "size": 29269, "upload_time": "2019-09-18T14:39:41", "url": "https://files.pythonhosted.org/packages/09/3f/b212b27b7ea164f4e6c40bef988b3c1cf8b2d5a283db62f593e65662aab9/elasticdeform-0.4.5-cp27-cp27m-win_amd64.whl" }, { "comment_text": "", "digests": { "md5": "9e491e2bc5404314cfce20e5fdc1b135", "sha256": "ca5a0f74db9ab3fd0f85a9bcda1b3a23383a74dfe424f964e06d2adf478b627a" }, "downloads": -1, "filename": "elasticdeform-0.4.5.tar.gz", "has_sig": false, "md5_digest": "9e491e2bc5404314cfce20e5fdc1b135", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27585, "upload_time": "2019-09-18T14:33:30", "url": "https://files.pythonhosted.org/packages/c3/45/6b9900da172a19482efcf95e9e5b1d116e35422a3107c15bb8a14ede1e28/elasticdeform-0.4.5.tar.gz" } ], "0.4.6": [ { "comment_text": "", "digests": { "md5": "06f98da1b0f9d88e8d460c4c17e242f8", "sha256": "eea8a9b341d5559b0d0d438c142b4202fae2efc960d102d4d0b08b0e117a646e" }, "downloads": -1, "filename": "elasticdeform-0.4.6-cp27-cp27m-win_amd64.whl", "has_sig": false, "md5_digest": "06f98da1b0f9d88e8d460c4c17e242f8", "packagetype": "bdist_wheel", "python_version": "cp27", "requires_python": null, "size": 29264, "upload_time": "2019-09-18T14:50:03", "url": "https://files.pythonhosted.org/packages/eb/42/c5e17d01813226c0debcb519f9d616b964b153b83efff933d83f11b22b52/elasticdeform-0.4.6-cp27-cp27m-win_amd64.whl" }, { "comment_text": "", "digests": { "md5": "5e2e32fded46146f01a7aecd936efd84", "sha256": "7d675a8786178d0cf6fea165a7d95fb84af7dd12594c119e8a1c50aca653f0c2" }, "downloads": -1, "filename": "elasticdeform-0.4.6-cp36-cp36m-win_amd64.whl", "has_sig": false, "md5_digest": "5e2e32fded46146f01a7aecd936efd84", "packagetype": "bdist_wheel", "python_version": "cp36", "requires_python": null, "size": 29603, "upload_time": "2019-09-18T14:52:13", "url": "https://files.pythonhosted.org/packages/ec/81/698305e5df757e5f68996326473423d2e515f9399fb8904834d17d201c6f/elasticdeform-0.4.6-cp36-cp36m-win_amd64.whl" }, { "comment_text": "", "digests": { "md5": "482be49a84db8e98887e9ca5260f07b3", "sha256": "1bad7a1b5d10901d6441030e33d643d3ea6189638c405f7cf5d786d2b7e9aea1" }, "downloads": -1, "filename": "elasticdeform-0.4.6-cp37-cp37m-win_amd64.whl", "has_sig": false, "md5_digest": "482be49a84db8e98887e9ca5260f07b3", "packagetype": "bdist_wheel", "python_version": "cp37", "requires_python": null, "size": 29596, "upload_time": "2019-09-18T14:52:25", "url": "https://files.pythonhosted.org/packages/74/e9/d827cad473226a502f64a3be55576f1426d56dd8f34c4c3b7c8641aa5e4b/elasticdeform-0.4.6-cp37-cp37m-win_amd64.whl" }, { "comment_text": "", "digests": { "md5": "4b4a880551eb1c3f7d5a53dd586ba46a", "sha256": "ba880611fe782d119903c6d87ec18304ab8afce21f77eddc71b7870cb4ec190a" }, "downloads": -1, "filename": "elasticdeform-0.4.6.tar.gz", "has_sig": false, "md5_digest": "4b4a880551eb1c3f7d5a53dd586ba46a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27582, "upload_time": "2019-09-18T14:52:39", "url": "https://files.pythonhosted.org/packages/41/67/931371b1434b919537c43867ef45dae8af985a7331ae5b6d0e47bddfc875/elasticdeform-0.4.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "06f98da1b0f9d88e8d460c4c17e242f8", "sha256": "eea8a9b341d5559b0d0d438c142b4202fae2efc960d102d4d0b08b0e117a646e" }, "downloads": -1, "filename": "elasticdeform-0.4.6-cp27-cp27m-win_amd64.whl", "has_sig": false, "md5_digest": "06f98da1b0f9d88e8d460c4c17e242f8", "packagetype": "bdist_wheel", "python_version": "cp27", "requires_python": null, "size": 29264, "upload_time": "2019-09-18T14:50:03", "url": "https://files.pythonhosted.org/packages/eb/42/c5e17d01813226c0debcb519f9d616b964b153b83efff933d83f11b22b52/elasticdeform-0.4.6-cp27-cp27m-win_amd64.whl" }, { "comment_text": "", "digests": { "md5": "5e2e32fded46146f01a7aecd936efd84", "sha256": "7d675a8786178d0cf6fea165a7d95fb84af7dd12594c119e8a1c50aca653f0c2" }, "downloads": -1, "filename": "elasticdeform-0.4.6-cp36-cp36m-win_amd64.whl", "has_sig": false, "md5_digest": "5e2e32fded46146f01a7aecd936efd84", "packagetype": "bdist_wheel", "python_version": "cp36", "requires_python": null, "size": 29603, "upload_time": "2019-09-18T14:52:13", "url": "https://files.pythonhosted.org/packages/ec/81/698305e5df757e5f68996326473423d2e515f9399fb8904834d17d201c6f/elasticdeform-0.4.6-cp36-cp36m-win_amd64.whl" }, { "comment_text": "", "digests": { "md5": "482be49a84db8e98887e9ca5260f07b3", "sha256": "1bad7a1b5d10901d6441030e33d643d3ea6189638c405f7cf5d786d2b7e9aea1" }, "downloads": -1, "filename": "elasticdeform-0.4.6-cp37-cp37m-win_amd64.whl", "has_sig": false, "md5_digest": "482be49a84db8e98887e9ca5260f07b3", "packagetype": "bdist_wheel", "python_version": "cp37", "requires_python": null, "size": 29596, "upload_time": "2019-09-18T14:52:25", "url": "https://files.pythonhosted.org/packages/74/e9/d827cad473226a502f64a3be55576f1426d56dd8f34c4c3b7c8641aa5e4b/elasticdeform-0.4.6-cp37-cp37m-win_amd64.whl" }, { "comment_text": "", "digests": { "md5": "4b4a880551eb1c3f7d5a53dd586ba46a", "sha256": "ba880611fe782d119903c6d87ec18304ab8afce21f77eddc71b7870cb4ec190a" }, "downloads": -1, "filename": "elasticdeform-0.4.6.tar.gz", "has_sig": false, "md5_digest": "4b4a880551eb1c3f7d5a53dd586ba46a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27582, "upload_time": "2019-09-18T14:52:39", "url": "https://files.pythonhosted.org/packages/41/67/931371b1434b919537c43867ef45dae8af985a7331ae5b6d0e47bddfc875/elasticdeform-0.4.6.tar.gz" } ] }