Click here to Skip to main content
14,428,804 members

Cartoonizer - Convert Photos into Cartoon Like Images

Rate this:
4.80 (20 votes)
Please Sign up or sign in to vote.
4.80 (20 votes)
18 Apr 2011GPL3
Cartoonize images using multi-pass bilateral filter and edge detection
Image 1


This allows you to apply a painting/cartoon effect to an image by using a bilateral filter followed by edge detection.


This is not my original work. This is a port from VB6 to VB.NET. After extensively searching the net for a decent cartoon effect, I found this VB6 project by Roberto Mior and wanted to preserve it and protect it from going extinct due to it being written in VB6.

Using the Code

Larger images than 600x800 and larger Radius settings will make the filters process more pixels which in turn makes it slower.

The main workflow is:

GetBytesFromImage --> MultiPassBilateralFilter --> SobelEdgeDetectionFilter --> LuminanceSegmentationFIlter --> PutBytesIntoImage

All of the algorithms used here can be found easily on the internet.

Example workflow:

#Region "Cartoonize"
  Private Sub btCartoonize_Click(ByVal sender As System.Object, _
	ByVal e As System.EventArgs) Handles btCartoonize.Click
    PictureBox1.Image = mBitmap
  End Sub

  Private Sub DoPreEffect()
    Select Case cbPreEffect.SelectedIndex
      Case 0
      Case 1
      Case 2
      Case 3
        FX.MagneKleverBCS(tbBrightness.Value, tbContrast.Value, tbSaturation.Value)
    End Select
  End Sub

  Private Sub DoContour()
    If tbContourAmount.Value > 0 Then
      Select Case cbContourMethod.SelectedIndex
        Case 0
          FX.zEFF_Contour(tbContourAmount.Value, tbLumHue.Value / 100)
        Case 1
          FX.zEFF_ContourbyDOG(tbContourAmount.Value, tbContourThreshold.Value / 1000)
      End Select
    End If
  End Sub

  Private Sub ApplyContour()
    If tbContourAmount.Value > 0 Then
    End If
  End Sub

  Private Sub DoBilateral()
    FX.zEFF_BilateralFilter(tbRadius.Value, tbSpatialIntensity.Value / 10000, _
	tbSpatialSigma.Value / 100, tbIterations.Value, cbIntensityMode.SelectedIndex, _
	cbColorMode.SelectedIndex = 0)
  End Sub

  Private Sub DoQuantizeLuminance()
    FX.zEFF_QuantizeLuminance(tbSegments.Value, tbPresence.Value / 100, _
	tbRadius.Value, False)
  End Sub

  'Private Sub InitDomains()
  '  FX.zInit_IntensityDomain(tbSpatialIntensity.Value / 10000, 
  '  cbIntensityMode.SelectedIndex)
  '  FX.zInit_SpatialDomain(tbSpatialSigma.Value / 100)
  'End Sub

  Public Sub Cartoonize()
    Dim bm As Bitmap = mBitmap.Clone()
    'Uncomment this if you want to call this without the UI

    PictureBox1.Image = bm
    FX_PercDONE("", 0, 0)
  End Sub

#End Region		

Points of Interest

The main challenge of porting the code was to be aware of the effect of implicit casting in the VB6 code. The VB6 code is faster than the VB.NET code. To speed this up, the effect processing will need to be written in C++ to process the byte arrays.


  • 6th January, 2011: 1.0 - Initial revision from VB6 port
  • 18th April, 2011: Fixed bitmap byte access code - fix provided by gilchinger (bauer)


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Ron Schuler
Software Developer
United States United States
No Biography provided

Comments and Discussions

SuggestionThe process is called Rotoscoping Pin
J Snape15-Jul-13 21:28
professionalJ Snape15-Jul-13 21:28 
Questionnice work Pin
zitmen4-Feb-12 11:21
Memberzitmen4-Feb-12 11:21 
Questionhi ron... Pin
nozeup1-Jul-11 6:10
Membernozeup1-Jul-11 6:10 
GeneralPerormance of the code [modified] Pin
gilchinger18-Apr-11 1:06
Membergilchinger18-Apr-11 1:06 
GeneralRe: Perormance of the code Pin
Ron Schuler18-Apr-11 3:17
MemberRon Schuler18-Apr-11 3:17 
GeneralRe: Perormance of the code Pin
gilchinger18-Apr-11 5:09
Membergilchinger18-Apr-11 5:09 
GeneralRe: Perormance of the code Pin
Ron Schuler18-Apr-11 10:20
MemberRon Schuler18-Apr-11 10:20 
GeneralBug if Image.Width mod 8 not equal 8 ?! [modified] Pin
gilchinger15-Apr-11 10:19
Membergilchinger15-Apr-11 10:19 
GeneralRe: Bug if Image.Width mod 8 not equal 8 ?! Pin
Ron Schuler15-Apr-11 14:29
MemberRon Schuler15-Apr-11 14:29 
GeneralRe: Bug if Image.Width mod 8 not equal 8 ?! Pin
gilchinger16-Apr-11 6:55
Membergilchinger16-Apr-11 6:55 
GeneralRe: Bug if Image.Width mod 8 not equal 8 ?! Pin
Ron Schuler17-Apr-11 17:32
MemberRon Schuler17-Apr-11 17:32 
GeneralBug if Image.Width mod 8 not equal 8 ?! Pin
gilchinger18-Apr-11 4:49
Membergilchinger18-Apr-11 4:49 
Generalcool - have 5 Pin
Pranay Rana6-Jan-11 21:23
professionalPranay Rana6-Jan-11 21:23 
GeneralMy vote of 5 Pin
maq_rohit6-Jan-11 4:46
professionalmaq_rohit6-Jan-11 4:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 6 Jan 2011

Tagged as


69 bookmarked