Project focused on Implementing the KuwaharaFilter in Swift for Apple Platforms
The current List of features is:
- CI Filter for all the Kuwahara Types (Standard, Generalized, Polynomial, and Anisotropic).
Zooming in is recommended!
- Photo by Nejc Košir on Pexels- Photo by Josh Hild on Pexels
To register the filter to use as any other CI do the following:
//AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
DispatchQueue.global().async {
FilterRegister.registerFilters()
}
return true
}
if you don't want or can't you can use:
let filter = Kuwara()
kuwahara.setValue(image, forKey: "inputImage")
let img = kuwahara?.outputImage //also optional remember to guard or don't I'm dev not a cop
All is Done via CIFilters meaning that you can use on any platform:
macOS:
import SwiftDithering
function yourFunction() {
//Highly Recommended
DispatchQueue.global().async{
guard let data: Data = NSImage(named:"testImage").tiffRepresentation,
let bit = NSBitmapImageRep(data: data),
let cImage: CIImage = CIImage(bitmapImageRep: bit),
let filter = CIFilter(name: "Kuwahara", parameters: ["inputImage": image])
else {
// handle this case
}
//can also add values like this
filter.setValue(value, forKey: "keyHere")
...
guard let out = filter.outputImage else {
//handle this
}
let rep = NSCIImageRep(ciImage: out)
let img = NSImage(size: rep.size)
img.addRepresentation(rep)
}
}
iOS:
import SwiftDithering
function yourFunction() {
//Highly Recommended
DispatchQueue.global().async{
guard let image: UIImage = UIImage(named:"testImage") else {
// handle this case
}
var ciImage:CIImage
if image.ciImage == nil {
guard let cg = image.cgImage else{
//handle
}
ciImage = CIImage(cgImage: image.cgImage)
} else{
ciImage = image.ciImage!
}
guard let filter = CIFilter(name: "Kuwahara", parameters: ["inputImage": ciImage]) else {
//handle this
}
//can also add values like this
filter.setValue(value, forKey: "keyHere")
...
guard let out = filter.outputImage,
let cg = CIContext().createCGImage(out, from: out.extent) else {
//handle this
}
let result = UIImage(cgImage: cg)
}
}
There's also a Sample app on the package(for now I plan to move it later) showing a basic implementation.
This project was possible by the great video and implementation of acerola and other resources that I found online.
Any images attached are not of my creation, I try to get everything from Pexels and credit everyone, if I forgot to do that please create an issue here on git, while is not mandatory according to Pexels rules and license is the least I can do for the amazing art these people created.