Main Content

locallapfilt

Fast local Laplacian filtering of images

Description

example

B = locallapfilt(I,sigma,alpha) filters the grayscale or RGB image I with an edge-aware, fast local Laplacian filter. sigma characterizes the amplitude of edges in I. alpha controls smoothing of details.

B = locallapfilt(I,sigma,alpha,beta) filters the image using beta to control the dynamic range of A.

example

B = locallapfilt(___,Name=Value) uses name-value arguments to control advanced aspects of the filter.

Examples

collapse all

Import an RGB image

A = imread('peppers.png');

Set parameters of the filter to increase details smaller than 0.4.

sigma = 0.4;
alpha = 0.5;

Use fast local Laplacian filtering

B = locallapfilt(A, sigma, alpha);

Display the original and filtered images side-by-side.

imshowpair(A, B, 'montage')

Figure contains an axes object. The axes object contains an object of type image.

Local Laplacian filtering is a computationally intensive algorithm. To speed up processing, locallapfilt approximates the algorithm by discretizing the intensity range into a number of samples defined by the 'NumIntensityLevels' parameter. This parameter can be used to balance speed and quality.

Import an RGB image and display it.

A = imread('peppers.png');
figure
imshow(A)
title('Original Image')

Figure contains an axes object. The axes object with title Original Image contains an object of type image.

Use a sigma value to process the details and an alpha value to increase the contrast, effectively enhancing the local contrast of the image.

sigma = 0.2;
alpha = 0.3;

Using fewer samples increases the execution speed, but can produce visible artifacts, especially in areas of flat contrast. Time the function using only 20 intensity levels.

t_speed = timeit(@() locallapfilt(A, sigma, alpha, 'NumIntensityLevels', 20))  
t_speed = 0.0698

Now, process the image and display it.

B_speed = locallapfilt(A, sigma, alpha, 'NumIntensityLevels', 20);
figure
imshow(B_speed)
title(['Enhanced with 20 intensity levels in ' num2str(t_speed) ' sec'])

Figure contains an axes object. The axes object with title Enhanced with 20 intensity levels in 0.069841 sec contains an object of type image.

A larger number of samples yields better looking results at the expense of more processing time. Time the function using 100 intensity levels.

t_quality = timeit(@() locallapfilt(A, sigma, alpha, 'NumIntensityLevels', 100))
t_quality = 0.3255

Process the image with 100 intensity levels and display it:

B_quality = locallapfilt(A, sigma, alpha, 'NumIntensityLevels', 100);
figure
imshow(B_quality)
title(['Enhancement with 100 intensity levels in ' num2str(t_quality) ' sec'])

Figure contains an axes object. The axes object with title Enhancement with 100 intensity levels in 0.32546 sec contains an object of type image.

Try varying the number of intensity levels on your own images. Try also flattening the contrast (with alpha > 1). You will see that the optimal number of intensity levels is different for every image and varies with alpha. By default, locallapfilt uses a heuristic to balance speed and quality, but it cannot predict the best value for every image.

Import a color image, reduce its size, and display it.

A = imread('car2.jpg');
A = imresize(A, 0.25);
figure
imshow(A)
title('Original Image')

Figure contains an axes object. The axes object with title Original Image contains an object of type image.

Set the parameters of the filter to dramatically increase details smaller than 0.3 (out of a normalized range of 0 to 1).

sigma = 0.3;
alpha = 0.1;

Let's compare the two different modes of color filtering. Process the image by filtering its intensity and by filtering each color channel separately:

B_luminance = locallapfilt(A, sigma, alpha);
B_separate  = locallapfilt(A, sigma, alpha, 'ColorMode', 'separate');

Display the filtered images.

figure
imshow(B_luminance)
title('Enhanced by boosting the local luminance contrast')

Figure contains an axes object. The axes object with title Enhanced by boosting the local luminance contrast contains an object of type image.

figure
imshow(B_separate)
title('Enhanced by boosting the local color contrast')

Figure contains an axes object. The axes object with title Enhanced by boosting the local color contrast contains an object of type image.

An equal amount of contrast enhancement has been applied to each image, but colors are more saturated when setting 'ColorMode' to 'separate'.

Import an image. Convert the image to floating point so that we can add artificial noise more easily.

A = imread('pout.tif');
A = im2single(A);

Add Gaussian noise with zero mean and 0.001 variance.

A_noisy = imnoise(A, 'gaussian', 0, 0.001);
psnr_noisy = psnr(A_noisy, A);
fprintf('The peak signal-to-noise ratio of the noisy image is %0.4f\n', psnr_noisy);        
The peak signal-to-noise ratio of the noisy image is 30.0234

Set the amplitude of the details to smooth, then set the amount of smoothing to apply.

sigma = 0.1;
alpha = 4.0;

Apply the edge-aware filter.

B = locallapfilt(A_noisy, sigma, alpha);
psnr_denoised = psnr(B, A);
fprintf('The peak signal-to-noise ratio of the denoised image is %0.4f\n', psnr_denoised);
The peak signal-to-noise ratio of the denoised image is 32.3362

Note an improvement in the PSNR of the image.

Display all three images side by side. Observe that details are smoothed and sharp intensity variations along edges are unchanged.

figure
subplot(1,3,1), imshow(A), title('Original')
subplot(1,3,2), imshow(A_noisy), title('Noisy')
subplot(1,3,3), imshow(B), title('Denoised')

Figure contains 3 axes objects. Axes object 1 with title Original contains an object of type image. Axes object 2 with title Noisy contains an object of type image. Axes object 3 with title Denoised contains an object of type image.

Import the image, resize it and display it

A = imread('car1.jpg');
A = imresize(A, 0.25);
figure
imshow(A)
title('Original Image')

Figure contains an axes object. The axes object with title Original Image contains an object of type image.

The car is dirty and covered in markings. Let's try to erase the dust and markings on the body. Set the amplitude of the details to smooth, and set a large amount of smoothing to apply.

sigma = 0.2;
alpha = 5.0;

When smoothing (alpha > 1), the filter produces high quality results with a small number of intensity levels. Set a small number of intensity levels to process the image faster.

numLevels = 16;

Apply the filter.

B = locallapfilt(A, sigma, alpha, 'NumIntensityLevels', numLevels);

Display the "clean" car.

figure
imshow(B)
title('After smoothing details')

Figure contains an axes object. The axes object with title After smoothing details contains an object of type image.

Input Arguments

collapse all

Image to filter, specified as a 2-D grayscale image or 2-D RGB image.

Data Types: single | int8 | int16 | uint8 | uint16

Amplitude of edges, specified as a non-negative number. sigma should be in the range [0, 1] for integer images and for single images defined over the range [0, 1]. For single images defined over a different range [a, b], sigma should also be in the range [a, b].

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Smoothing of details, specified as a positive number. Typical values of alpha are in the range [0.01, 10].

ValueDescription
alpha less than 1Increases the details of the input image, effectively enhancing the local contrast of the image without affecting edges or introducing halos.
alpha greater than 1Smooths details in the input image while preserving crisp edges
alpha equal to 1The details of the input image are left unchanged.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Dynamic range, specified as a non-negative number. Typical values of beta are in the range [0, 5]. beta affects the dynamic range of A.

ValueDescription
beta less than 1Reduces the amplitude of edges in the image, effectively compressing the dynamic range without affecting details.
beta greater than 1Expands the dynamic range of the image.
beta equal to 1Dynamic range of the image is left unchanged. This is the default value.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: B = locallapfilt(I,sigma,alpha,ColorMode="separate") filters each color channel independently.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: B = locallapfilt(I,sigma,alpha,"ColorMode","separate") filters each color channel independently.

Method used to filter RGB images, specified as one of the following values. This argument has no effect on grayscale images.

ValueDescription
"luminance"locallapfilt converts the input RGB image to grayscale before filtering and reintroduces color after filtering, which changes the contrast of the input image without affecting colors.
"separate"locallapfilt filters each color channel independently.

Data Types: char | string

Number of intensity samples in the dynamic range of the input image, specified as "auto" or positive integer. A higher number of samples gives results closer to exact local Laplacian filtering. A lower number increases the execution speed. Typical values are in the range [10, 100]. If set to "auto", locallapfilt chooses the number of intensity levels automatically to balance quality and speed based on other parameters of the filter.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char | string

Output Arguments

collapse all

Filtered image, returned as a numeric array of the same size and data type as the input image, A.

References

[1] Paris, Sylvain, Samuel W. Hasinoff, and Jan Kautz. Local Laplacian filters: edge-aware image processing with a Laplacian pyramid, ACM Trans. Graph. 30.4 (2011): 68.

[2] Aubry, Mathieu, et al. Fast local laplacian filters: Theory and applications. ACM Transactions on Graphics (TOG) 33.5 (2014): 167.

Version History

Introduced in R2016b

expand all