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.
Now lets "cartoonize" the image with a bilateral filter. Notice how edges in the image are preserved by the bilateral filter.
Contents
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;
preview(camera)

Read input image from webcam
You then use the snapshot function to grab an input frame from the webcam.inputImage = snapshot(camera);
figure;
imshow(inputImage);title('Input Image');
Convert 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)); figure; subplot(1,2,1); imshow(inputImage); title('Original Image'); subplot(1,2,2); imshow(cartoonImage); 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
- Category:
- Picks
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.