views:

54

answers:

1

So ... I have an image loaded into an NSBitmapImageRep object, so I am able to examine the contents of specific pixels via a two dimensional array. Now I want to apply a couple of "transformations" to the image, in preparation for some additional processing. If I was manipulating the image manually, in Photoshop, I would:

  1. Rotate the image
  2. Crop a portion of it and discard the rest
  3. Apply a "threshold" transformation (which essentially converts the image to black and white, based on the threshold value I provide)
  4. Resample the image to shrink it down a bit (which, although losing some image quality, will speed up the subsequent processing)

(not necessarily in that order)

Are there objective C methods available to facilitate these specific image manipulations, with the data in the NSBitmapImageRep object? If so, can someone point me to some good examples?

A: 

Create a CIImage for the CGImage of the bitmap image rep. Then you can:

  1. Rotate it
  2. Crop it
  3. Apply a threshold filter
  4. Scale it
Peter Hosey
Thanks Peter. That sounds perfect. I'll head down the CGImage path. Any thoughts on good reference material and/or examples? I'm doing a lot of googling and of course looking through the developer documentation ... but this is a rather "random" way to educate myself and some good working examples of code to load images, apply some various transforms, render, etc. etc. would be helpful. Or a specific book title?
Adam
I didn't use books very much in learning Cocoa and Quartz. I followed the Apple documentation, both the Guides and the framework References.
Peter Hosey
Hey I found the Core Image programming guide, and it looks like it has tons of good stuff in it for me regarding CI (that was probably so obvious to you that you assumed I had already been reading it ... but I'm in a new world here and nothing is obvious!) :)
Adam
When I follow the threshold filter link above, and copy the code into my project ... I get a compiler error on the first line: kernel vec4 threshold(sampler image, float midPoint, float range )The compiler says, "expected '=', ',', ';', 'asm' or '__attribute__' before 'vec4'"I've tried a several things to reformat the line and make it work. But nothing I try is any better. And this declaration looks just like all the other kernel examples I can find. Can you translate this error for me - and/or tell me how to fix it?
Adam
Also ... I initially mentioned a "threshold filter", and you gave me one. But maybe there is a better way (filter) to accomplish my objective of taking the input image and converting it to black and white only? In photoshop I do this with a "threshold" value of about 80, and it gives me good results. But maybe there's a better way to do it programmatically, within cocoa?
Adam
Adam
Those are three separate questions, and you should ask them separately.
Peter Hosey