Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create lighter color in matlab?

I have a base color, presented by basic [R G B] matrix.

And I want to create a lighter or darker version of that color, based on my constant, which is basically an angle (0 - 90°).

And I looking for an algorithm, how to create lighter or darker color based on that angle.

The endpoint for a lighter color is white and for a darker color is black.

silly example:

Green -> Lime -> White

Blue -> Navy -> Black

function [result] = GetColor(baseColor, angleValue)

    value = round(angleValue);

    endcolor = [1 1 1];

    r = linspace(basecolor(1,1), endcolor(1,1), 90);
    g = linspace(basecolor(1,2), endcolor(1,2), 90);
    b = linspace(basecolor(1,3), endcolor(1,3), 90);

    result = [r(value) g(value) b(value)];

end
like image 203
MicTech Avatar asked Dec 07 '10 21:12

MicTech


People also ask

How do you make a color lighter in MATLAB?

Use this syntax to adjust colors for all graphics objects in the current figure that use a colormap. brighten( map , beta ) shifts the intensities of the colormap specified as map . newmap = brighten(___) returns the adjusted colormap for any of the input argument combinations in the previous syntaxes.

How do you change scale color in MATLAB?

You can change the color scheme by specifying a colormap. Colormaps are three-column arrays containing RGB triplets in which each row defines a distinct color. For example, here is a surface plot with the default color scheme. f = figure; surf(peaks);

How do I make light blue in MATLAB?

Now, change the bar fill color and outline color to light blue by setting the FaceColor and EdgeColor properties to the hexadecimal color code," #80B3FF" .

How do you create a new color in MATLAB?

To specify one color, set newcolors to a character vector or a string scalar. For example, newcolors = 'red' specifies red as the only color in the color order. To specify multiple colors, set newcolors to a cell array of character vectors or a string array.


2 Answers

What it the lightest/darkest you want your color? Define your end points [r1 g1 b1], [r2 g2 b2] that will correspond to 0 and 90. Then use:

colormap = [linspace(r1, r2, 91)' linspace(g1, g2, 91)' linspace(b1, b2, 91)']

to define a set of 91 colors, and pick the color corresponding to the angle.

like image 178
Rich C Avatar answered Oct 13 '22 01:10

Rich C


You can easily use Java for this, as follows:

jColor = java.awt.Color(0.12,0.34,0.67);  % R,G,B fractions of 255 = [31,87,171]
lightColor = jColor.brighter.getRGBComponents([])'*255;  % => [44,124,244,255]  (4th component is alpha transparency)
darkColor = jColor.darker.getRGBComponents([])'*255;  % => [21,60,119,255]

Java has other supporting functions/classes that you can seamlessly use in Matlab, as in the above example.

like image 43
Yair Altman Avatar answered Oct 13 '22 01:10

Yair Altman