Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
553 views
in Technique[技术] by (71.8m points)

objective c - CI Filter to create Black & White image?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...