├── LICENSE
├── README.md
├── colorgraph.js
└── rgbquant.js
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Jack Qiao
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ColorGraph.js
2 |
3 | A color graph is a color palette arranged in an undirected, weighted graph.
4 | see more info on this concept here: http://brandmark.io/color-wheel/discussion/
5 |
6 |
to ->>>
7 |
8 |
9 | colorgraph.js takes an <img> and extracts its color graph. The result is a color palette and an adjacency matrix
10 |
11 | this library is meant for use on browsers, and requires the color quantization library [RgbQuant](https://github.com/leeoniya/RgbQuant.js/)
12 | (can work on node.js as well, but will require the node-canvas library)
13 |
14 | usage:
15 |
16 | 1: quantize an image
17 | ```
18 | // img: html
element
19 | // num: number of colors to quantize into
20 | // use_mode: Boolean, smooth the image using the mode of a 3x3 bucket (removes spurious 1px adjacency noise caused by down-scale sharpening)
21 |
22 | quantized = colorgraph.quantize(img,num,use_mode)
23 |
24 | {
25 | palette: [...], // quantized RGB palette
26 | out: {...}, // quantized datastructure from RgbQuant
27 | canvas: {...}, // quantized canvas for display
28 | sizes: [...] // normalized area of each color in palette
29 | }
30 |
31 | ```
32 |
33 | 2: get color adjacency matrix (this is the node connectivity matrix that defines the graph)
34 | ```
35 | // palette: input RGB palette
36 | // canvas: canvas containing the image
37 | // normalize: Boolean, normalize the adjacency matrix with respect to image perimeter size (for comparing the adjacency matrix of different sized images)
38 |
39 | adjacency = colorgraph.get_connectivity_matrix(quantized.palette, quantized.canvas, normalize)
40 |
41 | // row-major adjacency matrix (ith row = ith palette color)
42 | [
43 | [...]
44 | [...]
45 | [...]
46 | ]
47 | ```
48 |
49 | 3: ColorWheel API (optional)
50 | feel free to use my colorization API, free for non-commercial projects
51 | ```
52 | // model: 'dribbble', 'nes', 'soviet', 'anime', 'animation', 'pixelart', 'poster', 'painting'
53 | // invert: if false, returned palette will be sorted by luminance
54 | // num: number of palettes to return
55 |
56 | var data = {
57 | model: 'dribbble',
58 | quantized: { sizes: quantized.sizes, palette: quantized.palette, adjacency: adjacency },
59 | invert: true,
60 | num: 1
61 | };
62 |
63 | // 0 <= hue <= 1
64 | if(hue >= 0){
65 | data.hue = hue;
66 | }
67 |
68 | // 0 <= saturation <= 1
69 | if(saturation >= 0){
70 | data.saturation = saturation;
71 | }
72 |
73 | $.ajax({
74 | type: "POST",
75 | url: 'http://brandmark.io/color-wheel/api/',
76 | data: {input: JSON.stringify(data)},
77 | success: function(results){
78 | colorgraph.colorize(img, target_canvas, quantized, results[0]);
79 | },
80 | dataType: 'json'
81 | });
82 | ```
83 |
84 | 4: Colorize image
85 |
86 | apply new colors to <canvas> for display purposes
87 | ```
88 | // img: source
89 | // canvas: