New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RF: Use the average sigma in the mask. #1166
Conversation
Urgh. What's the right way to handle |
Maybe compute it explicitly instead of relying on nanmean? See http://stackoverflow.com/questions/5480694/numpy-calculate-averages-with-nans-removed for some variants. NB: Maybe a bit slower compared to np.nanmean, though. |
Codecov Report
@@ Coverage Diff @@
## master #1166 +/- ##
==========================================
+ Coverage 85.87% 85.87% +<.01%
==========================================
Files 221 221
Lines 27121 27128 +7
Branches 2776 2777 +1
==========================================
+ Hits 23290 23297 +7
Misses 3148 3148
Partials 683 683
Continue to review full report at Codecov.
|
bb0861a
to
48ab1c4
Compare
Thanks! That looks like a good solution to me. We can check whether numpy has a nanmean and use that one if possible, and otherwise use our own. What do you think? |
I liked it. 👍 |
What do you think about all the rest of this? Does it properly address #1131 in your opinion? |
3424c19
to
40149a5
Compare
Any more thoughts here? Seems like a bug we need to address before we can make a release. |
Anyone want to take a look at this? |
This looks good to me. @samuelstjean last chance to have a look at this PR. Does it address your issue #1131 correctly? |
It kinds of circumvent the problem. It is a less brute approach than picking the top left corner voxel, but it does cause problem if you have a large variation of the noise profile in your image. In that case, I would prefer if it just threw me an error that 3D arrays are not supported, and let me choose how to deal with it. For example, say I collected a noise measurement maps, extract local standard deviation from that, and feed it to the function. It will pick out the mean, and if the map is first masked (say by the scanner), then the median would probably be more appropriate to deal with those 3/4 of zeros values. As of now, I'll probably get a useless value, where the previous nlmeans version would happily work with my 3D map at each spatial location. Since that is now the case anymore, this would all happen silently and give me a less optimal result than I expected (true story, ask JC). |
I am back to this. I agree with @samuelstjean. It doesn't make sense to accept 3D sigma inputs to this function, because it will create a scalar under the hood using less than obvious rules. If you want to extract your sigma from a 3D volume, please do so before you feed it to this function. Simplified accordingly. |
204f94f
to
d321414
Compare
Now rebased on master |
@arokem @samuelstjean I'll be merging this PR on Monday. |
not sure it is fully finished in this current form, but the logic seems there |
Good comments both -- thanks for taking a look. I've removed the nanmean
cruft and added a check up-front for scalar sigma.
…On Sun, Apr 2, 2017 at 11:23 PM, Samuel St-Jean ***@***.***> wrote:
- the nanmean function serves no purpose
- not sure what error message it will throw you if you pass a 3D
array, and it might be hard to decipher
not sure it is fully finished in this current form, but the logic seems
there
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1166 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAHPNq2H5mKbsUisCZS1DWKiWDf6mGUyks5rsJBugaJpZM4LPuI8>
.
|
Instead of the value of sigma in the corner of the image.
f5ea84d
to
3d0ddfd
Compare
I added the option of passing in an array, if that array is a singleton. This fixes the test failures from yesterday (at least on my machine), and actually seems reasonable to me. I don't think that we need to adjust the documentation. The canonical input is still a single float, it's just that if you happen to deliver that single float in an array, we'll still accept that. Now also rebased on master |
@@ -81,7 +96,7 @@ def test_nlmeans_dtype(): | |||
S0 = 200 * np.ones((20, 20, 20), dtype=np.uint16) | |||
mask = np.zeros((20, 20, 20)) | |||
mask[10:14, 10:14, 10:14] = 1 | |||
S0n = non_local_means(S0, sigma=np.ones((20, 20, 20)), mask=mask, | |||
S0n = non_local_means(S0, sigma=1, mask=mask, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That probably fits on one line now.
@@ -39,7 +55,7 @@ def test_nlmeans_boundary(): | |||
|
|||
S0[:10, :10, :10] = 300 + noise[:10, :10, :10] | |||
|
|||
S0n = non_local_means(S0, sigma=np.ones((20, 20, 20)) * np.std(noise), | |||
S0n = non_local_means(S0, sigma=np.std(noise), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That probably fits on one line now.
Indeed. I've removed some other un-needed whitespace, while I was at it.
…On Fri, Apr 7, 2017 at 4:39 PM, Marc-Alexandre Côté < ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In dipy/denoise/tests/test_non_local_means.py
<#1166 (comment)>:
> @@ -39,7 +55,7 @@ def test_nlmeans_boundary():
S0[:10, :10, :10] = 300 + noise[:10, :10, :10]
- S0n = non_local_means(S0, sigma=np.ones((20, 20, 20)) * np.std(noise),
+ S0n = non_local_means(S0, sigma=np.std(noise),
That probably fits on one line now.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1166 (review)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAHPNsx9GfZcrVjVKmECDybI2_HNZahyks5rtskrgaJpZM4LPuI8>
.
|
RF: Use the average sigma in the mask.
Instead of the value of sigma in the corner of the image.
Addresses #1131