Core Image

Discussion in 'Mac Programming' started by Blakeasd, Oct 1, 2010.

  1. Blakeasd macrumors 6502a

    Dec 29, 2009
    Does anyone know of a good Core Image tutorial? If you do please tell me. Thanks, Blake
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Describe your level of experience in graphics processing, specifically digital image filtering.

    I easily found suitable articles with the following search terms:
    core image tutorial
    One is even titled "Image Unit Tutorial".

    If those are unsuitable for you, then you'll have to explain what types of tutorials would be suitable, by summarizing your current level of graphics processing knowledge. I also suggest describing what your goal is: a single goal of creating a specific filter is different from becoming more skilled at all aspects of image processing, and combining existing filters differs from creating your own filters.
  3. Blakeasd thread starter macrumors 6502a

    Dec 29, 2009
    For my Core Image purposes I would just like to be a able to change the appearance of images for example. I would like to have a button that says motion blur. When it is clicked it takes my NSImage and applies the motion blur effect, do you know of any tutorial on how to do this using Obj-c and Cocoa (QuartzCore as well)
  4. MorphingDragon macrumors 603


    Mar 27, 2009
    The World Inbetween
    Thats done through CoreImage too and there's an image section at the back of one of the tutorials by Apple.
  5. Blakeasd thread starter macrumors 6502a

    Dec 29, 2009
    Non-Apple Sources

    Does anyone know of tutorials that are not made by Apple. I have seen those and they have not provided the proper information.
  6. jared_kipe macrumors 68030


    Dec 8, 2003
    I think you mean..
    They have not provided you with a code snippet you can cut and paste into your application and connect to a button?
  7. Blakeasd thread starter macrumors 6502a

    Dec 29, 2009
    No that's actually not what I mean...... Maybe I just don't like the way Apple Documentation is organized...... Some people are so ignorant because they have more experience in something. Instead of making snobby remarks perhaps it is best for you to use a more constructive response such as "I think you should read Apple Documentation as it provides more in-depth information on the subject". That is what a mature individual would say.
  8. NT1440 macrumors G4


    May 18, 2008
    Well, that's one sure fire way to eliminate the chances of anyone helping you...
  9. Blakeasd thread starter macrumors 6502a

    Dec 29, 2009
    Whenever I go on this forum I find a bunch of ignorant people. No one gets any help on this forum anyway. Instead people asking questions get a bunch of crap from some snobs:mad:. I can go to Apple's forums and everyone is very helpful. Im not sure why i'm even posting here anymore...
  10. jared_kipe macrumors 68030


    Dec 8, 2003
    I think you mean..
    Arrogant, because how can having more experience make you ignorant?
  11. robvas macrumors 68030

    Mar 29, 2009
    What are the Apple examples lacking?

    What is, or isn't happening when you try to integrate that code into your project? There are plenty of people here who wouldn't mind helping out if they saw the specific problem you are having.
  12. jared_kipe macrumors 68030


    Dec 8, 2003
    Well then, I do love a good mystery. Especially when someone cannot figure out Apple's documentation themselves.

    - Keep in mind before today I have NEVER looked at the documentation, nor have ever had any experience, in Core Image.

    First things first, I googled it and found this page.
    About a third of the way down the page is a code snippet as follows.
    NSURL *url; 
    CIImage *source;
    CIImage *result;
    CIFilter *hueAdjust;
    url = [NSURL fileURLWithPath:path];
    source = [CIImage imageWithContentsOfURL:url];
    hueAdjust = [CIFilter filterWithName:@"CIHueAdjust"];
    [hueAdjust setValue:source forKey:@"inputImage"];
    [hueAdjust setValue:[NSNumber numberWithFloat:2.094] forKey:@"inputAngle"];
    result = [hueAdjust valueForKey:@"outputImage"];
    Ah ha! I thought to myself, it appears that if we knew the name of the supposed "motion blur" filter and keys that it used to modify that blur then it should be trivial to implement. I opened Xcode, typed in CIFilter and option+doubleclicked it to bring up this Apple documentation (which I used for the rest of my little exercise)

    I wrote a little foundation program that goes like this..
    #import <Foundation/Foundation.h>
    #import <QuartzCore/QuartzCore.h>
    int main (int argc, const char * argv[]) {
    	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    	NSArray *filters = [CIFilter filterNamesInCategories: nil];
    	for (id obj in filters) {
    		NSLog(@"%@", obj);
    	[pool drain];
    	return 0;
    That listed out a LONG list of things, but it was apparent from the naming convention where to look and I quickly found "CIMotionBlur".

    So I modified my program to contain ..
    	CIFilter *motionBlur = [CIFilter filterWithName: @"CIMotionBlur"];
    	NSDictionary *attributsDict = [motionBlur attributes];
    	NSArray *keysArray = [attributsDict allKeys];
    	for (id obj in keysArray) {
    		NSLog(@"%@", obj);
    This spit out..

    I underlined what I feel are the important keys. I do hope that this helps you out, and that we can go on to become best friends.
  13. Blakeasd thread starter macrumors 6502a

    Dec 29, 2009
    Thanks! Lol i was just frustrated with not being able to figure this out, so I do apologize for my rude comments.:) But there is just one more thing.. How do I apply the filter to my image.(view is the name of my image by the way) I tried [view CIMotionBlur]; in hopes that that would work however it did not. So is it possible to apply the filter with in a Cocoa program?
  14. jared_kipe macrumors 68030


    Dec 8, 2003

    Ok, firstly, that single line of code demonstrates a quite remarkable lack of grasping the core concepts here.

    Secondly, yes of course it is possible in Cocoa. That question demonstrates another odd gap in what I would consider "core concepts".

    Thirdly, look at the very first code fragment. Follow it through line for line and try to figure out what it is doing and what you expect is the "state" of the CIImage pointer "result" after the last line. IF you can see what is going on, THEN it should be trivial to implement a motion blur instead of hue adjustment. ELSE, you need to work on some simpler tasks before jumping into Core Image (or Cocoa more likely).
  15. Pixelmatortutor macrumors newbie

    Oct 15, 2010

    I thought that this would be a good place to start.
    I started experimenting with Quartz Composer for image filter creation a few months ago, and have become a lot better through some study and some trial and error.

    In certain cases I found that using the existing patches were somewhat limiting, so I decided to look into programing patches. I must admit that the Apple developer website is not the easiest of places to navigate around.

    I have found a good reference guide to OpenGL shading language, but so far I have not found a good reference guide to core image kernel language.

    I can get to know the commands after some studying.

    Examples are all well and good, but I need to grasp the syntax or "Grammar" of the language.

    I would appreciate any guidance as to the best way to learn this, and if there are any guides to this apart from the apple website.

    This is like being back at school!

    Many Thanks.
  16. lpetrich macrumors member

    Nov 26, 2009
    Apple's documentation has that: Core Image Kernel Language Reference: Core Image Kernel Language.

    Needless to say, Apple also has Core Image Programming Guide: Introduction to Core Image Programming Guide and Core Image Programming Guide: Creating Custom Filters.

    You can test your kernel code in Quartz Composer using the filter Core Image Filter. Do cmd-I on it, go the the second item in the top popup menu, and you'll get a place to enter your filter source code.

    I've actually written a custom-filter kernel, one that makes rosette-group or kaleidoscope patterns:
    const float PI = 3.14159265358979323846;
    const float TWO_PI = 2.0*PI;
    kernel vec4 Rosette(sampler Image, vec2 Center, float Angle, float Number, float Reflect)
        float TrueAngle = TWO_PI*Angle;
        float ReptAngle = TWO_PI/Number;
        float InvReptAngle = Number/TWO_PI;
        vec2 Pos = samplerCoord(Image) - Center;
        float PosLength = length(Pos);
        float PosAngle = atan(Pos.y, Pos.x) - TrueAngle;
        float RedPosAngle = mod(PosAngle* InvReptAngle,1.0);
        RedPosAngle = compare(-Reflect, compare(0.5-RedPosAngle, 1.0-RedPosAngle, RedPosAngle), RedPosAngle);
        PosAngle = RedPosAngle*ReptAngle;
        Pos = PosLength*cossin(PosAngle + TrueAngle) + Center;
        return sample(Image, Pos);
    I've been meaning to do more, but I'd have to complete writing a self-contained version of that filter (kernel + info files). I'd have to see what sort of ROI setup it would need, for instance.

    My experience so far:

    The CI kernel has a float data type, but no others primitive ones. No booleans, characters, integers, or doubles. It's picky about numerical constants -- you have to write them as floats, even if they are integers: 1. or 1.0 instead of 1

    But it does have some ways of grouping data: fixed-size arrays, structs, and vec2, vec3, and vec4 of floats.

    I used not only some GLSL functions: length, atan, mod, etc., but also some CI ones: cossin, etc. One can also define one's own functions in it, and forward-declare them with prototype statements in ANSI-C/C++ fashion. However, I've had to define pi explicitly.

    One can use a few C++ constructions, like const for constant values, and one can use both /* */ and // for comments.

    Flow of control is very limited. One can only use if, for, do, and while statements if their control-statement outcomes can be determined at compile time, not at run time.

    That may be why the CI kernel functions include compare(), defined as

    compare(x,y,z) = x < 0 ? y : z

    One can nest these functions; it seems that it calculates all the arg values, then does a conditional assignment.

Share This Page