To Convert Image to Cartoon in iOS

To Convert Image to Cartoon in ios

For a much faster solution than ImageMagick, you could use the GPUImageToonFilter from my GPUImage framework:

Toon filtering

It combines Sobel edge detection with posterization of the image to give a good cartoon-like feel. As implemented in this framework, it's fast enough to run on realtime video from the iPhone's camera, and is probably at least an order of magnitude faster than something similar in ImageMagick. My framework's also a little easier to integrate with an iOS project than ImageMagick.

If you want more of an abstract look to the image, the GPUImageKuwaharaFilter converts images into an oil painting style, as I show in this answer.

How to cartoonize images using GPUImage framework?

Hey Coder ACJHP understanding your question,

First thing is why don't you use ToonFilter and after that apply KuwaharaFilter, it might work.
But Seeing your final image output, I'm sure that this can be done using AI and coreMl Models.

For your output you can see this link - https://blog.prismalabs.ai/diy-prisma-app-with-coreml-6b4994cc99e1

For coreml models use this link - https://likedan.github.io/Awesome-CoreML-Models/

here you can directly download the models and use it.
Hope this is helpfull

GPUImage Cartoon Filter parameters

As described in the read me for GPUImage https://github.com/BradLarson/GPUImage the cartoon filter takes the following parameters:

texelWidth:

texelHeight: These parameters affect the visibility of the detected edges

threshold: The sensitivity of the edge detection, with lower values being more sensitive. Ranges from 0.0 to 1.0, with 0.2 as the default

quantizationLevels: The number of color levels to represent in the final image. Default is 10.0

As for the exact levels required, you'll need to play around with that yourself and determine what best fits your need. There is no one size fits all solution to just turn any image into a cartoon, especially at the level of detail in the photo in that question.

How to cartoon-ify an image programmatically?

Here's some algorithms to play with:

  • Median or repeated box blur filter to obtain cartoonish color palette

    • Edit: Bilateral filtering should suit your needs even better
  • Min filter (zeroth percentile) to enhance some types of edges
  • Color image segmentation using either small subcube or sphere in the RGB color cube
  • Generic edge enhancement on segmented image using edge detection such as Sobel kernels or 8-way edge tracing
  • Composit blurred/median-filtered image with enhanced edges

These are fairly basic and all very easy to implement. Keep in mind that median and box blur filters can be implemented with linear time complexity w.r.t. the kernel radius.

More edits:

Once you get the idea of Huang's algorithm, implementing a box blur filter is a delicious piece of cake.

Reading material:

  • Fast Median and Bilateral Filtering (get the PDF)
  • Median Filtering Constant time (get the PDF) Note: I have an implementation of this in C# using Mono/SIMD to accelerate histogram coalescence, however it only seems better than the O(r) algorithm when the diameter exceeds ~60 pixels due to the comparable number of add/sub instructions (the break-even point), a C++ implementation is probably much better suited to harness SIMD.

Other reading materials include Gonzalez & Woods' Digital Image Processing (seems to be an older edition) for segmentation and edge tracing. 8-way edge tracing can be really hard to bend your head around (choosing between on-pixel or between-pixel edges and how to latch onto edges). I'd be happy to share some code, but the hundred-liners don't exactly fit smoothly in here.

How to convert Image to Bitmap and upload with Alamofire?

Ok, I've finally found my answer. I can't use Data to insert my image, instead I have to convert it again to string in order to post it to server.

let imageData: Data = imageSelected.jpegData(compressionQuality: 0.4) ?? Data()
let encodedImage: String = imageData.base64EncodedString()

Thanks for all the help!

Convert image to sketch and then cartoonify?

cartoonifying image

If you have a basic knowledge of C++, you can port this app for your need.
This application works real time. If you want to non-real time,than you can use bilateral filter against two medianBlurs at the bottom of function. That will give better results, but bad performance. But you need to use OpenCV in your application. If you want to make application with more functions, I will suggest you to do it.



Related Topics



Leave a reply



Submit