diff --git a/CHANGELOG.md b/CHANGELOG.md index b24e18f..cb6114e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## [v0.1.0] - minor changes - 2019-02-15 + +### Added + +### Changed + +- makecolor_scheme uses color models + +### Removed + +- + +### Deprecated + +- + ## [v0.0.1] - first release - 2019-01-24 ### Added diff --git a/docs/build/assets/figures/curves.svg b/docs/build/assets/figures/curves.svg index 72af8fb..ae479cf 100644 --- a/docs/build/assets/figures/curves.svg +++ b/docs/build/assets/figures/curves.svg @@ -40,7 +40,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -103,7 +103,7 @@ - + @@ -121,7 +121,7 @@ - + @@ -133,13 +133,13 @@ - + - + @@ -151,7 +151,7 @@ - + diff --git a/docs/build/assets/figures/funcscheme1.svg b/docs/build/assets/figures/funcscheme1.svg index 552afd0..42075ce 100644 --- a/docs/build/assets/figures/funcscheme1.svg +++ b/docs/build/assets/figures/funcscheme1.svg @@ -40,7 +40,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -103,7 +103,7 @@ - + @@ -121,7 +121,7 @@ - + @@ -133,13 +133,13 @@ - + - + @@ -151,7 +151,7 @@ - + diff --git a/docs/build/assets/figures/funcscheme2.svg b/docs/build/assets/figures/funcscheme2.svg index 1b6ab9b..7e8d338 100644 --- a/docs/build/assets/figures/funcscheme2.svg +++ b/docs/build/assets/figures/funcscheme2.svg @@ -40,7 +40,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -103,7 +103,7 @@ - + @@ -121,7 +121,7 @@ - + @@ -133,13 +133,13 @@ - + - + @@ -151,7 +151,7 @@ - + diff --git a/docs/build/assets/figures/funcscheme3.svg b/docs/build/assets/figures/funcscheme3.svg index fde7e30..b233d18 100644 --- a/docs/build/assets/figures/funcscheme3.svg +++ b/docs/build/assets/figures/funcscheme3.svg @@ -40,7 +40,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -103,7 +103,7 @@ - + @@ -121,7 +121,7 @@ - + @@ -133,13 +133,13 @@ - + - + @@ -151,7 +151,7 @@ - + diff --git a/docs/build/assets/figures/funcscheme4.svg b/docs/build/assets/figures/funcscheme4.svg index 406c1ab..277370d 100644 --- a/docs/build/assets/figures/funcscheme4.svg +++ b/docs/build/assets/figures/funcscheme4.svg @@ -40,7 +40,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -103,7 +103,7 @@ - + @@ -121,7 +121,7 @@ - + @@ -133,13 +133,13 @@ - + - + @@ -151,7 +151,7 @@ - + diff --git a/docs/build/assets/figures/funcscheme5.svg b/docs/build/assets/figures/funcscheme5.svg index a188e94..638bac6 100644 --- a/docs/build/assets/figures/funcscheme5.svg +++ b/docs/build/assets/figures/funcscheme5.svg @@ -40,7 +40,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -103,7 +103,7 @@ - + @@ -121,7 +121,7 @@ - + @@ -133,13 +133,13 @@ - + - + @@ -151,7 +151,7 @@ - + diff --git a/docs/build/assets/figures/funcscheme6.svg b/docs/build/assets/figures/funcscheme6.svg new file mode 100644 index 0000000..bbaeb0a --- /dev/null +++ b/docs/build/assets/figures/funcscheme6.svg @@ -0,0 +1,2263 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/build/assets/figures/terrain.svg b/docs/build/assets/figures/terrain.svg index e2ac2dd..3661f2b 100644 --- a/docs/build/assets/figures/terrain.svg +++ b/docs/build/assets/figures/terrain.svg @@ -40,7 +40,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -103,7 +103,7 @@ - + @@ -121,7 +121,7 @@ - + @@ -133,13 +133,13 @@ - + - + @@ -151,7 +151,7 @@ - + diff --git a/docs/build/convertingimages.html b/docs/build/convertingimages.html index 04d08e1..97c1087 100644 --- a/docs/build/convertingimages.html +++ b/docs/build/convertingimages.html @@ -1,11 +1,11 @@ -Converting image colors · ColorSchemeTools

Converting image colors

Converting images

Convert image from one scheme to another

Using the ColorSchemes function getinverse() it's possible to convert an image using one colorscheme to use another.

convert_to_scheme(cscheme, img) returns a new image in which each pixel from the provided image is mapped to its closest matching color in the provided scheme.

In the following figure, the Julia logo is converted to use a ColorScheme with no black or white:

using FileIO, ColorSchemes, ColorSchemeTools, Images
+Converting image colors · ColorSchemeTools

Converting image colors

Converting images

Convert image from one scheme to another

It's possible to convert an image using one color scheme to use another.

convert_to_scheme(cscheme, img) returns a new image in which each pixel from the provided image is mapped to its closest matching color in the provided scheme. See ColorSchemes's getinverse() function for more details on how this works.

In the following figure, the Julia logo is converted to use a ColorScheme with no black or white:

using FileIO, ColorSchemes, ColorSchemeTools, Images
 
 img = load("julia-logo-square.png")
 img_rgb = RGB.(img) # get rid of alpha channel
 convertedimage = convert_to_scheme(ColorSchemes.PiYG_4, img_rgb)
 
 save("original.png",  img)
-save("converted.png", convertedimage)

"julia logo converted"

convert_to_scheme(cscheme, img)

Converts img from its current color values to use only the colors defined in cscheme.

image = nonTransparentImg
+save("converted.png", convertedimage)

"julia logo converted"

Notice how the white was matched by the color right at the boundary of the light purple and pale green.

convert_to_scheme(cscheme, img)

Converts img from its current color values to use only the colors defined in the ColorScheme cscheme.

image = nonTransparentImg
 convert_to_scheme(ColorSchemes.leonardo, image)
-convert_to_scheme(ColorSchemes.Paired_12, image)
source
+convert_to_scheme(ColorSchemes.Paired_12, image)
source
diff --git a/docs/build/makingschemes.html b/docs/build/makingschemes.html index b9fa3f0..d0bca00 100644 --- a/docs/build/makingschemes.html +++ b/docs/build/makingschemes.html @@ -37,19 +37,23 @@ (0.50, (1.0, 1.0, 0.6)), (0.75, (0.5, 0.36, 0.33)), (1.00, (1.0, 1.0, 1.0))) -terrain = make_colorscheme(terrain_data, length = 50)

"indexed lists scheme"

Functional color schemes

The colors in a 'functional' color scheme are produced by three functions that calculate the color values at each point on the scheme.

The make_colorscheme() function applies the first supplied function at each point on the colorscheme for the red values, the second function for the green values, and the third for the blue. You can use defined functions or supply anonymous ones.

Values produced by the functions are clamped to 0.0 and 1.0 before they're converted to RGB values.

Examples

The first example returns a smooth black to white gradient, because the identity() function gives back as good as it gets.

fscheme = make_colorscheme(identity, identity, identity)

"functional color schemes"

The next example uses the sin() function on values from 0 to π to control the red, and the cos() function from 0 to π to control the blue. The green channel is flat-lined.

fscheme = make_colorscheme((n) -> sin(n*π), (n) -> 0, (n) -> cos(n*π))

"functional color schemes"

You can generate stepped gradients by controlling the numbers. Here, each point on the scheme is nudged to the nearest multiple of 0.1.

fscheme = make_colorscheme(
-        (n) -> round(n, digits=1),
-        (n) -> round(n, digits=1),
-        (n) -> round(n, digits=1), length=10)

"functional color schemes"

The next example sinusoidally sends the red channel from black to red and back again.

fscheme = make_colorscheme(n -> sin(n * π), (n) -> 0, (n) -> 0)

"functional color schemes"

The final example produces a striped colorscheme as the rippling sine waves continually change phase:

ripple7(n)  = sin(π * 7n)
+terrain = make_colorscheme(terrain_data, length = 50)

"indexed lists scheme"

Functional color schemes

The colors in a 'functional' color scheme are produced by three functions that calculate the color values at each point on the scheme.

The make_colorscheme() function applies the first supplied function at each point on the colorscheme for the red values, the second function for the green values, and the third for the blue. You can use defined functions or supply anonymous ones.

Values produced by the functions are clamped to 0.0 and 1.0 before they're converted to RGB values.

Examples

The first example returns a smooth black to white gradient, because the identity() function gives back as good as it gets.

fscheme = make_colorscheme(identity, identity, identity)

"functional color schemes"

The next example uses the sin() function on values from 0 to π to control the red, and the cos() function from 0 to π to control the blue. The green channel is flat-lined.

fscheme = make_colorscheme(n -> sin(n*π), n -> 0, n -> cos(n*π))

"functional color schemes"

You can generate stepped gradients by controlling the numbers. Here, each point on the scheme is nudged to the nearest multiple of 0.1.

fscheme = make_colorscheme(
+        n -> round(n, digits=1),
+        n -> round(n, digits=1),
+        n -> round(n, digits=1), length=10)

"functional color schemes"

The next example sinusoidally sends the red channel from black to red and back again.

fscheme = make_colorscheme(n -> sin(n * π), n -> 0, n -> 0)

"functional color schemes"

The next example produces a striped colorscheme as the rippling sine waves continually change phase:

ripple7(n)  = sin(π * 7n)
 ripple13(n) = sin(π * 13n)
 ripple17(n) = sin(π * 17n)
-fscheme = make_colorscheme(ripple7, ripple13, ripple17, length=80)

"functional color schemes"

make_colorscheme(dict;
+fscheme = make_colorscheme(ripple7, ripple13, ripple17, length=80)

"functional color schemes"

If you're creating a scheme by generating LCHab colors, your functions should convert values between 0 and 1 to values between 0 and 100 (luminance and chroma) or 0 to 360 (hue).

f1(n) = 180 + 180sin(2π * n)
+f2(n) = 50 + 20(0.5 - abs(n - 0.5))
+fscheme = make_colorscheme(n -> 50, f2, f1,
+    length=80,
+    model=:LCHab)

"functional color schemes"

make_colorscheme(dict;
     length=100,
     category="",
-    notes="")

Make a new ColorScheme from a dictionary of linear-segment information. Calls get_linear_segment_color(dict, n) with n for every length value between 0 and 1.

source
make_colorscheme(indexedlist;
+    notes="")

Make a new ColorScheme from a dictionary of linear-segment information. Calls get_linear_segment_color(dict, n) with n for every length value between 0 and 1.

source
make_colorscheme(indexedlist;
     length=100,
     category="",
-    notes="")

Make a colorscheme using an 'indexed list' like this:

gist_rainbow = (
+    notes="")

Make a ColorScheme using an 'indexed list' like this:

gist_rainbow = (
        (0.000, (1.00, 0.00, 0.16)),
        (0.030, (1.00, 0.00, 0.00)),
        (0.215, (1.00, 1.00, 0.00)),
@@ -60,10 +64,11 @@
        (1.000, (1.00, 0.00, 0.75))
 )
 
-make_colorscheme(gist_rainbow)

The first element of this list of tuples is the point on the color scheme.

source
make_colorscheme(redfunction::Function, greenfunction::Function, bluefunction::Function;
-        length=100,
-        category="",
-        notes="")

Make a colorscheme using functions. Each function should return a value between 0 and 1 for that color component at each point on the colorscheme.

source
get_linear_segment_color(dict, n)

Get the RGB color for value n from a dictionary of linear color segments.

A dictionary where red increases from 0 to 1 over the bottom half, green does the same over the middle half, and blue over the top half, looks like this:

cdict = Dict(:red  => ((0.0,  0.0,  0.0),
+make_colorscheme(gist_rainbow)

The first element of each item is the point on the color scheme.

source
make_colorscheme_new(f1::Function, f2::Function, f3::Function;
+    model    = :RGB,
+    length   = 100,
+    category = "",
+    notes    = "functional ColorScheme")

Make a ColorScheme using functions. Each function should take a value between 0 and 1 and return for that color component at each point on the ColorScheme, depending on the color model.

The default color model is :RGB, and the functions should return values in the appropriate range:

  • f1 - [0.0 - 1.0] - red
  • f2 - [0.0 - 1.0] - green
  • f3 - [0.0 - 1.0] - blue

For the :HSV color model:

  • f1 - [0.0 - 360.0] - hue
  • f2 - [0.0 - 1.0] - saturataion
  • f3 - [0.0 - 1.0] - value (brightness)

For the :LCHab color model:

  • f1 - [0.0 - 100.0] - luminance
  • f2 - [0.0 - 100.0] - chroma
  • f3 - [0.0 - 360.0] - hue
source
get_linear_segment_color(dict, n)

Get the RGB color for value n from a dictionary of linear color segments.

This following is a dictionary where red increases from 0 to 1 over the bottom half, green does the same over the middle half, and blue over the top half:

cdict = Dict(:red  => ((0.0,  0.0,  0.0),
                        (0.5,  1.0,  1.0),
                        (1.0,  1.0,  1.0)),
             :green => ((0.0,  0.0,  0.0),
@@ -74,4 +79,4 @@
                        (0.5,  0.0,  0.0),
                        (1.0,  1.0,  1.0)))

The value of RGB component at every value of n is defined by a set of tuples. In each tuple, the first number is x. Colors are linearly interpolated in bands between consecutive values of x; if the first tuple is given by (Z, A, B) and the second tuple by (X, C, D), the color of a point n between Z and X will be given by (n - Z) / (X - Z) * (C - B) + B.

For example, given an entry like this:

:red  => ((0.0, 0.0, 0.0),
           (0.5, 1.0, 1.0),
-          (1.0, 1.0, 1.0))

and if n = 0.75, we return 1.0; 0.75 is between the second and third segments, but we'd already reached 1.0 (segment 2) when n was 0.5.

source
+ (1.0, 1.0, 1.0))

and if n = 0.75, we return 1.0; 0.75 is between the second and third segments, but we'd already reached 1.0 (segment 2) when n was 0.5.

source
diff --git a/docs/build/output.html b/docs/build/output.html index 555416d..5462a5b 100644 --- a/docs/build/output.html +++ b/docs/build/output.html @@ -4,12 +4,14 @@ # 20 pixels for each color, 150 rows img = colorscheme_to_image(ColorSchemes.vermeer, 150, 20) -save("/tmp/cs_vermeer-150-20.png", img)

"vermeer swatch"

The image_to_swatch() function (a shortcut) extracts a n-color scheme from the image and saves it as a swatch in a PNG.

image_to_swatch("/tmp/input.png", 10, "/tmp/output.png")
colorscheme_to_image(cs, nrows=50, tilewidth=5)

Make an image from a colorscheme by repeating the colors in a colorscheme.

Returns the image as an array.

Examples:

using FileIO
+save("/tmp/cs_vermeer-150-20.png", img)

"vermeer swatch"

The image_to_swatch() function (a shortcut) extracts a n-color scheme from a supplied image and saves it as a swatch in a PNG.

image_to_swatch("/tmp/input.png", 10, "/tmp/output.png")
colorscheme_to_image(cs, nrows=50, tilewidth=5)

Make an image from a ColorScheme by repeating the colors in nrows rows, repeating each pixel tilewidth times.

Returns the image as an array.

Examples:

using FileIO
 
 img = colorscheme_to_image(ColorSchemes.leonardo, 50, 200)
 save("/tmp/cs_image.png", img)
 
-save("/tmp/blackbody.png", colorscheme_to_image(ColorSchemes.blackbody, 10, 100))
source
image_to_swatch(imagefilepath, samples, destinationpath; nrows=50, tilewidth=5)

Extract a colorscheme from the image in imagefilepath to a swatch image PNG in destinationpath. This just runs sortcolorscheme(), colorscheme_to_image(), and save() in sequence.

Specify the number of colors. You can also specify the number of rows, and how many times each color is repeated.

image_to_swatch("monalisa.jpg", 10, "/tmp/monalisaswatch.png")
source

Saving colorschemes to text files

You can save a ColorScheme as a (Julia) text file with the imaginatively-titled colorscheme_to_text() function.

Remember to make the name a Julia-friendly one, because it may eventually become a symbol and a dictionary key if the Julia file is include-d.

colorscheme_to_text(ColorSchemes.vermeer,
+save("/tmp/blackbody.png", colorscheme_to_image(ColorSchemes.blackbody, 10, 100))
source
image_to_swatch(imagefilepath, samples, destinationpath;
+    nrows=50,
+    tilewidth=5)

Extract a ColorsSheme from the image in imagefilepath to a swatch image PNG in destinationpath. This just runs sortcolorscheme(), colorscheme_to_image(), and save() in sequence.

Specify the number of colors. You can also specify the number of rows, and how many times each color is repeated.

image_to_swatch("monalisa.jpg", 10, "/tmp/monalisaswatch.png")
source

Saving colorschemes to text files

You can save a ColorScheme as a (Julia) text file with the imaginatively-titled colorscheme_to_text() function.

Remember to make the name a Julia-friendly one, because it may eventually become a symbol and a dictionary key if the Julia file is include-d.

colorscheme_to_text(ColorSchemes.vermeer,
         "the_lost_vermeer",           # name
         "/tmp/the_lost_vermeer.jl",   # filename
         category="dutch painters",    # category
@@ -17,9 +19,9 @@
         )

Of course, if you just want the color definitions, you can simply type:

map(println, ColorSchemes.vermeer.colors);
colorscheme_to_text(cscheme::ColorScheme, schemename, filename;
     category="dutch painters",   # category
     notes="it's not really lost" # notes
-)

Write a colorscheme to a Julia text file.

Example

colorscheme_to_text(ColorSchemes.vermeer,
+)

Write a ColorScheme to a Julia text file.

Example

colorscheme_to_text(ColorSchemes.vermeer,
     "the_lost_vermeer",          # name
     "/tmp/the_lost_vermeer.jl",  # file
     category="dutch painters",   # category
     notes="it's not really lost" # notes
-    )

and read it back in with:

include("/tmp/the_lost_vermeer.jl")
source
+ )

and read it back in with:

include("/tmp/the_lost_vermeer.jl")
source diff --git a/docs/build/search_index.js b/docs/build/search_index.js index 4093eb0..7db6ac5 100644 --- a/docs/build/search_index.js +++ b/docs/build/search_index.js @@ -77,7 +77,7 @@ var documenterSearchIndex = {"docs": [ "page": "Tools", "title": "ColorSchemeTools.colorscheme_weighted", "category": "function", - "text": "colorscheme_weighted(colorscheme, weights, length)\n\nReturns a new colorscheme of length length (default 50) where the proportion of each color in colorscheme is represented by the associated weight of each entry.\n\nExamples:\n\ncolorscheme_weighted(extract_weighted_colors(\"hokusai.jpg\")...)\ncolorscheme_weighted(extract_weighted_colors(\"filename00000001.jpg\")..., 500)\n\n\n\n\n\n" + "text": "colorscheme_weighted(colorscheme, weights, length)\n\nReturns a new ColorScheme of length length (default 50) where the proportion of each color in colorscheme is represented by the associated weight of each entry.\n\nExamples:\n\ncolorscheme_weighted(extract_weighted_colors(\"hokusai.jpg\")...)\ncolorscheme_weighted(extract_weighted_colors(\"filename00000001.jpg\")..., 500)\n\n\n\n\n\n" }, { @@ -109,7 +109,7 @@ var documenterSearchIndex = {"docs": [ "page": "Converting image colors", "title": "ColorSchemeTools.convert_to_scheme", "category": "function", - "text": "convert_to_scheme(cscheme, img)\n\nConverts img from its current color values to use only the colors defined in cscheme.\n\nimage = nonTransparentImg\nconvert_to_scheme(ColorSchemes.leonardo, image)\nconvert_to_scheme(ColorSchemes.Paired_12, image)\n\n\n\n\n\n" + "text": "convert_to_scheme(cscheme, img)\n\nConverts img from its current color values to use only the colors defined in the ColorScheme cscheme.\n\nimage = nonTransparentImg\nconvert_to_scheme(ColorSchemes.leonardo, image)\nconvert_to_scheme(ColorSchemes.Paired_12, image)\n\n\n\n\n\n" }, { @@ -117,7 +117,7 @@ var documenterSearchIndex = {"docs": [ "page": "Converting image colors", "title": "Convert image from one scheme to another", "category": "section", - "text": "Using the ColorSchemes function getinverse() it\'s possible to convert an image using one colorscheme to use another.convert_to_scheme(cscheme, img) returns a new image in which each pixel from the provided image is mapped to its closest matching color in the provided scheme.In the following figure, the Julia logo is converted to use a ColorScheme with no black or white:using FileIO, ColorSchemes, ColorSchemeTools, Images\n\nimg = load(\"julia-logo-square.png\")\nimg_rgb = RGB.(img) # get rid of alpha channel\nconvertedimage = convert_to_scheme(ColorSchemes.PiYG_4, img_rgb)\n\nsave(\"original.png\", img)\nsave(\"converted.png\", convertedimage)(Image: \"julia logo converted\")convert_to_scheme" + "text": "It\'s possible to convert an image using one color scheme to use another.convert_to_scheme(cscheme, img) returns a new image in which each pixel from the provided image is mapped to its closest matching color in the provided scheme. See ColorSchemes\'s getinverse() function for more details on how this works.In the following figure, the Julia logo is converted to use a ColorScheme with no black or white:using FileIO, ColorSchemes, ColorSchemeTools, Images\n\nimg = load(\"julia-logo-square.png\")\nimg_rgb = RGB.(img) # get rid of alpha channel\nconvertedimage = convert_to_scheme(ColorSchemes.PiYG_4, img_rgb)\n\nsave(\"original.png\", img)\nsave(\"converted.png\", convertedimage)(Image: \"julia logo converted\")Notice how the white was matched by the color right at the boundary of the light purple and pale green.convert_to_scheme" }, { @@ -165,7 +165,7 @@ var documenterSearchIndex = {"docs": [ "page": "Making colorschemes", "title": "ColorSchemeTools.make_colorscheme", "category": "function", - "text": "make_colorscheme(dict;\n length=100,\n category=\"\",\n notes=\"\")\n\nMake a new ColorScheme from a dictionary of linear-segment information. Calls get_linear_segment_color(dict, n) with n for every length value between 0 and 1.\n\n\n\n\n\nmake_colorscheme(indexedlist;\n length=100,\n category=\"\",\n notes=\"\")\n\nMake a colorscheme using an \'indexed list\' like this:\n\ngist_rainbow = (\n (0.000, (1.00, 0.00, 0.16)),\n (0.030, (1.00, 0.00, 0.00)),\n (0.215, (1.00, 1.00, 0.00)),\n (0.400, (0.00, 1.00, 0.00)),\n (0.586, (0.00, 1.00, 1.00)),\n (0.770, (0.00, 0.00, 1.00)),\n (0.954, (1.00, 0.00, 1.00)),\n (1.000, (1.00, 0.00, 0.75))\n)\n\nmake_colorscheme(gist_rainbow)\n\nThe first element of this list of tuples is the point on the color scheme.\n\n\n\n\n\nmake_colorscheme(redfunction::Function, greenfunction::Function, bluefunction::Function;\n length=100,\n category=\"\",\n notes=\"\")\n\nMake a colorscheme using functions. Each function should return a value between 0 and 1 for that color component at each point on the colorscheme.\n\n\n\n\n\n" + "text": "make_colorscheme(dict;\n length=100,\n category=\"\",\n notes=\"\")\n\nMake a new ColorScheme from a dictionary of linear-segment information. Calls get_linear_segment_color(dict, n) with n for every length value between 0 and 1.\n\n\n\n\n\nmake_colorscheme(indexedlist;\n length=100,\n category=\"\",\n notes=\"\")\n\nMake a ColorScheme using an \'indexed list\' like this:\n\ngist_rainbow = (\n (0.000, (1.00, 0.00, 0.16)),\n (0.030, (1.00, 0.00, 0.00)),\n (0.215, (1.00, 1.00, 0.00)),\n (0.400, (0.00, 1.00, 0.00)),\n (0.586, (0.00, 1.00, 1.00)),\n (0.770, (0.00, 0.00, 1.00)),\n (0.954, (1.00, 0.00, 1.00)),\n (1.000, (1.00, 0.00, 0.75))\n)\n\nmake_colorscheme(gist_rainbow)\n\nThe first element of each item is the point on the color scheme.\n\n\n\n\n\nmake_colorscheme_new(f1::Function, f2::Function, f3::Function;\n model = :RGB,\n length = 100,\n category = \"\",\n notes = \"functional ColorScheme\")\n\nMake a ColorScheme using functions. Each function should take a value between 0 and 1 and return for that color component at each point on the ColorScheme, depending on the color model.\n\nThe default color model is :RGB, and the functions should return values in the appropriate range:\n\nf1 - [0.0 - 1.0] - red\nf2 - [0.0 - 1.0] - green\nf3 - [0.0 - 1.0] - blue\n\nFor the :HSV color model:\n\nf1 - [0.0 - 360.0] - hue\nf2 - [0.0 - 1.0] - saturataion\nf3 - [0.0 - 1.0] - value (brightness)\n\nFor the :LCHab color model:\n\nf1 - [0.0 - 100.0] - luminance\nf2 - [0.0 - 100.0] - chroma\nf3 - [0.0 - 360.0] - hue\n\n\n\n\n\n" }, { @@ -173,7 +173,7 @@ var documenterSearchIndex = {"docs": [ "page": "Making colorschemes", "title": "ColorSchemeTools.get_linear_segment_color", "category": "function", - "text": "get_linear_segment_color(dict, n)\n\nGet the RGB color for value n from a dictionary of linear color segments.\n\nA dictionary where red increases from 0 to 1 over the bottom half, green does the same over the middle half, and blue over the top half, looks like this:\n\ncdict = Dict(:red => ((0.0, 0.0, 0.0),\n (0.5, 1.0, 1.0),\n (1.0, 1.0, 1.0)),\n :green => ((0.0, 0.0, 0.0),\n (0.25, 0.0, 0.0),\n (0.75, 1.0, 1.0),\n (1.0, 1.0, 1.0)),\n :blue => ((0.0, 0.0, 0.0),\n (0.5, 0.0, 0.0),\n (1.0, 1.0, 1.0)))\n\nThe value of RGB component at every value of n is defined by a set of tuples. In each tuple, the first number is x. Colors are linearly interpolated in bands between consecutive values of x; if the first tuple is given by (Z, A, B) and the second tuple by (X, C, D), the color of a point n between Z and X will be given by (n - Z) / (X - Z) * (C - B) + B.\n\nFor example, given an entry like this:\n\n:red => ((0.0, 0.0, 0.0),\n (0.5, 1.0, 1.0),\n (1.0, 1.0, 1.0))\n\nand if n = 0.75, we return 1.0; 0.75 is between the second and third segments, but we\'d already reached 1.0 (segment 2) when n was 0.5.\n\n\n\n\n\n" + "text": "get_linear_segment_color(dict, n)\n\nGet the RGB color for value n from a dictionary of linear color segments.\n\nThis following is a dictionary where red increases from 0 to 1 over the bottom half, green does the same over the middle half, and blue over the top half:\n\ncdict = Dict(:red => ((0.0, 0.0, 0.0),\n (0.5, 1.0, 1.0),\n (1.0, 1.0, 1.0)),\n :green => ((0.0, 0.0, 0.0),\n (0.25, 0.0, 0.0),\n (0.75, 1.0, 1.0),\n (1.0, 1.0, 1.0)),\n :blue => ((0.0, 0.0, 0.0),\n (0.5, 0.0, 0.0),\n (1.0, 1.0, 1.0)))\n\nThe value of RGB component at every value of n is defined by a set of tuples. In each tuple, the first number is x. Colors are linearly interpolated in bands between consecutive values of x; if the first tuple is given by (Z, A, B) and the second tuple by (X, C, D), the color of a point n between Z and X will be given by (n - Z) / (X - Z) * (C - B) + B.\n\nFor example, given an entry like this:\n\n:red => ((0.0, 0.0, 0.0),\n (0.5, 1.0, 1.0),\n (1.0, 1.0, 1.0))\n\nand if n = 0.75, we return 1.0; 0.75 is between the second and third segments, but we\'d already reached 1.0 (segment 2) when n was 0.5.\n\n\n\n\n\n" }, { @@ -181,7 +181,7 @@ var documenterSearchIndex = {"docs": [ "page": "Making colorschemes", "title": "Examples", "category": "section", - "text": "The first example returns a smooth black to white gradient, because the identity() function gives back as good as it gets.fscheme = make_colorscheme(identity, identity, identity)\ndraw_rgb_levels(fscheme, 800, 200, \"assets/figures/funcscheme1.svg\") # hide\nnothing # hide(Image: \"functional color schemes\")The next example uses the sin() function on values from 0 to π to control the red, and the cos() function from 0 to π to control the blue. The green channel is flat-lined.fscheme = make_colorscheme((n) -> sin(n*π), (n) -> 0, (n) -> cos(n*π))\ndraw_rgb_levels(fscheme, 800, 200, \"assets/figures/funcscheme2.svg\") # hide\nnothing # hide(Image: \"functional color schemes\")You can generate stepped gradients by controlling the numbers. Here, each point on the scheme is nudged to the nearest multiple of 0.1.fscheme = make_colorscheme(\n (n) -> round(n, digits=1),\n (n) -> round(n, digits=1),\n (n) -> round(n, digits=1), length=10)\ndraw_rgb_levels(fscheme, 800, 200, \"assets/figures/funcscheme3.svg\") # hide\nnothing # hide(Image: \"functional color schemes\")The next example sinusoidally sends the red channel from black to red and back again.fscheme = make_colorscheme(n -> sin(n * π), (n) -> 0, (n) -> 0)\ndraw_rgb_levels(fscheme, 800, 200, \"assets/figures/funcscheme4.svg\") # hide\nnothing # hide(Image: \"functional color schemes\")The final example produces a striped colorscheme as the rippling sine waves continually change phase:ripple7(n) = sin(π * 7n)\nripple13(n) = sin(π * 13n)\nripple17(n) = sin(π * 17n)\nfscheme = make_colorscheme(ripple7, ripple13, ripple17, length=80)\ndraw_rgb_levels(fscheme, 800, 200, \"assets/figures/funcscheme5.svg\") # hide\nnothing # hide(Image: \"functional color schemes\")make_colorscheme\nget_linear_segment_color" + "text": "The first example returns a smooth black to white gradient, because the identity() function gives back as good as it gets.fscheme = make_colorscheme(identity, identity, identity)\ndraw_rgb_levels(fscheme, 800, 200, \"assets/figures/funcscheme1.svg\") # hide\nnothing # hide(Image: \"functional color schemes\")The next example uses the sin() function on values from 0 to π to control the red, and the cos() function from 0 to π to control the blue. The green channel is flat-lined.fscheme = make_colorscheme(n -> sin(n*π), n -> 0, n -> cos(n*π))\ndraw_rgb_levels(fscheme, 800, 200, \"assets/figures/funcscheme2.svg\") # hide\nnothing # hide(Image: \"functional color schemes\")You can generate stepped gradients by controlling the numbers. Here, each point on the scheme is nudged to the nearest multiple of 0.1.fscheme = make_colorscheme(\n n -> round(n, digits=1),\n n -> round(n, digits=1),\n n -> round(n, digits=1), length=10)\ndraw_rgb_levels(fscheme, 800, 200, \"assets/figures/funcscheme3.svg\") # hide\nnothing # hide(Image: \"functional color schemes\")The next example sinusoidally sends the red channel from black to red and back again.fscheme = make_colorscheme(n -> sin(n * π), n -> 0, n -> 0)\ndraw_rgb_levels(fscheme, 800, 200, \"assets/figures/funcscheme4.svg\") # hide\nnothing # hide(Image: \"functional color schemes\")The next example produces a striped colorscheme as the rippling sine waves continually change phase:ripple7(n) = sin(π * 7n)\nripple13(n) = sin(π * 13n)\nripple17(n) = sin(π * 17n)\nfscheme = make_colorscheme(ripple7, ripple13, ripple17, length=80)\ndraw_rgb_levels(fscheme, 800, 200, \"assets/figures/funcscheme5.svg\") # hide\nnothing # hide(Image: \"functional color schemes\")If you\'re creating a scheme by generating LCHab colors, your functions should convert values between 0 and 1 to values between 0 and 100 (luminance and chroma) or 0 to 360 (hue).\nf1(n) = 180 + 180sin(2π * n)\nf2(n) = 50 + 20(0.5 - abs(n - 0.5))\nfscheme = make_colorscheme(n -> 50, f2, f1,\n length=80,\n model=:LCHab)\ndraw_rgb_levels(fscheme, 800, 200, \"assets/figures/funcscheme6.svg\") # hide\nnothing # hide(Image: \"functional color schemes\")make_colorscheme\nget_linear_segment_color" }, { @@ -205,7 +205,7 @@ var documenterSearchIndex = {"docs": [ "page": "Saving colorschemes", "title": "ColorSchemeTools.colorscheme_to_image", "category": "function", - "text": "colorscheme_to_image(cs, nrows=50, tilewidth=5)\n\nMake an image from a colorscheme by repeating the colors in a colorscheme.\n\nReturns the image as an array.\n\nExamples:\n\nusing FileIO\n\nimg = colorscheme_to_image(ColorSchemes.leonardo, 50, 200)\nsave(\"/tmp/cs_image.png\", img)\n\nsave(\"/tmp/blackbody.png\", colorscheme_to_image(ColorSchemes.blackbody, 10, 100))\n\n\n\n\n\n" + "text": "colorscheme_to_image(cs, nrows=50, tilewidth=5)\n\nMake an image from a ColorScheme by repeating the colors in nrows rows, repeating each pixel tilewidth times.\n\nReturns the image as an array.\n\nExamples:\n\nusing FileIO\n\nimg = colorscheme_to_image(ColorSchemes.leonardo, 50, 200)\nsave(\"/tmp/cs_image.png\", img)\n\nsave(\"/tmp/blackbody.png\", colorscheme_to_image(ColorSchemes.blackbody, 10, 100))\n\n\n\n\n\n" }, { @@ -213,7 +213,7 @@ var documenterSearchIndex = {"docs": [ "page": "Saving colorschemes", "title": "ColorSchemeTools.image_to_swatch", "category": "function", - "text": "image_to_swatch(imagefilepath, samples, destinationpath; nrows=50, tilewidth=5)\n\nExtract a colorscheme from the image in imagefilepath to a swatch image PNG in destinationpath. This just runs sortcolorscheme(), colorscheme_to_image(), and save() in sequence.\n\nSpecify the number of colors. You can also specify the number of rows, and how many times each color is repeated.\n\nimage_to_swatch(\"monalisa.jpg\", 10, \"/tmp/monalisaswatch.png\")\n\n\n\n\n\n" + "text": "image_to_swatch(imagefilepath, samples, destinationpath;\n nrows=50,\n tilewidth=5)\n\nExtract a ColorsSheme from the image in imagefilepath to a swatch image PNG in destinationpath. This just runs sortcolorscheme(), colorscheme_to_image(), and save() in sequence.\n\nSpecify the number of colors. You can also specify the number of rows, and how many times each color is repeated.\n\nimage_to_swatch(\"monalisa.jpg\", 10, \"/tmp/monalisaswatch.png\")\n\n\n\n\n\n" }, { @@ -221,7 +221,7 @@ var documenterSearchIndex = {"docs": [ "page": "Saving colorschemes", "title": "Saving colorschemes as images", "category": "section", - "text": "Sometimes you want to save a colorscheme, which is usually just a pixel thick, as a swatch or image. You can do this with colorscheme_to_image(). The second argument is the number of rows. The third argument is the number of times each pixel is repeated in the row. The function returns an image which you can save using FileIO\'s save():using FileIO, ColorSchemeTools, Images, Colors\n\n# 20 pixels for each color, 150 rows\nimg = colorscheme_to_image(ColorSchemes.vermeer, 150, 20)\n\nsave(\"/tmp/cs_vermeer-150-20.png\", img)(Image: \"vermeer swatch\")The image_to_swatch() function (a shortcut) extracts a n-color scheme from the image and saves it as a swatch in a PNG.image_to_swatch(\"/tmp/input.png\", 10, \"/tmp/output.png\")colorscheme_to_image\nimage_to_swatch" + "text": "Sometimes you want to save a colorscheme, which is usually just a pixel thick, as a swatch or image. You can do this with colorscheme_to_image(). The second argument is the number of rows. The third argument is the number of times each pixel is repeated in the row. The function returns an image which you can save using FileIO\'s save():using FileIO, ColorSchemeTools, Images, Colors\n\n# 20 pixels for each color, 150 rows\nimg = colorscheme_to_image(ColorSchemes.vermeer, 150, 20)\n\nsave(\"/tmp/cs_vermeer-150-20.png\", img)(Image: \"vermeer swatch\")The image_to_swatch() function (a shortcut) extracts a n-color scheme from a supplied image and saves it as a swatch in a PNG.image_to_swatch(\"/tmp/input.png\", 10, \"/tmp/output.png\")colorscheme_to_image\nimage_to_swatch" }, { @@ -229,7 +229,7 @@ var documenterSearchIndex = {"docs": [ "page": "Saving colorschemes", "title": "ColorSchemeTools.colorscheme_to_text", "category": "function", - "text": "colorscheme_to_text(cscheme::ColorScheme, schemename, filename;\n category=\"dutch painters\", # category\n notes=\"it\'s not really lost\" # notes\n)\n\nWrite a colorscheme to a Julia text file.\n\nExample\n\ncolorscheme_to_text(ColorSchemes.vermeer,\n \"the_lost_vermeer\", # name\n \"/tmp/the_lost_vermeer.jl\", # file\n category=\"dutch painters\", # category\n notes=\"it\'s not really lost\" # notes\n )\n\nand read it back in with:\n\ninclude(\"/tmp/the_lost_vermeer.jl\")\n\n\n\n\n\n" + "text": "colorscheme_to_text(cscheme::ColorScheme, schemename, filename;\n category=\"dutch painters\", # category\n notes=\"it\'s not really lost\" # notes\n)\n\nWrite a ColorScheme to a Julia text file.\n\nExample\n\ncolorscheme_to_text(ColorSchemes.vermeer,\n \"the_lost_vermeer\", # name\n \"/tmp/the_lost_vermeer.jl\", # file\n category=\"dutch painters\", # category\n notes=\"it\'s not really lost\" # notes\n )\n\nand read it back in with:\n\ninclude(\"/tmp/the_lost_vermeer.jl\")\n\n\n\n\n\n" }, { diff --git a/docs/build/tools.html b/docs/build/tools.html index f2522e6..ffe926e 100644 --- a/docs/build/tools.html +++ b/docs/build/tools.html @@ -12,9 +12,9 @@ RGB{Float64}(0.497517,0.4913,0.269587), RGB{Float64}(0.880421,0.851357,0.538013), RGB{Float64}(0.738879,0.709218,0.441082) - ], "", "")

(Extracting color schemes from images may require you to install image importing and exporting abilities. These are platform-specific. On Linux/UNIX, ImageMagick.jl can be used for importing and exporting images. Use QuartzImageIO.jl on macOS.)

extract(imfile, n=10, i=10, tolerance=0.01; shrink=n)

extract() extracts the most common colors from an image from the image file imfile by finding n dominant colors, using i iterations. You can (and probably should) shrink larger images before running this function.

Returns a ColorScheme.

source

Sorting color schemes

Use sortcolorscheme() to sort a scheme non-destructively in the LUV color space:

using ColorSchemes
+    ], "", "")

(Extracting color schemes from images may require you to install image importing and exporting abilities. These are platform-specific. On Linux/UNIX, ImageMagick.jl can be used for importing and exporting images. Use QuartzImageIO.jl on macOS.)

extract(imfile, n=10, i=10, tolerance=0.01; shrink=n)

extract() extracts the most common colors from an image from the image file imfile by finding n dominant colors, using i iterations. You can (and probably should) shrink larger images before running this function.

Returns a ColorScheme.

source

Sorting color schemes

Use sortcolorscheme() to sort a scheme non-destructively in the LUV color space:

using ColorSchemes
 sortcolorscheme(ColorSchemes.leonardo)
-sortcolorscheme(ColorSchemes.leonardo, rev=true)

The default is to sort colors by their LUV luminance value, but you could try specifying the :u or :v LUV fields instead (sorting colors is another problem domain not really addressed in this package...):

sortcolorscheme(ColorSchemes.leonardo, :u)
sortcolorscheme(colorscheme::ColorScheme, field; kwargs...)

Sort (non-destructively) a colorscheme using a field of the LUV colorspace.

The less than function is lt = (x,y) -> compare_colors(x, y, field).

The default is to sort by the luminance field :l but could be by :u or :v.

Returns a new ColorScheme.

source

Weighted colorschemes

Sometimes an image is dominated by some colors with others occurring less frequently. For example, there may be much more brown than yellow in a particular image. A colorscheme derived from this image can reflect this. You can extract both a set of colors and a set of numerical values or weights that indicate the proportions of colors in the image.

cs, wts = extract_weighted_colors("monalisa.jpg", 10, 15, 0.01; shrink=2)

The ColorScheme is now in cs, and wts holds the various weights of each color:

wts
+sortcolorscheme(ColorSchemes.leonardo, rev=true)

The default is to sort colors by their LUV luminance value, but you could try specifying the :u or :v LUV fields instead (sorting colors is another problem domain not really addressed in this package...):

sortcolorscheme(ColorSchemes.leonardo, :u)
sortcolorscheme(colorscheme::ColorScheme, field; kwargs...)

Sort (non-destructively) a colorscheme using a field of the LUV colorspace.

The less than function is lt = (x,y) -> compare_colors(x, y, field).

The default is to sort by the luminance field :l but could be by :u or :v.

Returns a new ColorScheme.

source

Weighted colorschemes

Sometimes an image is dominated by some colors with others occurring less frequently. For example, there may be much more brown than yellow in a particular image. A colorscheme derived from this image can reflect this. You can extract both a set of colors and a set of numerical values or weights that indicate the proportions of colors in the image.

cs, wts = extract_weighted_colors("monalisa.jpg", 10, 15, 0.01; shrink=2)

The ColorScheme is now in cs, and wts holds the various weights of each color:

wts
 
     10-element Array{Float64,1}:
      0.0521126446851636
@@ -27,5 +27,5 @@
      0.08863381567908292
      0.08599068966285295
      0.09193772319937041

With the ColorScheme and the weights, you can make a new color scheme in which the more common colors take up more space in the scheme:

len = 50
-colorscheme_weighted(cs, wts, len)

Or in one go:

colorscheme_weighted(extract_weighted_colors("monalisa.jpg" # ...

Compare the weighted and unweighted versions of schemes extracted from the Hokusai image "The Great Wave":

"unweighted"

"weighted"

extract_weighted_colors(imfile, n=10, i=10, tolerance=0.01; shrink = 2)

Extract colors and weights of the clusters of colors in an image file. Returns a ColorScheme and weights.

Example:

pal, wts = extract_weighted_colors(imfile, n, i, tolerance; shrink = 2)
source
colorscheme_weighted(colorscheme, weights, length)

Returns a new colorscheme of length length (default 50) where the proportion of each color in colorscheme is represented by the associated weight of each entry.

Examples:

colorscheme_weighted(extract_weighted_colors("hokusai.jpg")...)
-colorscheme_weighted(extract_weighted_colors("filename00000001.jpg")..., 500)
source
+colorscheme_weighted(cs, wts, len)

Or in one go:

colorscheme_weighted(extract_weighted_colors("monalisa.jpg" # ...

Compare the weighted and unweighted versions of schemes extracted from the Hokusai image "The Great Wave":

"unweighted"

"weighted"

extract_weighted_colors(imfile, n=10, i=10, tolerance=0.01; shrink = 2)

Extract colors and weights of the clusters of colors in an image file. Returns a ColorScheme and weights.

Example:

pal, wts = extract_weighted_colors(imfile, n, i, tolerance; shrink = 2)
source
colorscheme_weighted(colorscheme, weights, length)

Returns a new ColorScheme of length length (default 50) where the proportion of each color in colorscheme is represented by the associated weight of each entry.

Examples:

colorscheme_weighted(extract_weighted_colors("hokusai.jpg")...)
+colorscheme_weighted(extract_weighted_colors("filename00000001.jpg")..., 500)
source
diff --git a/docs/src/makingschemes.md b/docs/src/makingschemes.md index 40e77c9..98eb7dc 100644 --- a/docs/src/makingschemes.md +++ b/docs/src/makingschemes.md @@ -238,7 +238,7 @@ nothing # hide The next example uses the `sin()` function on values from 0 to π to control the red, and the `cos()` function from 0 to π to control the blue. The green channel is flat-lined. ```@example drawscheme -fscheme = make_colorscheme((n) -> sin(n*π), (n) -> 0, (n) -> cos(n*π)) +fscheme = make_colorscheme(n -> sin(n*π), n -> 0, n -> cos(n*π)) draw_rgb_levels(fscheme, 800, 200, "assets/figures/funcscheme2.svg") # hide nothing # hide ``` @@ -248,9 +248,9 @@ You can generate stepped gradients by controlling the numbers. Here, each point ```@example drawscheme fscheme = make_colorscheme( - (n) -> round(n, digits=1), - (n) -> round(n, digits=1), - (n) -> round(n, digits=1), length=10) + n -> round(n, digits=1), + n -> round(n, digits=1), + n -> round(n, digits=1), length=10) draw_rgb_levels(fscheme, 800, 200, "assets/figures/funcscheme3.svg") # hide nothing # hide ``` @@ -259,13 +259,13 @@ nothing # hide The next example sinusoidally sends the red channel from black to red and back again. ```@example drawscheme -fscheme = make_colorscheme(n -> sin(n * π), (n) -> 0, (n) -> 0) +fscheme = make_colorscheme(n -> sin(n * π), n -> 0, n -> 0) draw_rgb_levels(fscheme, 800, 200, "assets/figures/funcscheme4.svg") # hide nothing # hide ``` !["functional color schemes"](assets/figures/funcscheme4.svg) -The final example produces a striped colorscheme as the rippling sine waves continually change phase: +The next example produces a striped colorscheme as the rippling sine waves continually change phase: ```@example drawscheme ripple7(n) = sin(π * 7n) @@ -277,6 +277,22 @@ nothing # hide ``` !["functional color schemes"](assets/figures/funcscheme5.svg) +If you're creating a scheme by generating LCHab colors, your functions should convert values between 0 and 1 to values between 0 and 100 (luminance and chroma) or 0 to 360 (hue). + +```@example drawscheme + +f1(n) = 180 + 180sin(2π * n) +f2(n) = 50 + 20(0.5 - abs(n - 0.5)) +fscheme = make_colorscheme(n -> 50, f2, f1, + length=80, + model=:LCHab) +draw_rgb_levels(fscheme, 800, 200, "assets/figures/funcscheme6.svg") # hide +nothing # hide +``` + +!["functional color schemes"](assets/figures/funcscheme6.svg) + + ```@docs make_colorscheme get_linear_segment_color diff --git a/src/ColorSchemeTools.jl b/src/ColorSchemeTools.jl index f04b967..fb18865 100644 --- a/src/ColorSchemeTools.jl +++ b/src/ColorSchemeTools.jl @@ -304,25 +304,6 @@ function get_linear_segment_color(dict, n) return result end -""" - make_colorscheme(dict; - length=100, - category="", - notes="") - -Make a new ColorScheme from a dictionary of linear-segment information. Calls -`get_linear_segment_color(dict, n)` with `n` for every `length` value between 0 and 1. -""" -function make_colorscheme(dict::Dict; - length=100, - category="", - notes="") - cs = ColorScheme([RGB(get_linear_segment_color(dict, i)...) - for i in range(0, stop=1, length=length)], - category, notes) - return cs -end - """ lerp((x, from_min, from_max, to_min=0.0, to_max=1.0) @@ -383,6 +364,25 @@ function get_indexed_list_color(indexedlist, n) return round.((r, g, b), digits=6) end +""" + make_colorscheme(dict; + length=100, + category="", + notes="") + +Make a new ColorScheme from a dictionary of linear-segment information. Calls +`get_linear_segment_color(dict, n)` with `n` for every `length` value between 0 and 1. +""" +function make_colorscheme(dict::Dict; + length=100, + category="", + notes="") + cs = ColorScheme([RGB(get_linear_segment_color(dict, i)...) + for i in range(0, stop=1, length=length)], + category, notes) + return cs +end + """ make_colorscheme(indexedlist; length=100, @@ -419,23 +419,68 @@ function make_colorscheme(indexedlist::Tuple; end """ - make_colorscheme(redfunction::Function, greenfunction::Function, bluefunction::Function; - length=100, - category="", - notes="") + make_colorscheme_new(f1::Function, f2::Function, f3::Function; + model = :RGB, + length = 100, + category = "", + notes = "functional ColorScheme") + +Make a ColorScheme using functions. Each function should take a value between 0 +and 1 and return for that color component at each point on the ColorScheme, +depending on the color model. + +The default color model is `:RGB`, and the functions should return values in the +appropriate range: + +- f1 - [0.0 - 1.0] - red +- f2 - [0.0 - 1.0] - green +- f3 - [0.0 - 1.0] - blue + +For the `:HSV` color model: -Make a ColorScheme using functions. Each function should return a value between 0 and 1 for that color component at each point on the ColorScheme. +- f1 - [0.0 - 360.0] - hue +- f2 - [0.0 - 1.0] - saturataion +- f3 - [0.0 - 1.0] - value (brightness) +For the `:LCHab` color model: + +- f1 - [0.0 - 100.0] - luminance +- f2 - [0.0 - 100.0] - chroma +- f3 - [0.0 - 360.0] - hue """ -function make_colorscheme(redf::Function, greenf::Function, bluef::Function; - length=100, - category="", - notes="functional ColorScheme") +function make_colorscheme(f1::Function, f2::Function, f3::Function; + model = :RGB, + length = 100, + category = "", + notes = "functional ColorScheme") + # output is always RGB for the moment cs = RGB[] - for i in range(0, stop=1, length=length) - r, g, b = redf(i), greenf(i), bluef(i) - r, g, b = clamp!([r, g, b], 0.0, 1.0) - push!(cs, RGB(r, g, b)) + if model == :LCHab + clamp1 = (0.0, 100.0) # + clamp2 = (0.0, 100.0) # + clamp3 = (0.0, 360.0) # Hue is 0-360 + elseif model == :HSV + clamp1 = (0.0, 360.0) # Hue is 0-360 + clamp2 = (0.0, 1.0) # + clamp3 = (0.0, 1.0) # + elseif model == :RGB + clamp1 = (0.0, 1.0) # + clamp2 = (0.0, 1.0) # + clamp3 = (0.0, 1.0) # + end + counter = 0 + for i in range(0.0, stop=1.0, length=length) + raw1, raw2, raw3 = f1(i), f2(i), f3(i) + final1 = clamp(raw1, clamp1...) + final2 = clamp(raw2, clamp2...) + final3 = clamp(raw3, clamp3...) + if model == :LCHab + push!(cs, convert(RGB, LCHab(final1, final2, final3))) + elseif model == :RGB + push!(cs, RGB(final1, final2, final3)) + elseif model == :HSV + push!(cs, convert(RGB, HSV(final1, final2, final3))) + end end return ColorScheme(cs, category, notes) end