CIFilter HueAdjust - uiimage

How to programmatically change the hue of UIImage?
I am using the above page's advice, for Core image filter CIFilter. The only problem I am having is my when I rotate to a yellow hue, it's a dark mustard yellow, and I can't get the brightest vibrant yellow, ie R:255 G:255 B:0. I have images that are on layers that are made up of a simple color R:255 G:0 B:0 I just want to rotate around, to get the basic colors plus orange. Orange works fine tho.
I just don't know why when I rotate from R:255 to try and get R:255 G:255 Yellow it's a dark yellow.
I am using 1.04719755 for the Yellow float, at deltaHueRadians
I don't know it's just weird this is the 3rd attempt at this but I keep getting a dingy yellow.

I realized the problem.
In Photoshop I have done so many Colorize operations when I used to photo edit, I got them confused with Hue Rotation.
Basically when you Colorize in Photoshop, it will "Colorize" the image not just Hue Rotate the values.
The difference between the two is a very thin line depending on what images you use. I don't really feel like going into a complete explanation but...
Say you have a grey cube on a layer, and you COLORIZE the image, the cube will rotate colors as you use a slider. If you Hue rotate it will stay grey.
But if you take a red cube, and hue rotate, then the hue rotation will take you thru colors, not necessarily all of them tho like a colorize.
I believe the issue has to do with all that good ole HSV RGB matrix crazy math problems. Which I am not doing right now. Keeping it simple.
I decided to just do a colorize method with:
CGContextSetBlendMode(context, kCGBlendModeMultiply);
With grey objects and this is perfectly what I wanted.
from googling I found this:
http://coffeeshopped.com/2010/09/iphone-how-to-dynamically-color-a-uiimage

Related

HTML5 canvas - make a mono mask efficiently without antialiasing

I am using pixel colour inspection to detect collisions. I know there are other ways to achieve this but this is my use case.
I draw a shape cloned from the main canvas on to a second canvas switching the fill and stroke colours to pur black. I then use getImageData() to get an array of pixel colours and inspect them - if I see black I have a collision with something.
However, some pixels are shades of grey because the second canvas is applying antialiasing to the shape. I want only black or transparent pixels.
How can I get the second canvas to be composed of either transparent or black only?
I have achieved this long in the past with Windows GDI via compositing/xor combinations etc. However, GDI did not always apply antialiasing. I guess the answer lies in globalCompositeOperation or filter but I cannot see what settings/filters or sequence to apply.
I appreciate I have not provided sample code but I am hoping that someone can throw me a bone and I'll work up a snippet here which might become a standard cut & paste for posterity from that.

How to shift Black to Color in an Image, Python

I have a new backlit led monitor, and I found this black and white image of a storm trooper that looks fantastic on the backlit monitor. My other monitor, however, is an old "energy star" liquid crystal, and the whites are yellow and the blacks are brown. The same background looks awful...
So, I was trying to write some code to create a negative of the image, then shift the base grays and blacks to a color. However, I guess I don't understand enough about color theory. I tried the following on the negative of the image:
def colorshift_image(hueshift,image_file,output_image_file):
image = imread(image_file)
hsv_image = colors.rgb_to_hsv(image)
hsv_image[:,:,2] += hueshift
image = colors.hsv_to_rgb(hsv_image)
imsave(output_image_file,image)
and it doesn't do much of anything, except maybe make the image look worse:
Original:
Negative:
Hue Shift:
Actually, it looks moderately awesome in the lower resolution. But anyway, I think the gist is that I would like the extreme whites to take on a color--in fact, keeping this last image as a base (because the color palette is good for the LCD, then adding a blur to soften the jarring hue transitions, I think it would work...if only I could move from the grays and whites: shift them to some kind of color...
Is there a way to grab, using PIL/Scipy/etc., the "shiny" bright white parts, and shift it to a red or blue...and the greys to another base color?

Classifying color in dark surroundings

In a program I am working on, I am trying to classify colors based on their RGB values as red, orange, yellow, green, blue, or white. I am classifying them by comparing the given RGB values to a constant "ideal" value for each color and finding the minimum euclidean distance in a three dimensional space. However, I am having trouble when the color I am analyzing comes from a dark image as the current program has difficulty differentiating between orange, yellow, and red within dark images. How should I fix or work around this issue?
The environment is always going to cause problems. Say if the only light source is red you won't be able to tell apart gray, green or blue.
If your situation is not that complex you could try to adjust the image. Almost all image processing software/libraries have some functions to that end. Probably the best solution would be to have some calibration components in the scene like a white ball that you know what color it should be and can help you adjust the image and make the color identification easier.

UIImage - highlight single color only

I need to convert an image to greyscale except for a single color. For example, if there is some red in the image (like a red bus), this will remain in color, but the rest of the image will remain in black & white.
I think I should be able to do a rudimentary job of this by going over each pixel individually, such as here: http://brandontreb.com/image-manipulation-retrieving-and-updating-pixel-values-for-a-uiimage . I am assuming I would just leave certain pixels alone if their red component was above a certain amount, and green/blue was below a certain amount. Otherwise, set the pixel to grayscale. Is this a good approach?
I'm more interested in whether or not it is possible to do to the live camera input, such as with a Core Image filter, or using GPUImage, but I haven't been able to find any suitable filters. Any suggestions?
Update:
This seems to be possible using GPUImage with a GPUImageLookupFilter, as per: https://stackoverflow.com/a/19340583/334982
I've created a lookup.png file in Photoshop, by dropping the Saturation for all colours except red to 0. This works ok, but it doesn't seem to grey out all colours. For example, my skin still looks fairly skin coloured, and my brown table is still fairly brown.

Best natural way of coloring an icon/sprite

I wanna to color a sprite/icon with a transparent background and with shadows. I tried to shift the hue to all pixels but it looks not so natural and I have problems with the black and the white colors in an image. If an image tend to be black shifting the hue do not change the black in red or another color even shifting by 360 degrees.
Tried to color addicting and subtracting color and even in that case the black and the white tend to be colored or disappears at all.
Maybe should I put an image on the icon to achieve the coloring effect ?
Any suggestions on how to proceed.
I lost.
You've been asking a lot about this hue shifting thing, so I figured I'd try to work out an example: http://jsfiddle.net/EMujN/3/
Here's another that uses an actual icon: http://jsfiddle.net/EMujN/4/
There's a lot in there. There's a huge data URL which you can ignore unless you want to replace it. Here's the relevant part where we modify HSL.
//SHIFT H HERE
var hMod = .3;
hsl[0]=(hsl[0]+hMod)%1;
//MODIFY S HERE
var sMod = .6;
hsl[1]=Math.max(0,Math.min(1,
hsl[1]+sMod
));
//MODIFY L HERE
var lMod = 0;
hsl[2]=Math.max(0,Math.min(1,
hsl[2]+lMod
));
I've converted to HSL because it's a lot easier to accomplish what you want in that color space than RGB.
Without getting any more complex, you have three variables you can tune: how much to add to either Hue, Saturation, or Lightness. I have the lightness variable set to 0 because any higher and you will see some nasty JPEG artifacts (if you can find a decent .png that would be better, but I went with the first CC night image I could find).
I think the hue shift (yellow to green) looks pretty good though and I have maxed out the saturation, so even a normally white light appears bright purple. Like I said in my comment, you will need to increase the lightness and saturation if you want to colorize patches of black and white. Hopefully, you can figure out what you need from this example.
image used: http://commons.wikimedia.org/wiki/File:Amman_(Jordan)_at_night.jpg
I found a better solution by myself which can solve the problem with the black and white.
So basically the solution can be solved in multiple steps. Here I will define the steps. Later I'll provide some working code:
Get the image
Calculate the predominant color, averaging the image pixels or simply providing an input RGB value which is the predominant that your eye can catch.
If the predominant tends to be black or white, or both, the image has to be recolored with an addictive or subtractive method, addictive if black, subtractive if white. So basically all RGB pixels should be attenuated or sharpened until RED. I think that the best solution should be RED, because RED is first in the HUE scale, and this can help when we will hue-shift the pixels.
To have a unique algorithm which can work with different kind of images, not only black predominant or white, ideally the input the non-black and non-white predominant images should be pre-hueshifted manually, using photoshop or with another algorithm in a way that the new predominant color results to be RED too
After that the Hue shifting coloring is straighforward. We know that the predominant color is RED for all the images, and we'll shift the HUE values with a difference between the HSV value of the desired color and the HSV of the predominant color (RED).
Game over. We have a pretty universal way to color different images with hue shifting in a natural way.
Another question could be how to authomatically pre-shift the input images which predominant color is not black or white.
But this is another question.
Why this coloring method could be considered natural. Simply consider one thing. Generally the non dominant black or white colors are part of the shadows and light which gives a 3D feel to the images. On the other hand if my shoes are 100% black and i will tint them with some colors, they will no more be black. Color the dominant black cannot be achieved simply shifting the HSV parameters but other steps should be performed. The steps are the above described.

Resources