KuwaharaFilter

1.0.1

Project focused on Implementing the KuwaharaFilter in Swift for iOS and macOS
lugalu/KuwaharaFilter

What's New

v1.0.1

2024-04-04T21:58:28Z

In this version:

  • Fixed a bug regarding the size of the UI elements of the Sample App
  • Fixed a bug where some keys of the dictionary on the Sample App had typos
  • Fixed a bug where the Generalized shader was outputting an invisible pre-pass image.

Know bugs:

  • I have a specific image that outputs Mostly black, I'm still not sure if it's the format or some metadata that Core Image uses.

KuwaharaFilter

Project focused on Implementing the KuwaharaFilter in Swift for Apple Platforms

Features

The current List of features is:

  • CI Filter for all the Kuwahara Types (Standard, Generalized, Polynomial, and Anisotropic).

Image Examples

Zooming in is recommended!

- Photo by Nejc Košir on Pexels


- Photo by Josh Hild on Pexels

How to use

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.

Thanks

This project was possible by the great video and implementation of acerola and other resources that I found online.

Others

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.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 13:41:39 GMT-0900 (Hawaii-Aleutian Daylight Time)