0

How can apply a gaussian blur on an image in (CIE)LAB format? RGB can be blurred with rgb_blurred = skimage.filters.gaussian(lab), but that doesn`t work on LAB (because of its first channel). Is there a way to blur images without converting them back to rgb first, and then converting them back?

gerhard
  • 31
  • 6

1 Answers1

1

From the docs:

The multi-dimensional filter is implemented as a sequence of one-dimensional convolution filters.

Therefore you can apply the filter to Lab images too. Images are stored as numpy array, so if you want to apply the filter to some channel(s) only it's no problem using standard numpy indexing. In fact, blurring the a and b channels has little influence on the visual impression. The effect comes from blurring the L channel:

from skimage import data    
from skimage.filters import gaussian
from skimage.color import rgb2lab, lab2rgb
import matplotlib.pyplot as plt

img = data.astronaut()
lab = rgb2lab(img)
blurred = gaussian(lab, 5)
lab[:,:,0] = gaussian(lab[:,:,0], 5, preserve_range=True)

fig, ax = plt.subplots(1,3,figsize=(20,20))
ax[0].imshow(img)
ax[1].imshow(lab2rgb(blurred))
ax[2].imshow(lab2rgb(lab))
ax[0].set_title('Original')
ax[1].set_title('Blurred (entire image)')
ax[2].set_title('Blurred (L channel only)')

enter image description here

Please note that you must set the parameter preserve_range to True when applying the filter to a single channel, otherwise the result will be in the range of 0.0 to 1.0.

Stef
  • 28,728
  • 2
  • 24
  • 52
  • On Win10 Python36 I'm getting a `RuntimeWarning: Images with dimensions (M, N, 3) are interpreted as 2D+RGB by default. Use 'multichannel=False' to interpret as 3D image with last dimension of length 3`. But I don't want to use either. – gerhard Oct 06 '19 at 16:49
  • it's just a warning regarding the ambiguity, see the docs for parameter `multichannel` (the warning doesn't depend on the nature of the 3 channels, so you'll see it for RGB too). You can safely ignore it in our case as we have a 2D + color channel image (even if the channels are Lab instead of RGB, so the wording of the documentation is not entirely precise here). – Stef Oct 06 '19 at 17:13