Cocoa in the Shell

NYXImagesUtilities becomes NYXImagesKit

Few months ago I released NYXImagesUtilities, a set of categories to perform various operations on UIImage objects such as resizing, applying filters and more. Since then I didn’t update it, but today I’m proud to announce that I’ve been working a lot on it lately to add new stuff and to focus on performances. For this occasion I decided to rename it NYXImagesKit


The main idea was to focus on performances, how could I improve them ?

It turned out that Apple brought Accelerate.framework on iOS 4 so we can take advantages of vDSP functions. And it’s even better on iOS 5, because we now have access to Core Image and vImage APIs in Accelerate.

The second idea was to add some functionalities, especially filters because there were only 3, now there are 11 !

The code still requires at least iOS 4.2, and is fully ARC enabled. The license has not changed and is Simplified BSD.

So, what’s new ?!

I. UIImage+Enchancing

This is a new category which works only on iOS 5 because it uses Core Image. It is composed of two methods :



The names are pretty straightforward to guess what these methods do.

II. New filters

There are 8 new filters, let’s review them with Sarah Shahi as a sample image.

1. Brighten

This filter allows you to brighten or darken an image.

UIImage* brightened = [myImage brightenWithValue:13.0f];

The value should be in the range –255, 255.

2. Contrast adjustment

UIImage* contrasted = [myImage contrastAdjustmentWithValue:37.0f];

The value should be in the range –255, 255.

3. Edge detection

This filter is used to detect edges on an image.

UIImage* edge = [myImage edgeDetectionWithBias:0];

The bias value is only used on iOS 5.

4. Emboss

UIImage* emboss = [myImage embossWithBias:0];

The bias value is only used on iOS 5.

5. Gamma correction

UIImage* gammaCorrected = [myImage gammaCorrectionWithValue:2.0f];

Good values for the gamma correction are in the range 0.01, 8

6. Invert

This filter inverts the colours of an image.

UIImage* inverted = [myImage invert];

7. Sharpen

UIImage* sharpened = [myImage sharpenWithBias:0];

The bias value is only used on iOS 5.

8. Unsharpen

UIImage* unsharpened = [myImage unsharpenWithBias:0];

The bias value is only used on iOS 5.

III. New rotation methods

There are 2 new methods to rotate an image but they are only available on iOS 5 because they use vImage.



The difference between the other rotation methods is that the dimensions of the image won’t change (here 640x960), it’s the content that is being rotated, so the image is being truncated.

IV. Saving to

I added a simple method in UIImage+Saving to save an UIImage to the Photos application.

[myImage saveToPhotosAlbum];

What changed ?

So now let’s look at what has changed.

I. Blurring

I’m no longer using Jeff’s code to perform the gaussian blur, instead I rewrote the method using vDSP for iOS 4, and vImage for iOS 5.

Here is a quick benchmark on an iPhone 4S with the same image. With the old method the average time to blur the image was 4.0s, so it was very very slow.

On iOS 4 with vDSP it took about 0.67s, 6x times faster.

On iOS 5 with vImage it took about 0.19s, 21x times faster.

So it’s a very big win for this method.

II. Sepia filter

For iOS 4, I rewrote it using vDSP, it is more than 1.6x faster than before, so it’s a bit better.

The big win is on iOS 5, because it uses Core Image. As a result it is 1.6x faster than the iOS 4 method, that’s 2.5x faster than my original method. The other great thing is that the sepia tone from Core Image are nicer than with the manual method.


I hope you will like this new release, and feel free to contribute !

As before, you can get the code on github.