Difference between brightness and lightness in Image Manipulation - android

I have an application to adjust the lightness/brightness of the image and the saturation and i found this link here which uses android colormatrix to adjust the brightness. Here's the function to adjust brightness in colormatrix.
public static void adjustBrightness(ColorMatrix cm, float value) {
value = cleanValue(value,50);
if (value == 0) {
return;
}
float[] mat = new float[]
{
1,0,0,0,value,
0,1,0,0,value,
0,0,1,0,value,
0,0,0,1,0
};
cm.postConcat(new ColorMatrix(mat));
}
But i don't know if there's a difference with lightness in brightness. Because in GIMP software there is lightness and brightness. See the screenshot below. If there's another method to adjust lightness/brigthness saturation at the same time I would be happy to see it :).

Brightness is visual perception related with reflecting or radiating of lights of different frequencies. On the otherhand lightness is TONE which moves from Darkest color to lightest color of same color Gamma is nothing but an attribute to handle luminescence Means how bright should be the image be (it's more a mathematical calculation rather definition.
In non technical words we can say
Lightness seems to more affect the saturation of the photograph, whereas brightness seems to affect how vivid the colors look.
If you want to go in deep for the proof of concepts, please follow this
http://www.sciencedirect.com/science/article/pii/S0042698910004578

Related

iOS and Android Algorithm or library for feathering edges of the images similar to photoshop's

I am looking for iOS and Android library for (preferably) or algorithm that would help me to feather edges of the image in similar way how it is handled in Photoshop. The illustration below shows the desired effect of the algorithm. I am not interested feathering bounds of the image, just alpha edges. I have been searching for algorithm that can accomplish it for few days without luck. Any help will be appreciated.
Assuming that you have alpha channel (like on photo with transparent background) it seems that regular convultion blur matrix should satisfy you.
However instead of going through RGB channels - you should go through ALPHA channel only.
Check the blur filter here:
https://en.wikipedia.org/wiki/Kernel_%28image_processing%29
You are interested in box blur/gaussian blur. However to make this effect more smooth - you should use matrix of bigger size.
The reason that algorithm will satisfy your needs is that if all surrounding pixels have alpha 0 - it will be still 0. If 255 - it will stay 255. Just pixels in area of border between alpha 0/255 will be affected.
Edit:
Please check this fiddle with chrome (in ff that's really slow):
http://jsfiddle.net/5L40ms65/
You can take a look into algorithm in the end of code. Since implementation i noted that:
- no need to blur if all neigbour pixels are 255 or 0 (alpha channel)
- it is required to blur also RGB in other case
In general:
RADIUS = 2 (makes total width of matrix = 5)
For x = 0..width
for y = 0..width
if all pixels in square of radius 2 are alpha = 0
do nothing
elsif all pixels in square have alpha = 255
do nothing
else
pixel[x][y].RGB = average RGB of adjacent pixels where alpha != 0
pixel[x][y].ALPHA = average ALPHA in square
Example result with radius=2
Of course this is rather concept program, there is a lot of place for memoization and tuning this script however it should make a big picture clear
You could change the alpha of your border based on the background color of the view.
var r:Float!
var g:Float!
var b:Float!
var a:Float!
if self.view.backgroundColor.getRed(red:r, green:g, blue:b, alpha:a) {
var imgv = UIImageView(frame: CGRect(x:100, y:100, width:100, height:100))
imgv.image = UIImage(named:"name")
imgv.layer.borderWidth = 2.0
imgv.layer.borderColor = UIColor(red:r, green:g, blue:b, alpha:0.5).CGColor
imgv.layer.cornerRadius = imgv.frame.size.width / 2
imgv.clipsToBounds = true
}else{
//Could not get the RGB of background color
}
You may see errors in this code because I have not yet tested it.

Android find if color is too close to black or white

I have a int representation of a color. What I want to do is if this color is too black or too white, I want to set background to a default color. I want to find if the color is too close to black or white using RGB or HSV representation is fine. By too black or too white, I mean to say I can set some threshold depending on the scale. Say there is a scale from 0 to 1 where 0 is black and 1 is white, I want to reject all the colors below 0.2 and above 0.8. I tried the below code but it actually does not work. This does not work since I see some other colors also get rejected which are not shades of black or white. Please help.
public static boolean isWhitish(int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
return hsv[2] > 0.8;
}
First you will want to get the HEX CODE of your color, then you can use this solution to extract the brightness of that color.
You can then use your (brightness < .2 || brightness > .8) to decide what to do next.
Hope this helps, good luck :-)

libgdx - how to change my font color with an animated effect

I try to explain what I need in the most clear way. Imagine I have a font with an outline, now I want this outline to change its color dynamically but not sharply, like if it changes slightly from a color to another... a kind of continuous effect which change my outline between four color and then restart from the first one.
I don't know how you implemented font outline so I will use a Label font color change as example - you can implement it with your outline if you want to.
My idea is to create some kind of "animation manager" updated in every screen step - it is very "straight" resolution but should work for sure. It should work in following steps:
If target color is achieved get next target color
Calculate the new step-color that brings you closer target
Apply color to Label
Now you can use some existing mechanisms to achieve this goal and this two will be useful for you:
HSL/HSB color system
https://en.wikipedia.org/wiki/HSL_and_HSV
Is kind of color representation using three arguments - Hue, Saturation and Value. This is actually good for you because to change color you need to modify just one of arguments - Hue, other can be the same all the time which will guarantee you that every color will have same saturation and brightness.
Unfortunately Color class in LibGDX doesn't support hsb/hsl system so you need to use some "external" tool - the good one is Oracle implementation:
int java.awt.Color.HSBtoRGB(float hue, float saturation, float brightness)
which you can use to create LibGDX color this way:
Color color = new com.badlogic.gdx.graphics.Color( java.awt.Color.HSBtoRGB(hue, saturation, brightness) );
Of course you can use another hsb->rgb "converter" or just implement it yourself - there are some patterns to calculate r, g and b values from h, s and l and you will find them in Google easily.
LibGDX Interpolation mechanism
Interpolation.apply(float start, float end, float a)
The start is the value of your beggining color and the end is value of your target one. The a argument is step in time you've got to calculate on your own.
To sum up basic code changing the Label color would be something like:
...
float a = 0.0f;
#Override
protected void step()
{
if( a < 1.0f ) a += 0.001f; // 0.01f is your time step - "how fast change"
label.getStyle().fontColor = new com.badlogic.gdx.graphics.Color( java.awt.Color.HSBtoRGB(Interpolation.linear.apply(0.4f, 0.9f, a), 0.5f, 0.5f) );
...
Now using this code you can create the manager that will handle with achieving target for example:
...
if( a < 1.0f ) a += 0.001f;
else
{
a = 0.0f;
someTargetColor = someValue; //someValue can be taken from an Array
}
...
Regards,
MichaƂ

OpenGL ES 2 Texture atlas bleeding edge

Currently working on video games project.
When I get:
Matrix.orthoM(projectionMatrix, 0, 0, widthwindows, heightwindows, 0, -1, 3);
Everything looks ok. But when the variable widthwindows is different from the real screen resolution now I get this effect.
I can't use precited solution from other topic because some of my tiles are curve or whatever so even with -0.5 pixel there are no effect on them they still get transparency around them (and even some tiles aren't in taking 64*64, but 12*64 for instance, so -0.5 pixel get no effect).
You might want to work with PMA(Pre Multiplied Alpha).
When you draw a sprite with transparency you many times use a Normal blending mode.
A normal blending mode takes the sprite's pixel color multiplies it by the Alpha of that pixel and adds it to the background pixel color multipled by 1 compliment of the source pixel alpha.
This works most of the time however when scaling and filtering the sprite this might cause semi transparent pixels to appear darker than they should.
In order to solve this you use PMA.
Since in the blending you are going to multiply the sprite's color with the sprite's alpha, you can instead store the pixel color already multiplied by it's alpha.
Now the blending mode will look like this... Add PMA pixel color(without multiplying the alpha) to the background color multiplied by 1's compliment of the source pixel alpha.
In GLES 2 the Normal blending mode will be like this:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
The PMA blending mode will look like this:
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
Hope this solves your issue.

Android changing a color's brightness

I want to change the brightness of any given color (Note: I am not talking about screen brightness), I have looked at the Color class, it has a few methods for conversions between RGB and HSV, I'm a newbie in this area. To start with, how do I change the brightness of red, if its value is spefied in RGB (#FF0000)?
The easiest way would be to convert the color to HSL (not HSV! they are different - see http://en.wikipedia.org/wiki/HSL_and_HSV) and change the L component - increase to make it brighter, decrease to make it darker.
Considering that you are talking about brightness (color enhance) and not luminance (white amount), your model is the HSV (aka HSB) and not HSL.
On fast briefing, if you enhance the V channel on HSV over, lets say... some blue, you have a "more blue" color. If you enhance the L channel on HSL model you have a more "clear and washed" blue.
The android.graphics.Color class have built-in support to HSV model. Use Color.colorToHSV() and Color.HSVToColor() to edit the brightness value (or hue, or saturation, if you like).
On HSV model, H (hue) define the base color, S (saturation) control the amount of gray and V controls the brightness. So, if you enhance V and decrease S at same time, you gets more luminance, in pratice.
For starters, you need to remember two things -
To reduce brightness, you can change red from #FF0000 to #AA0000 or #880000 - basically reduce the Red component.
You can also try reducing opacity - often you'll realize that it works better than just reducing brightness.
You can use Color.colorToHSV to convert the color to HSV, then change the brightness of the HSV color, then use Color.HSVToColor to convert it back to a color int. For example, the following code sets the brightness to 0.5:
#ColorInt int originalColor = /*your original color*/;
float[] hsv = new float[3]; //Create an array to pass to the colorToHSV function
Color.colorToHSV(originalColor, hsv); //Put the HSV components in the array created above
hsv[2] = 0.5f; //Whatever brightness you want to set. 0 is black, 1 is the pure color.
#ColorInt int newColor = Color.HSVToColor(hsv); //Convert it back to a ColorInt

Categories

Resources