PDA

View Full Version : Core Image




Blakeasd
Oct 1, 2010, 10:54 AM
Does anyone know of a good Core Image tutorial? If you do please tell me. Thanks, Blake



chown33
Oct 1, 2010, 02:21 PM
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 site:developer.apple.com
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.

Blakeasd
Oct 1, 2010, 04:12 PM
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)
Thanks

MorphingDragon
Oct 2, 2010, 05:10 AM
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)
Thanks

Thats done through CoreImage too and there's an image section at the back of one of the tutorials by Apple.

Blakeasd
Oct 2, 2010, 02:03 PM
Does anyone know of tutorials that are not made by Apple. I have seen those and they have not provided the proper information.

jared_kipe
Oct 2, 2010, 02:30 PM
... they have not provided the proper information.
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?

Blakeasd
Oct 2, 2010, 06:21 PM
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.

NT1440
Oct 2, 2010, 06:26 PM
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.

Well, that's one sure fire way to eliminate the chances of anyone helping you...

Blakeasd
Oct 2, 2010, 07:23 PM
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...

jared_kipe
Oct 2, 2010, 07:52 PM
... ignorant because they have more experience in something. ...

I think you mean..
Arrogant, because how can having more experience make you ignorant?

robvas
Oct 2, 2010, 08:11 PM
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.

jared_kipe
Oct 2, 2010, 08:48 PM
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.
http://developer.apple.com/macosx/coreimage.html
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)
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/QuartzCoreFramework/Classes/CIFilter_Class/Reference/Reference.html


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..
CIAttributeFilterDisplayName
outputImage
inputAngle
inputImage
CIAttributeFilterName
CIAttributeDescription
CIAttributeReferenceDocumentation
CIAttributeFilterCategories
inputRadius

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.

Blakeasd
Oct 2, 2010, 09:03 PM
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?

jared_kipe
Oct 2, 2010, 10:21 PM
... (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?

*Sigh*

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).

Pixelmatortutor
Oct 16, 2010, 01:22 AM
Hi,

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.

lpetrich
Jun 8, 2011, 04:34 AM
Apple's documentation has that: Core Image Kernel Language Reference: Core Image Kernel Language (http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CIKernelLangRef/ci_gslang_ext.html#//apple_ref/doc/uid/TP40004397-CH206-TPXREF101).

Needless to say, Apple also has Core Image Programming Guide: Introduction to Core Image Programming Guide (http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/CoreImaging/ci_intro/ci_intro.html) and Core Image Programming Guide: Creating Custom Filters (http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/CoreImaging/ci_custom_filters/ci_custom_filters.html#//apple_ref/doc/uid/TP30001185-CH207-TPXREF101).

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.