Why does Angular Material use alpha to create grey colors? - angular-material2

I've noticed that in angular material when they need a grey they take black and then adjust it's alpha to be lighter. For example if you go here: https://material.angular.io/components and inspect any of the cards on the page, you'll notice the body paragraph has the font color rgba(0, 0, 0, .54);. Does anyone know why they choose to create greys by taking black and adjusting the alpha this way as opposed to just using hex or rgb? The only thing I can think of is that it helps support the warm and cool themes.

From https://material.io/guidelines/style/color.html#color-usability
Do: Using opacity instead of shifting colors often creates better contrast and relative luminance. For example, gray text (#727272) becomes hard to read if the background color changes to magenta.
Don't: Shifting to gray instead of decreasing contrast on black often lowers the relative luminance, making typography unreadable.

Related

Setting the background to transparent using GIMP

Using GIMP 2, I have an image of a grey chair on a white background, as below:
I now want to set the background to transparent. Therefore, I decided to use GIMP's "Color To Alpha" tool. So, I told it to set all pixels which are white (255, 255, 255) to transparent, as below:
This did set all white pixels to transparent. However, it also set the grey pixels on the chair to be partially transparent, as below:
So when I export this image and place it in front of a background, there is no white box around the chair -- but the background partially shows through the chair.
What am I doing wrong?
First, this question is offtopic here, and should be on https://graphicdesign.stackexchange.com .
Second, it is trivial enough just to answer: the color to alpha plug-in is not there to turn a single color, as seem on the image, to transparency: it is a sophisticated plug-in that will remove one color of your image in a way that, if you lace the new image over a background of the same color the color you removed, you get the original image back.
Thus, in your case, it removed the "whiteness" of your chair, transforming all pixels to different opaque shades of black - so that when placed over white, you get the original image.
To simply remove the white, you have to cick on the Select By Color tool (by default th 5th icon on the toolbox), click on the white background to have it selected, and then just edit->cut. (It won't work if your image layer does not have transparency to start with - if that is the case, prior to edit->cut do Layer->Transparency->Add Alpha Channel).
If you get aliased borders, then, after edit>cut, but prior to dismissing your selection, you can do Select->Border... by 1 or 2px, and then use the color to alpha filter with White on this selection.
For more information on Color to Alpha, I have this other answer its use and comparison with edit-cut here: https://graphicdesign.stackexchange.com/questions/28058/gimp-color-to-alpha-is-not-selectable/28097#28097
Just use a selection to restrict the action of Color to alpha where it matters: backgroundand edge pixels:
Select background with fuzzy select
Select>Grow by one pixel so that the selection ofverlaps the edge pixels
Color>Color to alpha

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?

a black image's color can not be changed in Unity

the color of a black image , or the black part of a image, can not be changed.
I set the image's color to red, but the image is still black.
Is that a desired feature?
What i want is , the image is changed to red.
the Unity version is 5.0.1f.
I am using the new UI.
To understand the source of the problem, you have to understand how "changing colors" work. It's nothing but a simple multiplication. In RGB terms, "black" is a vector of (0, 0, 0) — and it's pretty obvious, that whatever you multiply the 0 by, it stays black.
If you want the template image to be able to change to any color, use white.
To modify colours in a more complex way, you have to understand how the Color property of a Image component works. UI system hides a lot of complexity underneath (and it's good). Basically, Color modifies the vertex colours of a mesh. Since you don't usually specify a material, a default sprite material is used, and it uses a default sprite shader. And inside this shader, when it paints the pixels on the screen, it multiplies the vertex colours by the texture colour sampled at this pixel, and that's how it produces the end result. If you want the colours to be combined in a different way, you'll have to write a custom shader — which is really not as hard, but you probably don't need it for what you're trying to do in the scope of this question.
Black stays black.
White, however, will change with whatever Color you choose, so if you use an image editor and make your image be white instead of black, the image can then be whatever color you choose within Unity.
Check to see if your image has an alpha channel. You can do this with GIMP or Photoshop. If it does, then check your shader/material to ensure that it's set to transparent/diffuse (and not just diffuse). Diffuse only doesn't apply the alpha property to the material.
Also, it doesn't look like you assigned a material...
Make sure you have used yourImage.canvasRenderer.SetColor.
For example:
damageAnim.canvasRenderer.SetColor (new Color (255, 255, 255, 255));

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.

Edge Detection and transparency

Using images of articles of clothing taken against a consistent background, I would like to make all pixels in the image transparent except for the clothing. What is the best way to go about this? I have researched the algorithms that are common for this and the open source library opencv. Aside from rolling my own or using opencv is there an easy way to do this? I am open to any language or platform.
Thanks
If your background is consistend in an image but inconsistent across images it could get tricky, but here is what I would do:
Separate the image into some intensity/colour form such as YUV or Lab.
Make a histogram over the colour part. Find the most occuring colour, this is (most likely) your background (update) maybe a better trick here would be to find the most occuring colour of all pixels within one or two pixels from the edge of the image.
Starting from the eddges of the image, set all pixels that have that colour and are connected to the edge through pixels of that colour to transparent.
The edge of the piece of clothing is now going to look a bit ugly because it consist of pixels that gain their colour from both the background and the piece of clothing. To combat this you need to do a bit more work:
Find the edge of the piece of clothing through some edge detection mechanism.
Replace the colour of the edge pixels with a blend of the colour just "inside" the edge pixel (i.e. the colour of the clothing in that region) and transparent (if your output image format supports that).
If you want to get really fancy, you increase the transparency depending on how much "like" the background colour the colour of that pixel is.
Basically, find the color of the background and subtract it, but I guess you knew this. It's a little tricky to do this all automatically, but it seems possible.
First, take a look at blob detection with OpenCV and see if this is basically done for you.
To do it yourself:
find the background: There are several options. Probably easiest is to histogram the image, and the large number of pixels with similar values are the background, and if there are two large collections, the background will be the one with a big hole in the middle. Another approach is to take a band around the perimeter as the background color, but this seems inferior as, for example, reflection from a flash could dramatically brighten more centrally located background pixels.
remove the background: a first take at this would be to threshold the image based on the background color, and then run the "open" or "close" algorithms on this, and then use this as a mask to select your clothing article. (The point of open/close is to not remove small background colored items on the clothing, like black buttons on a white blouse, or, say, bright reflections on black clothing.)
OpenCV is a good tool for this.
The trickiest part of this will probably be at the shadow around the object (e.g. a black jacket on a white background will have a continuous gray shadow at some of the edges and where to make this cut?), but if you get this far, post another question.
if you know the exact color intensity of the background and it will never change and the articles of clothing will never coincide with this color, then this is a simple application of background subtraction, that is everything that is not a particular color intensity is considered an "on" pixel, one of interest. You can then use connected component labeling (http://en.wikipedia.org/wiki/Connected_Component_Labeling) to figure out seperate groupings of objects.
for a color image, with the same background on every pictures:
convert your image to HSV or HSL
determine the Hue value of the background (+/-10): do this step once, using photoshop for example, then use the same value on all your pictures.
perform a color threshold: on the hue channel exclude the hue of the background ([0,hue[ + ]hue, 255] typically), for all other channels include the whole value range (0 to 255 typically). this will select pixels which are NOT the background.
perform a "fill holes" operation (normally found along blob analysis or labelling functions) to complete the part of the clothes which may have been of the same color than the background.
now you have an image which is a "mask" of the clothes: non-zero pixels represents the clothes, 0 pixels represents the background.
this step of the processing depends on how you want to make pixels transparent: typically, if you save your image as PNG with an alpha (transparency) channel, use a logical AND (also called "masking") operation between the alpha channel of the original image and the mask build in the previous step.
voilà, the background disappeared, save the resulting image.

Resources