views:

46

answers:

1

I have a CIImage I need to convert from color to Black and White within my Cocoa / objective C program. Peter H. previously pointed me to this link (http://www.codingadventures.com/2008/06/threshold-filter-in-glsl/) as a potential solution ... but I am having trouble compiling the kernel routine there (see separate thread, if interested).

So I am wondering if one of the other built-in CIFilters will accomplish what I'm trying to do. I don't want a grayscale image ... I want each pixel in the Result image to be either Black or White -- I just need to be able to tell the filter how to determine which pixels should become black and which should become white. The "Threshold" filter in Photoshop does exactly this -- it lets me specify the "threshold" and then it uses this value to decide which pixels become white and which become black. This is what I am trying to "replicate" via code in my Xcode project.

Any ideas if one of the other built in filters can be used for this? Thanks.

+1  A: 

You can use the CIColorMap filter. Give it a 20(w) by 1(h) jpg where the left half is white and the right half is black (or the other way around) and use that as your color map gradient. That seems to hammer down the colors nicely. I originally tried a 2x1 image with 1 white pixel and one black, but it looked like it got interpolated a bit. I went up to 20x1 and it worked fine.

Hint: I used Core Image Funhouse (not Quartz Composer) to experiment.

Joshua Nozzi
I'll give that a shot and report back. Thanks...
Adam
Adam
Post the code you're using to set all this up. Works fine in Core Image Fun House, which is just a basic GUI wrapper to tryout the existing CI filters.
Joshua Nozzi
After additional experimentation I think the issue may be with my source Image gradient filter, rather than my code. Using FunHouse, if I apply my gradient filter to the included Copenhagen.jpg image ... it does exactly what I want. If, however, I apply the same filter to my own image (the one I need to modify in my program) ... it does not behave the same way. The transformation makes my image either completely white or completely black (depending on whether the left side of my 1x20 gradient is white or black). to be cont'd...
Adam
Adam
Oops ... on the second-to-last comment I meant to say "... with my source image OR my gradient filter ...", on the first sentence. But my ability to edit comment 1 evidently went away when I posted comment 2.
Adam
The best advice I can give here is to look into the details of both of your images. Bit depth, color space, format, etc. This approach worked alright for both the Funhouse example images and screen captured images (which I used to generate a quick test image).
Joshua Nozzi
OK. Well, thanks for the help on this. The filter DOES do what I want -- just not with my particular image! Hopefully with some additional investigation I can figure that out. Meanwhile I'll mark this thread Answered and if I have more issues post them in a new thread. Thanks again for the help.
Adam