BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.24k stars 4.61k forks source link

Selective Color filter like in photoshop? #299

Open haihw opened 12 years ago

haihw commented 12 years ago

This filter in photoshop allow user to change one kind of color (red, yellow, green, cyan, blue, magentas, white, neutral, black) by adjusting the percentage of Cyan, Magenta, Yellow, Black. Can I do this with GPUImage ?

BradLarson commented 12 years ago

There's the GPUImageRGBFilter, which lets you alter the balance within the red, green, and blue channels. There isn't a variant of that to do this with CMYK, but you could create a custom filter based on the RGB one that first converts to CMYK, adjusts those components, then converts back to RGB for display.

haihw commented 12 years ago

Thanks for your answer. But GPUImageRGBFilter seem changes R, G, B of whole image. While selective color filter in photoshop changes color of a part of image, which has a given color. For example, I has an street photo with some red cars and some yellow cars, I choose red color and change the value then only red car is changed color. Am I missing anything about GPUImageRGBFilter?

CullenSUN commented 12 years ago

haihw, As per my understanding, photoshop does not change color of a part of image. The red car's color got changed because its color go selected by the selection algorithm e.g. "if (r > 0.9 && g<0.5&&b<0.5) {//do sth here}", while the algorithm definitely scans all the pixels. To human eyes, it looks like Photoshop only changed a part of image.

haihw commented 12 years ago

@CullenSUN : yes, it's exactly what I want to mean. You have any idea to do that?

CullenSUN commented 12 years ago

@haihw . For my current project, I would just try tuning with RGBFilter and other color filters instead of doing a Selective Color filter at this stage. Selective Color Filter is complex, 7select x4colorAdjust parameters, and you will need to convert between RGB and CMYK back and forth.
The challenging part is selection algorithm. Trying to be the same as photoshop? There is not much information about it on internet. If you want to work on it, I can contribute a bit. Cheers.

liovch commented 12 years ago

@haihw @CullenSUN I wonder what kind of functionality you're trying to achieve, do you need to be able to dynamically adjust the settings for the filter, or will it be sufficient to have a filter with settings pre-fixed to certain values?

haihw commented 12 years ago

My designer friend use photoshop to make the effect. My mission is transform that effect into ios Apps. So I try to create the tools that like in photoshop as same as possible (color balance, selective color, curves, levels, blah blah).

@liovch : I try to find the filter like Selective Filter on Photoshop CS5, I'm appreciated if someone has the solution as same as possible with photoshop P.s: I tried your GPUImageColorBalanceFilter with paramenter midtones: (-0.1, 0.6, 0.1) and preserve luminosity set to YES. The result look so bad. Am i doing something wrong?. I can upload the image if u need.

haihw commented 12 years ago

@CullenSUN : yes, I'm trying to do the filter like that. I'm agree with you about the hardest part is selection algorithm. Currently, I have no idea for it. I think supposing one range value of RBG is Red selection seem to be good way. But which range bring us the same result like Photoshop is the challenge

BradLarson commented 12 years ago

If you want an example of a color selection algorithm, look at the GPUImageChromaKeyBlendFilter. The fragment shader for that takes a color and a sensitivity threshold and uses that to determine how to blend two images. You could take that color matching algorithm and modify it to adjust the colors matching that threshold.

liovch commented 12 years ago

@haihw @CullenSUN You could use GPUImageLookupFilter to create Instagram-like filters. Please see my comment here: https://github.com/BradLarson/GPUImage/issues/193

ezrover commented 11 years ago

Hi Brad, the luminosity filter in your test case only displays a grey image on the screen. Is that the desired effect?

BradLarson commented 11 years ago

@ezrover I'm not sure what this has to do with this particular issue, but the FilterShowcase merely has a quick example of the luminosity filter's output. The luminosity filter returns the average luminosity of a particular image. With autofocus and automatic exposure enabled, the iOS camera generally tries to maintain an average luminosity of 50%, thus the grey.

ezrover commented 11 years ago

Thanks sorry i should have started a new thread. anyways, u r awesome...

pursuits-knowledge commented 6 years ago

@haihw : Were you able to do it finally ?