Giter Club home page Giter Club logo

ios-image-filters's Introduction

ios-image-filters

These days everyone seems to want instagram-style filters for images on iPhone. The way to do this (I think) is to examine how people have implemented equivalent filters in Photoshop and code them in objective c. Unfortunately, the imaging libraries are all geared for gaming. For non-game developers who just want simple image processing, this is overkill.

It's like photoshop for the UIImage class!

I've worked hard to mimic the photoshop color adjustment menus. Turns out these are clutch in pretty much all the best image filters you can name right now (lomo, polaroid). For example, if you want to manipulate levels, here's your method, built straight onto the UIImage class:

- (UIImage*) levels:(NSInteger)black mid:(NSInteger)mid white:(NSInteger)white

An API just like that cool menu in Photoshop!

Want to do a curves adjustment to mimic a filter you saw on a blog? Just do this:

NSArray *redPoints = [NSArray arrayWithObjects:
        [NSValue valueWithCGPoint:CGPointMake(0, 0)],
        [NSValue valueWithCGPoint:CGPointMake(93, 76)],
        [NSValue valueWithCGPoint:CGPointMake(232, 226)],
        [NSValue valueWithCGPoint:CGPointMake(255, 255)],
        nil];
NSArray *bluePoints = [NSArray arrayWithObjects:
         [NSValue valueWithCGPoint:CGPointMake(0, 0)],
         [NSValue valueWithCGPoint:CGPointMake(57, 59)],
         [NSValue valueWithCGPoint:CGPointMake(220, 202)],
         [NSValue valueWithCGPoint:CGPointMake(255, 255)],
         nil];
UIImage *image = [[[UIImage imageNamed:@"landscape.jpg" applyCurve:redPoints toChannel:CurveChannelRed] 
 applyCurve:bluePoints toChannel:CurveChannelBlue];

The problem with my curves implementation is that I didn't use the same kind of curve algorithm as Photoshop uses. Mainly, because I don't know how, and other than the name of the curve (bicubic) all the posts and documentation I simply don't understand or cannot figure out how to port to iOS. But, the curves I use (catmull-rom) seem close enough.

How to integrate

Copy and paste the ImageFilter.* and Curves/* classes into your project. It's implemented a Category on UIImage.

How to use

#import "ImageFilter.h"
UIImage *image = [UIImage imageNamed:@"landscape.jpg"];
self.imageView.image = [image sharpen];
// Or
self.imageView.image = [image saturate:1.5];
// Or
self.imageView.image = [image lomo];

What it looks like

Screen shot 1 Screen shot 2

What is still broken

  • Gaussian blur is slow!
  • More blend modes for layers
  • Curves are catmull rom, not bicubic
  • So much else...

Other options

I tried, but mostly failed, to understand these libraries. Simple Image Processing is too simple, and uses a CPP class to accomplish its effects, as does CImg. I find the CPP syntax ghoulish, to say the least. I stared at the GLImageProcessing code for hours, and still don't understand what's going on. Guess I should have taken CS244a...

UPDATE: Core image filters in iOS5 are probably what you want to use going forward, though they are not backwards-compatible with iOS4 or earlier.

License

MIT License, where applicable. I borrowed code from this project: http://sourceforge.net/projects/curve/files/ , which also indicates it is MIT-licensed. http://en.wikipedia.org/wiki/MIT_License

There is also now code adapted from ImageMagick, whose license may be found at: http://www.imagemagick.org/script/license.php

ios-image-filters's People

Contributors

dbsgen avatar esilverberg avatar kiichi avatar kpmaalej avatar samuelsoe avatar unit51 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ios-image-filters's Issues

EXC_BAD_ACCESS problem

Hello,

I try to use ios-image-filters, but not everything is working for me.
Examplary if I call 'lomo' or 'adjust', Xcode says: EXC_BAD_ACCESS code=2 in line "pixelBuf[r] = SAFECOLOR(red * (1 + val.r));" for adjusting.
I'm using ARC, so I loaded classes with flag -fno-objc-arc, but even if I tried .xcodeproj attached to the package - it does the same.

I'm not very experienced in Obj-C, so could you help me to fix this issue?

filterCurve Method Deteriorates Image

I have tried to change RGB curves of an image but there seems to be a problem with "filterCurve" method. What it does is deteriorating shiny parts of the image. What I mean by shiny parts is where the sunlight shines and the area is white-ish than any other point area on image. Here is an example of what I am talking about; http://www.sensorprod.com/news/pr/2007-09_hydraulics/image01.jpg There you can see red and yellowish parts which are deteriorated. I ran into this issue when I play around with green curve. There is nothing wrong when I just change Red and Blue curves, but when it comes to Green one things change.

OSX Port

Hello,

Are you planning to port it to Mac?

Thanks for your work!

Hue Filter

Hey, its really a very nice work , helped me lot but i am finding them very hard ,look like i need another spoon feed of your code .

I am actually want to make hue filter like your filters ... but its like hitting a wall i am not getting anywhere. Can you tell me some algo of hue filter ?

Need new five filter that was added by instagram.

First of i would like to salute you for this amazing work.

We still need that new 5 filters which was recently added by instagram.

Can you please help one more time please ...

Once again salute for this work.

Zero dividing issue

There may be some zero dividing issues, for example:

void filterPosterize(UInt8 pixelBuf, UInt32 offset, void *context)
{
int levels = *((int
)context);
int step = 255 / levels;

int r = offset;
int g = offset+1;
int b = offset+2;

int red = pixelBuf[r];
int green = pixelBuf[g];
int blue = pixelBuf[b];

pixelBuf[r] = SAFECOLOR((red / step) * step);
pixelBuf[g] = SAFECOLOR((green / step) * step);
pixelBuf[b] = SAFECOLOR((blue / step) * step);

}

I once crashed on int step = 255 / levels;

Crashes

It crashes when pressing on Sharpen, Lomo filter.

Crash in iOS 6

In iOS 6 (Current version is Beta 3) the filter crashes when apply multiple filter continuously.

Let me give you a example, the crashes happen when apply the "Lomo" filter in your example code. In additional vignette, polaroidish crashes too.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.