• Stars
    star
    100
  • Rank 330,075 (Top 7 %)
  • Language
    Swift
  • Created almost 9 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Syntactic Sugar for Accelerate/vImage and Core Image Filters

ShinpuruImage

Syntactic Sugar for Accelerate/vImage and Core Image Filters

Screenshot

ShinpuruImage offers developers a consistent and strongly typed interface to Apple's Core Image and vImage/Accelerate image filters without the need for boilerplate code.

ShinpuruImage filters are implemented as extensions to UIImage and can be chained together with a super easy syntax:

        let image = UIImage(named: "vegas.jpg")!
            .SIFastBlur(width: 10, height: 10, backgroundColor: UIColor.redColor())
            .SIMonochrome(color: UIColor.yellowColor(), intensity: 1)
            .SIRotate(angle: 0.3, backgroundColor: UIColor.purpleColor())

Installation

ShinpuruImage consists of three Swift files and to use ShinpuruImage in your own project, you simply need to copy:

Filters

Photo Effects

  • func SIPhotoEffectNoir() -> UIImage Applies a preconfigured set of effects that imitate black-and-white photography film with exaggerated contrast.
  • func SIPhotoEffectChrome() -> UIImage Applies a preconfigured set of effects that imitate vintage photography film with exaggerated color.
  • func SIPhotoEffectFade() -> UIImage Applies a preconfigured set of effects that imitate vintage photography film with diminished color.
  • func SIPhotoEffectInstant() -> UIImage Applies a preconfigured set of effects that imitate vintage photography film with distorted colors.
  • func SIPhotoEffectMono() -> UIImage Applies a preconfigured set of effects that imitate black-and-white photography film with low contrast.
  • func SIPhotoEffectProcess() -> UIImage Applies a preconfigured set of effects that imitate vintage photography film with emphasized cool colors.
  • func SIPhotoEffectTonal() -> UIImage Applies a preconfigured set of effects that imitate black-and-white photography film without significantly altering contrast.
  • func SIPhotoEffectTransfer() -> UIImage Applies a preconfigured set of effects that imitate vintage photography film with emphasized warm colors.

Color Effects

  • func SIFalseColor(#color0: UIColor, color1: UIColor) -> UIImage Maps luminance to a color ramp of two colors.
  • func SIPosterize(#levels: Int) -> UIImage Remaps red, green, and blue color components to the number of brightness values you specify for each color component.
  • func SIMonochrome(#color: UIColor, intensity: Float) -> UIImage Remaps colors so they fall within shades of a single color.

Stylize

  • func SIBloom(#radius: Float, intensity: Float) -> UIImage Softens edges and applies a pleasant glow to an image.
  • func SIGloom(#radius: Float, intensity: Float) -> UIImage Dulls the highlights of an image.
  • func SIPixellate(#scale: Float) -> UIImage Makes an image blocky by mapping the image to colored squares whose color is defined by the replaced pixels.

Blur

  • func SIGaussianBlur(#radius: Float) -> UIImage Spreads source pixels by an amount specified by a Gaussian distribution.

Color Adjustment

  • func SIColorControls(#saturation: Float, brightness: Float, contrast: Float) -> UIImage Adjusts saturation, brightness, and contrast values.
  • func SIExposureAdjust(#ev: Float) -> UIImage Adjusts the exposure setting for an image similar to the way you control exposure for a camera when you change the F-stop.
  • func SIGammaAdjust(#power: Float) -> UIImage Adjusts midtone brightness.
  • func SIHueAdjust(#power: Float) -> UIImage Changes the overall hue, or tint, of the source pixels.
  • func SIVibrance(#amount: Float) -> UIImage Adjusts the saturation of an image while keeping pleasing skin tones.
  • func SIWhitePointAdjust(#color: UIColor) -> UIImage Adjusts the reference white point for an image and maps all colors in the source using the new reference.

Morphology functions

  • func SIDilateFilter(#kernel: [UInt8]) -> UIImage Dilates an object
  • func SIErodeFilter(#kernel: [UInt8]) -> UIImage Erodes an object
  • func SIMaxFilter(#width: Int, height: Int) -> UIImage The morphological operation Max is a special case of the dilation operation whereby all the elements of the kernel have the same value.
  • func SIMinFilter(#width: Int, height: Int) -> UIImage The morphological operation Min is a special case of the erosion operation whereby all the elements of the kernel have the same value.

High Level Geometry Functions

  • func SIScale(#scaleX: Float, scaleY: Float) -> UIImage Resize the input image
  • func SIRotate(#angle: Float, backgroundColor: UIColor = UIColor.blackColor()) -> UIImage Rotate the input image around a center point by any amount
  • func SIRotateNinety(rotation: RotateNinety, backgroundColor: UIColor = UIColor.blackColor()) -> UIImage Rotate an image by 0, 90, 180 or 270 degrees
  • func SIHorizontalReflect() -> UIImage Reflect an image across a mirror plane at the center of the image
  • func SIVerticalReflect() -> UIImage Reflect an image across a mirror plane at the center of the image

Convolution

  • func SIBoxBlur(#width: Int, height: Int, backgroundColor: UIColor = UIColor.blackColor()) -> UIImage Apply a mean filter to the image.
  • func SIFastBlur(#width: Int, height: Int, backgroundColor: UIColor = UIColor.blackColor()) -> UIImage Apply a tent filter to the image.
  • func SIConvolutionFilter(#kernel: [Int16], divisor: Int, backgroundColor: UIColor = UIColor.blackColor()) -> UIImage All four channel convolution function

Histogram

  • func SIHistogramCalculation() -> (alpha: [UInt], red: [UInt], green: [UInt], blue: [UInt]) Returns a tuple containing four arrays of 256 UInt representing the histogram of the supplied image

Demo Application

The demo app contains three components:

  • RotateAndScale - demonstrates chained SIScale() and SIRotate() controlled by three numeric sliders
  • ColorControls - demonstrates SIColorControls controlled by three numeric sliders
  • Histogram - uses ios-charts to demonstrate the use of SIHistogramCalculation and the performance benefits of using fast filter chaining.

Filter Chaining

For the best perfomance when chaining image filters together, Shinpuru Image includes a SIFastChainableImage type that prevents the chain from converting to UIImage between individual chained filters. The syntax is slightly different and requires the source UIImage to be cast to a SIFastChainableImage and the final output to be converted back to a UIImage:

            let image = UIImage(named: "oculista.jpg")!

            let chained = SIFastChainableImage(image: image)
                .SIPhotoEffectFade()
                .SIGaussianBlur(radius: 5)
                .SIFalseColor(color0: UIColor.blueColor(), color1: UIColor.redColor())
                .SIPixellate(scale: 5)
                .toUIImage()

For complex chains of filters, using SIFastChainableImage can be four or fives times faster. However, in this mode, color management is turned off.

Blurring Images

To blur an image you have three options: a true Gaussian blur (SIGaussianBlur), a box blur (SIBoxBlur) and ShinpuruImage fast blur (SIFastBlur) which is based on vImageTentConvolve. Of the three, I've found SIBoxBlur to be the fastest and SIGaussianBlur to be the slowest. It's worth using measureBlock() to do your own performance testing.

More Repositories

1

Filterpedia

Core Image Filter Explorer & Showcase
Swift
2,241
star
2

Blurable

Apply a Gaussian Blur to any UIView with Swift Protocol Extensions
Swift
932
star
3

Plum-O-Meter

3D Touch Application for Weighing Plums (and other small fruit!)
Swift
528
star
4

ParticleLab

Particle system that's both calculated and rendered on the GPU using the Metal framework
Swift
493
star
5

sweetcorn

Node based CIKernel creation
Swift
261
star
6

SmoothScribble

Smooth Drawing for iOS in Swift with Hermite Spline Interpolation
Swift
241
star
7

MarkingMenu

Swift MarkingMenu
Swift
217
star
8

CartoonEyes

Composite Cartoon Eyes over Face from Front Camera with CoreImage
Swift
163
star
9

LiveCameraFiltering

Demonstration of applying a Comic Book filter to a live video feed
Swift
151
star
10

SwiftSpace

CoreMotion Controlled Drawing in 3D Space
Swift
150
star
11

ShinpuruLayout

Simple Layout in Swift using HGroups & VGroups
Swift
128
star
12

ForceSketch

Demonstration of a Sketching App Using 3D Touch
Swift
109
star
13

ParticleCam

Metal based particle system influenced by iPad camera
Swift
102
star
14

ShinpuruNodeUI

Node Based UI Component Written in Swift
Swift
98
star
15

ValentinesSwift

You love Swift & Swift loves you!
Swift
89
star
16

CoreImageForSwiftPlaygrounds

CoreImage For Swift Playgrounds
Swift
88
star
17

SnapSwift

SnapSeed Style Popup Menu for iOS
Swift
87
star
18

CoreImageHelpers

Syntactic sugar for displaying CIImage using OpenGL and grabbing CIImages from iOS cameras
Swift
73
star
19

VideoEffects

iPad app to open videos from file system, apply Core Image filters and save result back SavedPhotosAlbum
Swift
71
star
20

MetalReactionDiffusion

Reaction Diffusion using Swift & Metal
Swift
69
star
21

AudioKitNodality

AudioKitNodality
Swift
68
star
22

3D-Motion-Controller

Using MultipeerConnectivity and CoreMotion to allow an iPhone to act as a 3D mouse for an iPad app
Swift
67
star
23

Globular

Colourful SpriteKit Metaballs Controlled by 3D Touch
Swift
67
star
24

Interpolation-Playground-

Swift playground demonstrating lerp, smooth step, Catcall-Rom and others!
Swift
63
star
25

Nebula

Core Image Volumetric Rendering
Swift
60
star
26

MetalKit-Particles

An implementation of my Metal ParticleLab component for OS X 10.11 and iOS 9
Swift
57
star
27

AdvancedTouch

Swift Advanced Touch Handling in iOS9: Coalescing and Prediction
Swift
50
star
28

MetalVideoCapture

Demo of Creating a Metal Texture from AVCaptureSession and Applying MetalPerformanceShaders In-Place
Swift
50
star
29

AudioSynthesis

CoreAudio for Sound Synthesis Demonstration
Swift
48
star
30

UIScrollViewDemo

A Node Based User Interface implemented with the Presentation Model Pattern
Swift
41
star
31

SwiftCFD

CPU Based Navier Stokes Computational Fluid Dynamics in Swift for iOS
Swift
41
star
32

StrangeAttractor

Lorenz Attractor in Swift & Metal
Swift
39
star
33

Spritely

Using SpriteKit events to trigger AudioKit sounds
Swift
39
star
34

SwiftGoo

Kai's Power Tools Goo - written in Swift!
Swift
38
star
35

Scribe

Handwriting and Stroke Recognition in Swift
Swift
37
star
36

DeepPressGestureRecognizer

UIGestureRecognizer for recognising deep press 3D Touch on iPhone 6s
Swift
35
star
37

MercurialPaint

Mercurial Painting using Metal and Core Image
Swift
33
star
38

PencilController

Using Apple Pencil as a 3D Controller for Image Editing
Swift
30
star
39

CoreImagePerspectivePlayground

Core Image Perspective Playground
Swift
28
star
40

GameplayKitAgents

A Look at Agents, Goals & Behaviours in GameplayKit
Swift
27
star
41

CoreImageFluidDynamics

CIFilter / CIKernel based fluid dynamics
Swift
26
star
42

SceneKitMaterialEditor

A very simple app for editing SceneKit materials
Swift
26
star
43

DepthOfFieldExplorer

SceneKit Depth of Field Demonstration
Swift
26
star
44

ChromaTouch

Introduction to 3D Touch in Swift with Peek, Pop and Preview Actions
Swift
26
star
45

3D-ReTouch

Experimental Retouching App using 3D Touch
Swift
26
star
46

FurrySketch

Using Apple Pencil's Azimuth & Altitude Data for Creating Directional Furry Brush Strokes
Swift
26
star
47

Purikura

Bulging eyes Purikura effect
Swift
25
star
48

SkyCubeTextureDemo

A demonstration of using MDLSkyCubeTexture in a SceneKit project
Swift
25
star
49

CIImage-UIImage-Orientation-Fix

Demo of UIImageOrientation to TIFF Orientation conversion that fixes orientation issues when creating CIImage from UIImage
Swift
24
star
50

CoreImageConvolutionExplorer

CoreImageConvolutionExplorer
Swift
24
star
51

ImageToneCurveEditor

Project demonstrating the use of CIToneCurve
Swift
24
star
52

PencilSynth

An Audiokit Synthesiser Controller by Apple Pencil
Swift
23
star
53

CoreImageTransitionExplorer

Simple slide show demonstration using Core Image Transitions and PHImageManager
Swift
22
star
54

SceneKitProceduralNormalMapping

Demo of Core Image filter to create SceneKit normal maps from procedural bump maps
Swift
22
star
55

ForceZoom

Zoom Into Image Details using 3D Touch Peek
Swift
21
star
56

PendulaTone

Audio driven by pendulum waves
Swift
20
star
57

PhotoBrowserDemo

A Swift image browser/picker for use with PHImageManager
Swift
19
star
58

Rotatable

Swift Protocol Extension to Rotate any UIView
Swift
19
star
59

Protocol-Extension-Event-Dispatcher

Implementation of EventDispatcher pattern using Swift Protocol Extensions
Swift
18
star
60

ImageProcessingWithMetal

An introduction to image processing with Metal and Swift
17
star
61

WheelTone

Audio synthesis driven by a network of friction gears
Swift
15
star
62

FilterChainingDemo

Demonstration of chaining a series of CIFilters together
Swift
15
star
63

ConvolutionExplorer

vImage / Accelerate convolution filter in Swift
Swift
14
star
64

Bokeh

Demonstration of simulation of hexagonal bokeh using Metal Performance Shaders
Swift
14
star
65

SpriteKitMotionBlur

SpriteKitMotionBlur
Swift
14
star
66

FMNixieDisplay

Nixie Tube Display Component on Swift
Swift
14
star
67

MercurialText

Embossed Type using SceneKit and CIShadedMaterial
Swift
14
star
68

GPUImageDemo

GPUImageDemo
Swift
12
star
69

Christmas-Tree-Bowling

Apple Pencil Controlled Christmas Tree Bowling!
Swift
12
star
70

GestureRecognizer

Demo of custom UIGestureRecognizer
Swift
11
star
71

NumericDialDemo

NumericDialDemo
Swift
11
star
72

ProgSConCompanion

ProgSConCompanion
Swift
10
star
73

MetalKit-ReactionDiffusion

Reaction diffusion simulation using Metal Kit with parameter gradients controlled by the camera
Swift
10
star
74

CoreImageReactionDiffusion

Gary-Scott reaction Diffusion Implemented as a Core Image CIKernel
Swift
10
star
75

PencilScale

Using an Apple Pencil with an iPad Pro as an electronic scale
Swift
9
star
76

GrayScott

Non GPU GrayScott Reaction Diffusion Experiment Using NSOperation
Swift
9
star
77

FMHierarchicalSelector

Hierarchical Selector Component based on UIPickerView & UICollectionView
Swift
9
star
78

NemoCam

Virtual underwater video recording using Filterpedia's Caustic Refraction Filter
Swift
9
star
79

InnerPlanetCurves

Draws Cubic Bezier Curve Between Earth & Venus Using Mercury & Mars as Control Points
Swift
8
star
80

BristlePaint

Embossed Painting with Individual Bristles using SpriteKit Normal Mapping
Swift
8
star
81

StackView

A first play with Swift 2's UIStackView
Swift
8
star
82

MPS_Equalisation

Demonstration of Histogram Equalisation with Metal Performance Shaders
Swift
7
star
83

CoreImageReductionFilterExplorer

App demonstrating extracting color data from CIAreaAverage and displaying Core Image Histograms
Swift
7
star
84

Vertigo

Vertigo inducing colourful painting...
Swift
6
star
85

CoreImageCathodeRayTube

Simple cathode ray tube simulation CIKernel processing live feed from iOS camera.
Swift
5
star
86

Swift3_CoreImageDemo

Swift3_CoreImageDemo
Swift
4
star
87

LondonSwiftDemo

Demo Project for London Swift
Swift
4
star
88

Swarm-Chemistry-GCD

New Version of Swarm Chemistry, using GCD and Bitmap creation
Swift
4
star
89

PHImageManagerTwitterDemo

Demonstration of PHImageManager and Twitter Integration
Swift
3
star
90

CoreImageVoronoi

Full screen animated Moroni noise!
Swift
3
star
91

PhysicsExperiments

Swift
3
star
92

InlineMethodTest

Testing performance of inline code versus instance methods versus class methods
Swift
3
star
93

StPatricksDay

Happy St Patricks Day!
Swift
3
star
94

HisogramSpecificationBlendDemo

Demonstration of Histogram Specification for Image Composition
Swift
2
star
95

SelectorPlayground

Demonstration of `#selector` expression
Swift
2
star
96

FlexMonkeyExamples

Files to support posts in http://flexmonkey.blogspot.co.uk/
Swift
2
star
97

SwiftExperiments

Swift experiments
Swift
1
star
98

Swarm-Chemistry

DEPRECATED: Multithreaded CPU based Swarm Chemistry
Swift
1
star
99

GaussianPlayground

Demonstration of creating a Gaussian blur using separate vertical and horizontal convolution filters.
Swift
1
star
100

ArraySpeedTest

Some simple tests looking at the performance of different techniques populating and interrogating arrays
Swift
1
star