Repository navigation
Wavelet denoising in YCbCr color space - #2240
Conversation
Current coverage is 90.69% (diff: 100%)@@ master #2240 diff @@
==========================================
Files 304 304
Lines 21452 21476 +24
Methods 0 0
Messages 0 0
Branches 1842 1850 +8
==========================================
+ Hits 19454 19478 +24
Misses 1658 1658
Partials 340 340
|
|
Hmm, I honestly thought this would look better. I've seen wavelet denoising do an amazing job at eliminating both luminance and color noise, so it's possible. None of these are quite the right approach, so I was wrong about YCbCr. @scikit-image/core any other suggestions? |
|
In my previous implementation, I was only denoising the Y color plane. On my local machine (nothing pushed yet), I'm denoising separately for all 3 color planes, Cb and Cr included. I'm unsure how to integrate this with specifying the noise variance; how does the noise variance change in each new color plane? That's definitely not global across different color planes. In doing this, I can obtain the following result: @JDWarner is what you were expecting? The luminance is reduced (in the image above there's less red, in astronaut there's less orange, etc) but there is more detail. |
|
I've added a keyword argument to In doing this, I also allow the noise st.devs to be either a scalar or a list of noise levels in each color plane. It is still possible to keep the same behavior of plain wavelet thresholding without any conversion to any colorspaces with Do we want to keep going down this path? It seems like this should be in every denoise function, but it also took me a while to figure how properly denoise an image in YCbCr and have it look good. Maybe a good halfway point is having an example in the documentation of YCbCr, but I'd like for that to be default. |
|
@stsievert Hi! |
e20ed08 to
d839987
Compare
|
@soupault I've rebased and have allowed edits from maintainers. I had to make some modifications to the if-statement logic to allow sensible denoising when the RGB colorspace is specified. This commit is still a WIP; the code is not clean. If we decide we want to integrate, I can clean up. I have verified that incorporating the changes still yields a correct result. The docs should reflect comparison between RGB and YCbCr denoising. img = data.chelsea()[:450, :450]
img = img_as_float(img)
sigma = 0.8*img.std()
noisy = util.random_noise(img, var=sigma**2)
denoised = [('original', img), ('noisy' , noisy),
('ycbcr' , denoise_wavelet(noisy)),
('rgb' , denoise_wavelet(noisy, colorspace='rgb'))] |
|
@stsievert very nice results!
Whichever way we choose to go in, any general purpose color conversion functions/context managers/whatever have to be put under @scikit-image/core more opinions on this? |
|
To my eyes, the RGB denoising looks better than the YCbCr! Is it just my inexperienced visual system playing tricks on me? I would improve this PR by changing the docstring part that says "denoising is often done in YCbCr" to an actual justification + reference as to why that would be the case. As to @soupault's suggestions/questions:
|
|
Look again, @jni - this is an excellent and compelling example. The goal isn't maximizing the amount of noise removed, it's addressing the color accuracy problems introduced by denoising. YCbCr does this beautifully; RGB keeps a significant amount of incorrect chroma as well as preserves much less texture/detail. When you denoise, you need to tailor your methods to your noise. The way this example is structured, we add a lot of chroma noise. In other words, the noise is random and uncorrelated between channels, That gives you the color mishmash shown in the raw noisy image. Another example might deal exclusively with luminance noise, but that's out of the scope of this PR. YCbCr is much better than RGB for chroma noise. The result for YCbCr is true to the original image's color, and that's the point of the example. RGB denoising, when turned up high enough, can sort of smear this over at the expense of details - but it never quite works, color accuracy always suffers, and you lose both texture and detail. RGB never gets as good as YCbCr. Look at them both at 100-200%, comparing the out-of-focus bokeh areas, and you'll see this. Because it's better suited to this noise, YCbCr is also preserving more detail at the same denoising strength. If you thought the best result would be the smoothest, RGB might at first glance appear ahead - but it isn't. @soupault - Assumptions are dangerous. Multichannel images are not necessarily RGB[A], consider NASA cameras at arbitrary wavelengths as well as medical images. Users should be informed how this would best be used, examples go a long way, but ultimately they are responsible to make sure their data is preprocessd appropriately. Context managers for this kind of thing quickly lead toward pipeline workflows. VTK and similar use these, and they have benefits, but that philosophy is not at all easily integrated into scikit-image given the choices we've made to date. That doesn't mean it's wrong; we could discuss how that would look, but it's out of scope for this PR. Feel free to raise that as a separate Issue (or Project) for consideration, but let's keep the discussion narrowly focused on the example here. Finally, as far as my review is concerned: There are a few minor test suite complaints which should be simple to address. |
|
@JDWarner thanks for the write-up. After a second pass I agree with you, and notice the aberrations introduced by the RGB denoising. I fell for the old "crank up the TV saturation in the store" trick. =) Nevertheless, I think this would be valuable information to put in the docstring, perhaps in slightly more condensed form. =) And with a reference! I actually have no idea what the YCbCr colorspace is. |
|
I'm also hesitant to include my current approach: this method is better suited for a context manager and I don't want to implement more than I need to. At first, I was only planning on mentioning this in the doc examples but made more changes because I ran into issues with converting and 0/1 scaling in the skimage workflow. Sounds like we've settled on But looking at skimage.segmentation.slic, they have |
@jni I actually think that it is better to have these things explicit. Keeping our images in pure numpy-arrays doesn't mean that we have to avoid the idea of metadata handling. With the current state of affairs, either we should have all functions taking @stsievert I've given this one more round, and I'd agree with your proposal to have |
|
@soupault Yes, I am actually (mostly) a fan of (img, md) tuples as a standard thing in scikit-image. But imho that needs to be implemented in a giant sprint so that the interface is consistent throughout scikit-image, rather than in a PR about one specific feature. I think there's an issue open about metadata handling. |
| multichannel : bool, optional | ||
| Apply wavelet denoising separately for each channel (where channels | ||
| correspond to the final axis of the array). | ||
| convert2ycbcr : bool, options |
| convert2ycbcr : bool, options | ||
| If True do the wavelet denoising in the YCbCr colorspace (typically) | ||
| instead of the RGB color space. This typically results in better | ||
| performance for RGB images (default: False). |
There was a problem hiding this comment.
Please, remove (default: False)
| [0, 1] depending on the input image range. | ||
|
|
||
| Wavelet denoising is often done in the YCbCr colorspace. It is assumed the | ||
| input image is in RGB. If ``colorspace in {None, 'rgb'}``, no colorspace |
There was a problem hiding this comment.
There is no such parameter anymore.
| out = _wavelet_threshold(img, wavelet=wavelet, mode=mode, | ||
| sigma=sigma, wavelet_levels=wavelet_levels) | ||
| if convert2ycbcr: | ||
| if type(sigma) in {float, int, complex}: |
There was a problem hiding this comment.
Could we just do this once somewhere?
| out = color.rgb2ycbcr(img) | ||
| for i in range(3): | ||
| # renormalizing this color channel to live in [0, 1] | ||
| min, max = out[..., i].min(), out[..., i].max() |
There was a problem hiding this comment.
min, max are reserved built-ins. Please, use another variable names.
| else: | ||
| out = _wavelet_threshold(img, wavelet=wavelet, mode=mode, | ||
| sigma=sigma, wavelet_levels=wavelet_levels) | ||
| if convert2ycbcr: |
There was a problem hiding this comment.
Hmmm... Under else? Not a multichannel?
soupault
left a comment
There was a problem hiding this comment.
More comments on the implementation.
| mode=mode, sigma=sigma, | ||
| mode=mode, sigma=sigma[c], | ||
| wavelet_levels=wavelet_levels) | ||
| elif convert2ycbcr: |
There was a problem hiding this comment.
I mean aren't we expecting multichannel image here?
if multichannel:
if convert2ycbcr:
...
else:
...
else:
There was a problem hiding this comment.
If we're expecting multichannel, why enforce that it's specified? In the docs we could add that convert2ycbcr implies multichannel.
There was a problem hiding this comment.
"explicit is better than implicit". This way it is clearer for the user, and is easier for the developer to be refactored/deprecated in case of any architectural changes.
| The noise is represented by small values in the wavelet domain which are set to | ||
| 0. | ||
|
|
||
| In color images, wavelet denoising is typically done in the YCbCr color space |
There was a problem hiding this comment.
Is it possible to add a link to https://en.wikipedia.org/wiki/YCbCr in this sentence please?
| but it is cast into an ndarray of floats for the computation | ||
| of the denoised image. | ||
| sigma : float, optional | ||
| sigma : float, list, optional |
There was a problem hiding this comment.
According to numpy docstring format is should be float or list.
| correspond to the final axis of the array). | ||
| convert2ycbcr : bool, optional | ||
| If True and multichannel True, do the wavelet denoising in the YCbCr | ||
| colorspace (typically) instead of the RGB color space. This typically |
| out[..., c] = _wavelet_threshold(img[..., c], wavelet=wavelet, | ||
| mode=mode, sigma=sigma, | ||
| wavelet_levels=wavelet_levels) | ||
| if multichannel or convert2ycbcr: |
There was a problem hiding this comment.
if multichannel: should be enough.
ac02be9 to
e5a510c
Compare
|
@stsievert I kindly ask you to rebase onto |
9432434 to
290dc58
Compare
|
@stsievert Perfect, thanks! The tests are passing. |
BUG: typo BUG: fixes the test to test right sigma BUG: removes long BUG: test typo
logic change; nest convert2ycbcr if inside multichannel if TST: remove test args -- no test perform BUG: sigma list formation in correct place also properly checks for type(sigma) == number BUG: typo (number => numbers) BUG with multichannel=True and sigma=None BUG: forgot to pass multichannel
12983d5 to
5a36da2
Compare
BUG: removes `colorspace` kwarg from denoise_wavelet in examples MAINT: either convert2ycbcr OR multichannel BUG: syntax BUG: syntax MAINT: explicit is better than implicit DOC: reformats docstrings
|
@scikit-image/core one more person to review? |
|
awesome. I merge. Thanks @stsievert and to the other reviewers. |



Description
This documents the process for doing denoising a color image in the YCbCr color space (aka only denoising the Y color channel).
This also shows the comparison between denoising in RGB and denoising in YCbCr. The example shown in the docs is shown below.
Checklist
./doc/examples(new features only)[For detailed information on these and other aspects see scikit-image contribution guidelines]
Possible enhancements
denoise_waveletto denoise a color image in the YCbCr color space?References
This is documentation was suggested by #2190 (comment)
Example added to docs
...but formatted differently