File Exchange Pick of the Week

Our best user submissions

Cartoonize an image using bilateral filtering

Avi's pick of the week is Bilateral Filtering by Douglas Lanman. Bilateral filtering is an edge-preserving smoothing filter that can be used for a wide variety of image processing tasks such as de-noising and tone mapping, another fun application of a bilateral filter is to "cartoonize" an image. In his submission Douglas provides a helper function that shows how a bilateral filter can be used to turn an image into a cartoon version of itself.


Connect to a webcam

Lets start by reading in an input image from a webcam using the webcam object in MATLAB. You can view the live stream using the preview function.
clear camera;
camera = webcam;

Read input image from webcam

You then use the snapshot function to grab an input frame from the webcam.
inputImage = snapshot(camera);
imshow(inputImage);title('Input Image');

POTW_Post_03Convert image into cartoon version of itself 

Now lets "cartoonize" the image with a bilateral filter. Notice how edges in the image are preserved by the bilateral filter.
cartoonImage = cartoon(im2double(inputImage));
title('Original Image');
title('Cartoon Image');


Other edge-preserving filters

If you are interested in using an edge-preserving filter I would recommend you try the new guided filter in the Image Processing Toolbox.
doc imguidedfilter
  • print
  • send email


To leave a comment, please click here to sign in to your MathWorks Account or create a new one.