{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/comments/71068718","id":71068718,"diff_hunk":"@@ -332,3 +332,126 @@ def denoise_tv_chambolle(im, weight=0.1, eps=2.e-4, n_iter_max=200,\n     else:\n         out = _denoise_tv_chambolle_nd(im, weight, eps, n_iter_max)\n     return out\n+\n+\n+def _wavelet_threshold(im, wavelet, threshold=None, sigma=None, mode='soft'):\n+    \"\"\"Performs wavelet denoising.\n+    Parameters\n+    ----------\n+    im : ndarray (2d or 3d) of ints, uints or floats\n+        Input data to be denoised. `im` can be of any numeric type,\n+        but it is cast into an ndarray of floats for the computation\n+        of the denoised image.\n+    wavelet : string\n+        The type of wavelet to perform. Can be any of the options\n+        [pywt.wavelist]_ outputs. For example, this may be any of ``{db1, db2,\n+        db3, db4, haar}``.\n+    sigma : float, optional\n+        The standard deviation of the noise. The noise is estimated when sigma is None (the default).\n+    threshold : float, optional\n+        The thresholding value. All wavelet coefficients less than this value\n+        are set to 0. The default value (None) uses the SureShrink method found in\n+        [1]_ to remove noise.\n+    mode : {'soft', 'hard'}, optional\n+        An optional argument to choose the type of denoising performed. It\n+        noted that choosing soft thresholding given additive noise finds the\n+        best approximation of the original image.\n+\n+    Returns\n+    -------\n+    out : ndarray\n+        Denoised image.\n+\n+    References\n+    ----------\n+    .. [1] Chang, S. Grace, Bin Yu, and Martin Vetterli. \"Adaptive wavelet\n+           thresholding for image denoising and compression.\" Image Processing,\n+           IEEE Transactions on 9.9 (2000): 1532-1546.\n+    \"\"\"\n+    import pywt\n+    coeffs = pywt.wavedecn(im, wavelet=wavelet)\n+    detail_coeffs = coeffs[-1]['d' * im.ndim]\n+\n+    if sigma is None:\n+        # Estimate the noise std.dev as discussed in PR #1837\n+        sigma = np.median(np.abs(detail_coeffs)) / 0.67448975019608171\n+\n+    if threshold is None:\n+        # The BayesShrink threshold from [1]_ in docstring\n+        threshold = sigma**2 / np.sqrt(max(im.var() - sigma**2, 0))\n+\n+    denoised_detail = [{key: pywt.threshold(level[key], value=threshold,\n+                       mode=mode) for key in level} for level in coeffs[1:]]\n+    denoised_root = pywt.threshold(coeffs[0], value=threshold, mode=mode)\n+    return pywt.waverecn([denoised_root, *denoised_detail], wavelet)\n+\n+\n+def denoise_wavelet(im, sigma=None, wavelet='db1', mode='soft'):\n+    \"\"\"Performs wavelet denoising on an image.\n+    Parameters\n+    ----------\n+    im : ndarray (greater than 2d) of ints, uints or floats\n+        Input data to be denoised. `im` can be of any numeric type,\n+        but it is cast into an ndarray of floats for the computation\n+        of the denoised image.\n+    sigma : float, optional\n+        The noise standard deviation used when computing the threshold\n+        adaptively as described in [1]_.\n+    wavelet : string, optional\n+        The type of wavelet to perform and can be any of the options\n+        [pywt.wavelist]_ outputs. The default is `'db1'`. For example,\n+        ``wavelet`` can be any of ``{'db2', 'haar', 'sym9'}`` and many more.\n+    mode : {'soft', 'hard'}, optional\n+        An optional argument to choose the type of denoising performed. It\n+        noted that choosing soft thresholding given additive noise finds the\n+        best approximation of the original image.\n+    Returns\n+    -------\n+    out : ndarray\n+        Denoised image.\n+    Notes\n+    -----\n+    As with the Fourier transform, there is an analogue to frequency in the\n+    wavelet domain. Correspondingly, many pixel values of an image are 0 after\n+    taking the wavelet transform.\n+    By wavelet denoising, we are enforcing that many of the wavelet coefficients\n+    are 0 while keeping the error small. When we use soft thresholding, our\n+    estimate is\n+    .. math:: \\widehat{x} = \\arg \\min_x ||z - x||_2^2 + \\lambda ||x||_1\n+    where :math:`z` is the input image wavelet coefficients and :math:`\\lambda`\n+    is the threshold.\n+    This function performs wavelet denoising on each color plane separately. The\n+    output is clipped between 0 and 1.\n+    References\n+    ----------\n+    .. [1] Chang, S. Grace, Bin Yu, and Martin Vetterli. \"Adaptive wavelet\n+           thresholding for image denoising and compression.\" Image Processing,\n+           IEEE Transactions on 9.9 (2000): 1532-1546.","path":"skimage/restoration/_denoise.py","position":38,"original_position":98,"commit_id":"1c38da0fca2c8b7a461f6f139286996d9484dd4b","original_commit_id":"1c38da0fca2c8b7a461f6f139286996d9484dd4b","user":{"login":"sciunto","id":335370,"avatar_url":"https://avatars.githubusercontent.com/u/335370?v=3","gravatar_id":"","url":"https://api.github.com/users/sciunto","html_url":"https://github.com/sciunto","followers_url":"https://api.github.com/users/sciunto/followers","following_url":"https://api.github.com/users/sciunto/following{/other_user}","gists_url":"https://api.github.com/users/sciunto/gists{/gist_id}","starred_url":"https://api.github.com/users/sciunto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sciunto/subscriptions","organizations_url":"https://api.github.com/users/sciunto/orgs","repos_url":"https://api.github.com/users/sciunto/repos","events_url":"https://api.github.com/users/sciunto/events{/privacy}","received_events_url":"https://api.github.com/users/sciunto/received_events","type":"User","site_admin":false},"body":"Please, add DOI.","created_at":"2016-07-16T16:47:26Z","updated_at":"2016-07-16T16:47:26Z","html_url":"https://github.com/scikit-image/scikit-image/pull/2190#discussion_r71068718","pull_request_url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/2190","_links":{"self":{"href":"https://api.github.com/repos/scikit-image/scikit-image/pulls/comments/71068718"},"html":{"href":"https://github.com/scikit-image/scikit-image/pull/2190#discussion_r71068718"},"pull_request":{"href":"https://api.github.com/repos/scikit-image/scikit-image/pulls/2190"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/2190","id":77713239,"html_url":"https://github.com/scikit-image/scikit-image/pull/2190","diff_url":"https://github.com/scikit-image/scikit-image/pull/2190.diff","patch_url":"https://github.com/scikit-image/scikit-image/pull/2190.patch","issue_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/2190","number":2190,"state":"open","locked":false,"title":"ENH: Implements wavelet denoising (from #1833)","user":{"login":"stsievert","id":1320475,"avatar_url":"https://avatars.githubusercontent.com/u/1320475?v=3","gravatar_id":"","url":"https://api.github.com/users/stsievert","html_url":"https://github.com/stsievert","followers_url":"https://api.github.com/users/stsievert/followers","following_url":"https://api.github.com/users/stsievert/following{/other_user}","gists_url":"https://api.github.com/users/stsievert/gists{/gist_id}","starred_url":"https://api.github.com/users/stsievert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stsievert/subscriptions","organizations_url":"https://api.github.com/users/stsievert/orgs","repos_url":"https://api.github.com/users/stsievert/repos","events_url":"https://api.github.com/users/stsievert/events{/privacy}","received_events_url":"https://api.github.com/users/stsievert/received_events","type":"User","site_admin":false},"body":"## Description\r\nThis implements wavelet denoising and is based off #1833 -- see that PR for more detail. I tried to `git rebase` but my attempt failed and this is faster.\r\n\r\nNew changes that are not reflected in #1833:\r\n\r\n* pywt added to optional requirements\r\n* a parameter renamed (`noise_std` --> `sigma`).\r\n\r\n## Checklist\r\n[It's fine to submit PRs which are a work in progress! But before they are merged, all PRs should provide:]\r\n- [x] Clean style in [the spirit of PEP8](https://www.python.org/dev/peps/pep-0008/)\r\n- [x] [Docstrings for all functions](https://github.com/numpy/numpy/blob/master/doc/example.py)\r\n- [x] Gallery example in `./doc/examples` (new features only)\r\n- [x] Unit tests\r\n- [ ] Add to contributors.txt\r\n\r\n\r\n## References\r\nThis is the same implementation as #1833, but I made a new branch to resolve some merge conflicts (I tried to rebase but *sigh*).\r\n","created_at":"2016-07-16T16:18:30Z","updated_at":"2016-07-16T16:47:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dbe195ecb12aa06772a02ca29356a2349085c135","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/2190/commits","review_comments_url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/2190/comments","review_comment_url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/2190/comments","statuses_url":"https://api.github.com/repos/scikit-image/scikit-image/statuses/1c38da0fca2c8b7a461f6f139286996d9484dd4b","head":{"label":"stsievert:wavelet-denoise-v2","ref":"wavelet-denoise-v2","sha":"1c38da0fca2c8b7a461f6f139286996d9484dd4b","user":{"login":"stsievert","id":1320475,"avatar_url":"https://avatars.githubusercontent.com/u/1320475?v=3","gravatar_id":"","url":"https://api.github.com/users/stsievert","html_url":"https://github.com/stsievert","followers_url":"https://api.github.com/users/stsievert/followers","following_url":"https://api.github.com/users/stsievert/following{/other_user}","gists_url":"https://api.github.com/users/stsievert/gists{/gist_id}","starred_url":"https://api.github.com/users/stsievert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stsievert/subscriptions","organizations_url":"https://api.github.com/users/stsievert/orgs","repos_url":"https://api.github.com/users/stsievert/repos","events_url":"https://api.github.com/users/stsievert/events{/privacy}","received_events_url":"https://api.github.com/users/stsievert/received_events","type":"User","site_admin":false},"repo":{"id":47167158,"name":"scikit-image","full_name":"stsievert/scikit-image","owner":{"login":"stsievert","id":1320475,"avatar_url":"https://avatars.githubusercontent.com/u/1320475?v=3","gravatar_id":"","url":"https://api.github.com/users/stsievert","html_url":"https://github.com/stsievert","followers_url":"https://api.github.com/users/stsievert/followers","following_url":"https://api.github.com/users/stsievert/following{/other_user}","gists_url":"https://api.github.com/users/stsievert/gists{/gist_id}","starred_url":"https://api.github.com/users/stsievert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stsievert/subscriptions","organizations_url":"https://api.github.com/users/stsievert/orgs","repos_url":"https://api.github.com/users/stsievert/repos","events_url":"https://api.github.com/users/stsievert/events{/privacy}","received_events_url":"https://api.github.com/users/stsievert/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/stsievert/scikit-image","description":"Image Processing SciKit (Toolbox for SciPy)","fork":true,"url":"https://api.github.com/repos/stsievert/scikit-image","forks_url":"https://api.github.com/repos/stsievert/scikit-image/forks","keys_url":"https://api.github.com/repos/stsievert/scikit-image/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stsievert/scikit-image/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stsievert/scikit-image/teams","hooks_url":"https://api.github.com/repos/stsievert/scikit-image/hooks","issue_events_url":"https://api.github.com/repos/stsievert/scikit-image/issues/events{/number}","events_url":"https://api.github.com/repos/stsievert/scikit-image/events","assignees_url":"https://api.github.com/repos/stsievert/scikit-image/assignees{/user}","branches_url":"https://api.github.com/repos/stsievert/scikit-image/branches{/branch}","tags_url":"https://api.github.com/repos/stsievert/scikit-image/tags","blobs_url":"https://api.github.com/repos/stsievert/scikit-image/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stsievert/scikit-image/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stsievert/scikit-image/git/refs{/sha}","trees_url":"https://api.github.com/repos/stsievert/scikit-image/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stsievert/scikit-image/statuses/{sha}","languages_url":"https://api.github.com/repos/stsievert/scikit-image/languages","stargazers_url":"https://api.github.com/repos/stsievert/scikit-image/stargazers","contributors_url":"https://api.github.com/repos/stsievert/scikit-image/contributors","subscribers_url":"https://api.github.com/repos/stsievert/scikit-image/subscribers","subscription_url":"https://api.github.com/repos/stsievert/scikit-image/subscription","commits_url":"https://api.github.com/repos/stsievert/scikit-image/commits{/sha}","git_commits_url":"https://api.github.com/repos/stsievert/scikit-image/git/commits{/sha}","comments_url":"https://api.github.com/repos/stsievert/scikit-image/comments{/number}","issue_comment_url":"https://api.github.com/repos/stsievert/scikit-image/issues/comments{/number}","contents_url":"https://api.github.com/repos/stsievert/scikit-image/contents/{+path}","compare_url":"https://api.github.com/repos/stsievert/scikit-image/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stsievert/scikit-image/merges","archive_url":"https://api.github.com/repos/stsievert/scikit-image/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stsievert/scikit-image/downloads","issues_url":"https://api.github.com/repos/stsievert/scikit-image/issues{/number}","pulls_url":"https://api.github.com/repos/stsievert/scikit-image/pulls{/number}","milestones_url":"https://api.github.com/repos/stsievert/scikit-image/milestones{/number}","notifications_url":"https://api.github.com/repos/stsievert/scikit-image/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stsievert/scikit-image/labels{/name}","releases_url":"https://api.github.com/repos/stsievert/scikit-image/releases{/id}","deployments_url":"https://api.github.com/repos/stsievert/scikit-image/deployments","created_at":"2015-12-01T05:14:02Z","updated_at":"2015-12-01T05:14:06Z","pushed_at":"2016-07-16T16:09:16Z","git_url":"git://github.com/stsievert/scikit-image.git","ssh_url":"git@github.com:stsievert/scikit-image.git","clone_url":"https://github.com/stsievert/scikit-image.git","svn_url":"https://github.com/stsievert/scikit-image","homepage":"http://scikit-image.org","size":41230,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scikit-image:master","ref":"master","sha":"418de7e4f017e4074ad8e1c90624cb9d3657c99c","user":{"login":"scikit-image","id":897180,"avatar_url":"https://avatars.githubusercontent.com/u/897180?v=3","gravatar_id":"","url":"https://api.github.com/users/scikit-image","html_url":"https://github.com/scikit-image","followers_url":"https://api.github.com/users/scikit-image/followers","following_url":"https://api.github.com/users/scikit-image/following{/other_user}","gists_url":"https://api.github.com/users/scikit-image/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-image/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-image/subscriptions","organizations_url":"https://api.github.com/users/scikit-image/orgs","repos_url":"https://api.github.com/users/scikit-image/repos","events_url":"https://api.github.com/users/scikit-image/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-image/received_events","type":"Organization","site_admin":false},"repo":{"id":2014929,"name":"scikit-image","full_name":"scikit-image/scikit-image","owner":{"login":"scikit-image","id":897180,"avatar_url":"https://avatars.githubusercontent.com/u/897180?v=3","gravatar_id":"","url":"https://api.github.com/users/scikit-image","html_url":"https://github.com/scikit-image","followers_url":"https://api.github.com/users/scikit-image/followers","following_url":"https://api.github.com/users/scikit-image/following{/other_user}","gists_url":"https://api.github.com/users/scikit-image/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-image/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-image/subscriptions","organizations_url":"https://api.github.com/users/scikit-image/orgs","repos_url":"https://api.github.com/users/scikit-image/repos","events_url":"https://api.github.com/users/scikit-image/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-image/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scikit-image/scikit-image","description":"Image Processing SciKit (Toolbox for SciPy)","fork":false,"url":"https://api.github.com/repos/scikit-image/scikit-image","forks_url":"https://api.github.com/repos/scikit-image/scikit-image/forks","keys_url":"https://api.github.com/repos/scikit-image/scikit-image/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scikit-image/scikit-image/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scikit-image/scikit-image/teams","hooks_url":"https://api.github.com/repos/scikit-image/scikit-image/hooks","issue_events_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/events{/number}","events_url":"https://api.github.com/repos/scikit-image/scikit-image/events","assignees_url":"https://api.github.com/repos/scikit-image/scikit-image/assignees{/user}","branches_url":"https://api.github.com/repos/scikit-image/scikit-image/branches{/branch}","tags_url":"https://api.github.com/repos/scikit-image/scikit-image/tags","blobs_url":"https://api.github.com/repos/scikit-image/scikit-image/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scikit-image/scikit-image/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scikit-image/scikit-image/git/refs{/sha}","trees_url":"https://api.github.com/repos/scikit-image/scikit-image/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scikit-image/scikit-image/statuses/{sha}","languages_url":"https://api.github.com/repos/scikit-image/scikit-image/languages","stargazers_url":"https://api.github.com/repos/scikit-image/scikit-image/stargazers","contributors_url":"https://api.github.com/repos/scikit-image/scikit-image/contributors","subscribers_url":"https://api.github.com/repos/scikit-image/scikit-image/subscribers","subscription_url":"https://api.github.com/repos/scikit-image/scikit-image/subscription","commits_url":"https://api.github.com/repos/scikit-image/scikit-image/commits{/sha}","git_commits_url":"https://api.github.com/repos/scikit-image/scikit-image/git/commits{/sha}","comments_url":"https://api.github.com/repos/scikit-image/scikit-image/comments{/number}","issue_comment_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/comments{/number}","contents_url":"https://api.github.com/repos/scikit-image/scikit-image/contents/{+path}","compare_url":"https://api.github.com/repos/scikit-image/scikit-image/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scikit-image/scikit-image/merges","archive_url":"https://api.github.com/repos/scikit-image/scikit-image/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scikit-image/scikit-image/downloads","issues_url":"https://api.github.com/repos/scikit-image/scikit-image/issues{/number}","pulls_url":"https://api.github.com/repos/scikit-image/scikit-image/pulls{/number}","milestones_url":"https://api.github.com/repos/scikit-image/scikit-image/milestones{/number}","notifications_url":"https://api.github.com/repos/scikit-image/scikit-image/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scikit-image/scikit-image/labels{/name}","releases_url":"https://api.github.com/repos/scikit-image/scikit-image/releases{/id}","deployments_url":"https://api.github.com/repos/scikit-image/scikit-image/deployments","created_at":"2011-07-07T22:07:20Z","updated_at":"2016-07-16T07:53:18Z","pushed_at":"2016-07-16T16:29:29Z","git_url":"git://github.com/scikit-image/scikit-image.git","ssh_url":"git@github.com:scikit-image/scikit-image.git","clone_url":"https://github.com/scikit-image/scikit-image.git","svn_url":"https://github.com/scikit-image/scikit-image","homepage":"http://scikit-image.org","size":75025,"stargazers_count":1165,"watchers_count":1165,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":586,"mirror_url":null,"open_issues_count":283,"forks":586,"open_issues":283,"watchers":1165,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-image/scikit-image/pulls/2190"},"html":{"href":"https://github.com/scikit-image/scikit-image/pull/2190"},"issue":{"href":"https://api.github.com/repos/scikit-image/scikit-image/issues/2190"},"comments":{"href":"https://api.github.com/repos/scikit-image/scikit-image/issues/2190/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-image/scikit-image/pulls/2190/comments"},"review_comment":{"href":"https://api.github.com/repos/scikit-image/scikit-image/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scikit-image/scikit-image/pulls/2190/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-image/scikit-image/statuses/1c38da0fca2c8b7a461f6f139286996d9484dd4b"}}}}
{"actor":{"display_login":"sciunto"}}