diff --git a/docs/404.html b/docs/404.html index 83249e8..422b9ea 100644 --- a/docs/404.html +++ b/docs/404.html @@ -1,76 +1,35 @@ - - - - + + + + - Page not found (404) • imgpalr - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - -
-
- + +
+ + + - - -
+
+
-
+ + - - diff --git a/docs/CODE_OF_CONDUCT.html b/docs/CODE_OF_CONDUCT.html index f64bb86..d53c2f6 100644 --- a/docs/CODE_OF_CONDUCT.html +++ b/docs/CODE_OF_CONDUCT.html @@ -1,76 +1,12 @@ - - - - - - - -Contributor Code of Conduct • imgpalr - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Contributor Code of Conduct • imgpalr + + - - - - -
-
- -
- -
+
+
-
- - + + diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 648d588..6772005 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -1,76 +1,12 @@ - - - - - - - -License • imgpalr - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -License • imgpalr + + - - - - -
-
- -
- -
+
+
-
- - + + diff --git a/docs/LICENSE.html b/docs/LICENSE.html index 2c8f460..d0b00e0 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -1,76 +1,12 @@ - - - - - - - -MIT License • imgpalr - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -MIT License • imgpalr + + - - - - -
-
- -
- -
+
+
-
- - + + diff --git a/docs/authors.html b/docs/authors.html index 6f324ec..4b46d16 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -1,76 +1,12 @@ - - - - - - - -Authors • imgpalr - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Authors and Citation • imgpalr - - + + - - - -
-
-
- -
+
- @@ -136,22 +79,20 @@

Authors

-
- - + + diff --git a/docs/index.html b/docs/index.html index 568948d..eb06a26 100644 --- a/docs/index.html +++ b/docs/index.html @@ -19,13 +19,17 @@ - + + +
-
-

-
-

-Several hues

+
+

Several hues +

Using an image with several prominent hues, a divergent palette is not sensible here. A sequential is likely best sorted by hue.

Note in the second image below, you can also set quantize = TRUE to show a color-quantized reference thumbnail image based on the derived palette. This makes use of the image_quantmap function. Rather than only quantizing the image, it does so while also mapping the colors of any image to an arbitrary color palette based on nearest distances in RGB space.

-image_pal(x[3], type = "qual", brightness = c(0.4, 1), plot = TRUE)
+image_pal(x[3], type = "qual", brightness = c(0.4, 1), plot = TRUE)

-image_pal(x[3], type = "seq", bw = c(0.2, 1), saturation = c(0.2, 1), 
-          plot = TRUE, quantize = TRUE)
+image_pal(x[3], type = "seq", bw = c(0.2, 1), saturation = c(0.2, 1), + plot = TRUE, quantize = TRUE)

Palette generation uses k-means clustering; results are different each time you call image_pal. If the palette you obtain does not feel right, even with fixed arguments you can run it again to obtain a different palette. Depending on the settings and the nature of the source image, it may change quite a bit. If you need a reproducible palette, set the seed argument. In the example above, the seed was set globally to avoid having to set it in each call to image_pal.

-
-

-Quantize and remap image colors

+
+

Quantize and remap image colors +

You can quantize the colors in an image using image_quantmap directly. Choose any vector of colors. Each pixel has its color mapped to whichever of these colors it is closest to in RGB space. The RGB array is returned. You can plot the image with the palette.

-x <- system.file("blue-yellow.jpg", package = "imgpalr")
-pal <- c("black", "navyblue", "dodgerblue", "yellow")
-a <- image_quantmap(x, pal, k = 7, plot = TRUE)
+x <- system.file("blue-yellow.jpg", package = "imgpalr") +pal <- c("black", "navyblue", "dodgerblue", "yellow") +a <- image_quantmap(x, pal, k = 7, plot = TRUE)

-str(a)
-#>  num [1:317, 1:400, 1:3] 0 0 0 0 0 0 0 0 0 0 ...
+str(a) +#> num [1:317, 1:400, 1:3] 0 0 0 0 0 0 0 0 0 0 ...

This works well if you want to quantize the colors to colors a short distance away in RGB space, but if you want to also swap them out for very different colors, this should be a two step process. If you provide an equal-length vector of colors to the pal2 argument, these colors will replace those in pal after the initial quantization.

-pal2 <- c("darkred", "darkgreen", "tomato", "orange")
-a <- image_quantmap(x, pal, pal2, k = 7, plot = TRUE, show_pal = FALSE)
+pal2 <- c("darkred", "darkgreen", "tomato", "orange") +a <- image_quantmap(x, pal, pal2, k = 7, plot = TRUE, show_pal = FALSE)

Note: This function can be very slow for large k and/or larger images.

-
@@ -254,5 +261,7 @@

Developers

+ + diff --git a/docs/news/index.html b/docs/news/index.html index b0a3ccb..bff5e2f 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -1,76 +1,12 @@ - - - - - - - -Changelog • imgpalr - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Changelog • imgpalr - - + + - - -
-
- -
- -
+
-
-

-imgpalr 0.3.1 Unreleased -

-
    -
  • Documentation updates.
  • -
-
-
-

-imgpalr 0.3.0 2019-11-28 -

-
    -
  • Updates to image_quantmap.
  • +
    + +
    • Added required package alias in documentation.
    • +
    +
    + +
    • Documentation updates.
    • +
    +
    + +
    • Updates to image_quantmap.
    • Use farver package internally in place of grDevices functions.
    • Update documentation.
    • -
    -
    -
    -

    -imgpalr 0.2.2 2019-10-26 -

    -
      -
    • Corrected syntax error in example.
    • +
    +
    + +
    • Corrected syntax error in example.
    • Minor updates to documentation.
    • Fixes unit test file writing issue.
    • -
    -
    -
    -

    -imgpalr 0.2.1 2019-07-26 -

    -
      -
    • Examples and unit tests updated for CRAN release.
    • +
    +
    + +
    • Examples and unit tests updated for CRAN release.
    • Added k argument to image_pal and image_quantmap for control over the number of k-means clusters during initial image processing.
    • Added div_center so that an alternative color can be specified for the midpoint of divergent palettes.
    • -
    -
    -
    -

    -imgpalr 0.2.0 Unreleased -

    -
      -
    • Added image_quantmap function and a quantize argument to image_pal for the preview thumbnail image.
    • +
    +
    + +
    • Added image_quantmap function and a quantize argument to image_pal for the preview thumbnail image.
    • Added unit tests and updated documentation.
    • Made jpeg an imported package per CRAN request for executable example in help docs.
    • -
    -
    -
    -

    -imgpalr 0.1.1 Unreleased -

    -
      -
    • Fix bug in file downloader.
    • -
    -
    -
    -

    -imgpalr 0.1.0 Unreleased -

    -
      -
    • Added package scaffolding.
    • +
    +
    + +
    • Fix bug in file downloader.
    • +
    +
    + +
    • Added package scaffolding.
    • Added initial package functions, documentation, examples and tests.
    • -
    -
    +
+
-
- - + + diff --git a/docs/pkgdown.css b/docs/pkgdown.css index 1273238..80ea5b8 100644 --- a/docs/pkgdown.css +++ b/docs/pkgdown.css @@ -56,8 +56,10 @@ img.icon { float: right; } -img { +/* Ensure in-page images don't run outside their container */ +.contents img { max-width: 100%; + height: auto; } /* Fix bug in bootstrap (only seen in firefox) */ @@ -78,11 +80,10 @@ dd { /* Section anchors ---------------------------------*/ a.anchor { - margin-left: -30px; - display:inline-block; - width: 30px; - height: 30px; - visibility: hidden; + display: none; + margin-left: 5px; + width: 20px; + height: 20px; background-image: url(./link.svg); background-repeat: no-repeat; @@ -90,17 +91,15 @@ a.anchor { background-position: center center; } -.hasAnchor:hover a.anchor { - visibility: visible; -} - -@media (max-width: 767px) { - .hasAnchor:hover a.anchor { - visibility: hidden; - } +h1:hover .anchor, +h2:hover .anchor, +h3:hover .anchor, +h4:hover .anchor, +h5:hover .anchor, +h6:hover .anchor { + display: inline-block; } - /* Fixes for fixed navbar --------------------------*/ .contents h1, .contents h2, .contents h3, .contents h4 { @@ -264,31 +263,26 @@ table { /* Syntax highlighting ---------------------------------------------------- */ -pre { - word-wrap: normal; - word-break: normal; - border: 1px solid #eee; -} - -pre, code { +pre, code, pre code { background-color: #f8f8f8; color: #333; } +pre, pre code { + white-space: pre-wrap; + word-break: break-all; + overflow-wrap: break-word; +} -pre code { - overflow: auto; - word-wrap: normal; - white-space: pre; +pre { + border: 1px solid #eee; } -pre .img { +pre .img, pre .r-plt { margin: 5px 0; } -pre .img img { +pre .img img, pre .r-plt img { background-color: #fff; - display: block; - height: auto; } code a, pre a { @@ -305,9 +299,8 @@ a.sourceLine:hover { .kw {color: #264D66;} /* keyword */ .co {color: #888888;} /* comment */ -.message { color: black; font-weight: bolder;} -.error { color: orange; font-weight: bolder;} -.warning { color: #6A0366; font-weight: bolder;} +.error {font-weight: bolder;} +.warning {font-weight: bolder;} /* Clipboard --------------------------*/ @@ -365,3 +358,27 @@ mark { content: ""; } } + +/* Section anchors --------------------------------- + Added in pandoc 2.11: https://github.com/jgm/pandoc-templates/commit/9904bf71 +*/ + +div.csl-bib-body { } +div.csl-entry { + clear: both; +} +.hanging-indent div.csl-entry { + margin-left:2em; + text-indent:-2em; +} +div.csl-left-margin { + min-width:2em; + float:left; +} +div.csl-right-inline { + margin-left:2em; + padding-left:1em; +} +div.csl-indent { + margin-left: 2em; +} diff --git a/docs/pkgdown.js b/docs/pkgdown.js index 7e7048f..6f0eee4 100644 --- a/docs/pkgdown.js +++ b/docs/pkgdown.js @@ -80,7 +80,7 @@ $(document).ready(function() { var copyButton = ""; - $(".examples, div.sourceCode").addClass("hasCopyButton"); + $("div.sourceCode").addClass("hasCopyButton"); // Insert copy buttons: $(copyButton).prependTo(".hasCopyButton"); @@ -91,7 +91,7 @@ // Initialize clipboard: var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { text: function(trigger) { - return trigger.parentNode.textContent; + return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); } }); diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index db1b182..e7be4d1 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,8 +1,8 @@ -pandoc: 2.7.3 -pkgdown: 1.6.1 +pandoc: 3.1.1 +pkgdown: 2.0.7 pkgdown_sha: ~ articles: {} -last_built: 2021-02-19T19:44Z +last_built: 2023-09-10T02:52Z urls: reference: http://leonawicz.github.io/imgpalr/reference article: http://leonawicz.github.io/imgpalr/articles diff --git a/docs/reference/figures/README-example-1.png b/docs/reference/figures/README-example-1.png index 7debb83..80312f8 100644 Binary files a/docs/reference/figures/README-example-1.png and b/docs/reference/figures/README-example-1.png differ diff --git a/docs/reference/figures/README-example-2.png b/docs/reference/figures/README-example-2.png index 9823e04..4fa07ab 100644 Binary files a/docs/reference/figures/README-example-2.png and b/docs/reference/figures/README-example-2.png differ diff --git a/docs/reference/figures/README-example-3.png b/docs/reference/figures/README-example-3.png index f87952f..c7c69fc 100644 Binary files a/docs/reference/figures/README-example-3.png and b/docs/reference/figures/README-example-3.png differ diff --git a/docs/reference/figures/README-example2-1.png b/docs/reference/figures/README-example2-1.png index 1e07994..a1e12ca 100644 Binary files a/docs/reference/figures/README-example2-1.png and b/docs/reference/figures/README-example2-1.png differ diff --git a/docs/reference/figures/README-example2-2.png b/docs/reference/figures/README-example2-2.png index ac3d36b..955496c 100644 Binary files a/docs/reference/figures/README-example2-2.png and b/docs/reference/figures/README-example2-2.png differ diff --git a/docs/reference/figures/README-example2-3.png b/docs/reference/figures/README-example2-3.png index f1c0b1d..12ef4d0 100644 Binary files a/docs/reference/figures/README-example2-3.png and b/docs/reference/figures/README-example2-3.png differ diff --git a/docs/reference/figures/README-example3-1.png b/docs/reference/figures/README-example3-1.png index 3e44365..da1961c 100644 Binary files a/docs/reference/figures/README-example3-1.png and b/docs/reference/figures/README-example3-1.png differ diff --git a/docs/reference/figures/README-example3-2.png b/docs/reference/figures/README-example3-2.png index 34b3008..038af31 100644 Binary files a/docs/reference/figures/README-example3-2.png and b/docs/reference/figures/README-example3-2.png differ diff --git a/docs/reference/figures/README-quantmap-1.png b/docs/reference/figures/README-quantmap-1.png index f93e750..650ba4a 100644 Binary files a/docs/reference/figures/README-quantmap-1.png and b/docs/reference/figures/README-quantmap-1.png differ diff --git a/docs/reference/figures/README-quantmap2-1.png b/docs/reference/figures/README-quantmap2-1.png index d5e4786..8f6710e 100644 Binary files a/docs/reference/figures/README-quantmap2-1.png and b/docs/reference/figures/README-quantmap2-1.png differ diff --git a/docs/reference/image_load.html b/docs/reference/image_load.html index 326bd6e..5cbfcbe 100644 --- a/docs/reference/image_load.html +++ b/docs/reference/image_load.html @@ -1,77 +1,12 @@ - - - - - - - -Load PNG, JPG, BMP or GIF — image_load • imgpalr - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Load PNG, JPG, BMP or GIF — image_load • imgpalr - - - - + + -
-
- -
- -
+
@@ -130,60 +52,83 @@

Load PNG, JPG, BMP or GIF

Load PNG, JPG, BMP or GIF from disk or URL.

-
image_load(file)
- -

Arguments

- - - - - - -
file

character, file name. A local file or URL. Extension must be one of png, jpg, jpeg, bmp or gif.

+
+
image_load(file)
+
-

Value

+
+

Arguments

+
file
+

character, file name. A local file or URL. Extension must be one of png, jpg, jpeg, bmp or gif.

-

an RBG array

-

Details

+
+
+

Value

+ +

an RBG array

+
+
+

Details

The function will prompt you of the need to install a format-specific package if not installed and needed for the given file extension; png, bmp, magick (for GIF). jpeg is already imported for purpose of running examples.

+
-

Examples

-
x <- paste0(system.file(package = "imgpalr"), "/blue-yellow.", - c("jpg", "png", "bmp", "gif")) -str(image_load(x[1])) -
#> num [1:317, 1:400, 1:3] 0.208 0.149 0.125 0.153 0.157 ...
if(require(png)) str(image_load(x[2])) -
#> Loading required package: png
#> num [1:158, 1:200, 1:3] 0.153 0.122 0.137 0.133 0.208 ...
if(require(bmp)) str(image_load(x[3])) -
#> Loading required package: bmp
#> Warning: there is no package called 'bmp'
if(require(magick)) str(image_load(x[4])) -
#> Loading required package: magick
#> Linking to ImageMagick 6.9.11.57 -#> Enabled features: cairo, freetype, fftw, ghostscript, heic, lcms, pango, raw, rsvg, webp -#> Disabled features: fontconfig, x11
#> num [1:158, 1:200, 1:3] 0.129 0.102 0.114 0.129 0.196 ...
+
+

Examples

+
x <- paste0(system.file(package = "imgpalr"), "/blue-yellow.",
+  c("jpg", "png", "bmp", "gif"))
+str(image_load(x[1]))
+#>  num [1:317, 1:400, 1:3] 0.216 0.149 0.125 0.161 0.157 ...
+if(require(png)) str(image_load(x[2]))
+#> Loading required package: png
+#>  num [1:158, 1:200, 1:3] 0.153 0.122 0.137 0.133 0.208 ...
+if(require(bmp)) str(image_load(x[3]))
+#> Loading required package: bmp
+#>  num [1:158, 1:200, 1:3] 0.153 0.122 0.137 0.133 0.208 ...
+#>  - attr(*, "header")=List of 13
+#>   ..$ filesize     : num 94854
+#>   ..$ offset       : num 54
+#>   ..$ header_sz    : num 40
+#>   ..$ width        : num 200
+#>   ..$ height       : num 158
+#>   ..$ nplanes      : int 1
+#>   ..$ depth        : int 24
+#>   ..$ compress_type: num 0
+#>   ..$ bmp_bytesz   : num 94800
+#>   ..$ hres         : num 2835
+#>   ..$ vres         : num 2835
+#>   ..$ ncolors      : num 0
+#>   ..$ nimpcolors   : num 0
+if(require(magick)) str(image_load(x[4]))
+#> Loading required package: magick
+#> Linking to ImageMagick 6.9.12.93
+#> Enabled features: cairo, freetype, fftw, ghostscript, heic, lcms, pango, raw, rsvg, webp
+#> Disabled features: fontconfig, x11
+#>  num [1:158, 1:200, 1:3] 0.129 0.102 0.114 0.129 0.196 ...
+
+
+
-
- - + + diff --git a/docs/reference/image_pal-1.png b/docs/reference/image_pal-1.png index 930c7e4..28480b7 100644 Binary files a/docs/reference/image_pal-1.png and b/docs/reference/image_pal-1.png differ diff --git a/docs/reference/image_pal.html b/docs/reference/image_pal.html index 72a472c..8bd02a5 100644 --- a/docs/reference/image_pal.html +++ b/docs/reference/image_pal.html @@ -1,77 +1,12 @@ - - - - - - - -Create a color palette from an image — image_pal • imgpalr - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Create a color palette from an image — image_pal • imgpalr - - - - + + -
-
- -
- -
+
@@ -130,99 +52,101 @@

Create a color palette from an image

Derive qualitative, sequential and divergent color palettes from an image on disk or at a URL.

-
image_pal(
-  file,
-  n = 9,
-  type = c("qual", "seq", "div"),
-  k = 100,
-  bw = c(0, 1),
-  brightness = c(0, 1),
-  saturation = c(0, 1),
-  seq_by = "hsv",
-  div_center = "#FFFFFF",
-  seed = NULL,
-  plot = FALSE,
-  labels = TRUE,
-  label_size = 1,
-  label_color = "#000000",
-  keep_asp = TRUE,
-  quantize = FALSE
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
file

character, file path or URL to an image.

n

integer, number of colors.

type

character, type of palette: qualitative, sequential or divergent ("qual", "seq", or "div").

k

integer, the number of k-means cluster centers to consider in the image. See details.

bw

a numeric vector of length two giving the lower and upper quantiles to trim trim near-black and near-white colors in RGB space.

brightness

as above, trim possible colors based on brightness in HSV space.

saturation

as above, trim possible colors based on saturation in HSV space.

seq_by

character, sort sequential palette by HSV dimensions in a specific order, e.g., "hsv", "svh". See details.

div_center

character, color used for divergent palette center, defaults to white.

seed

numeric, set the seed for reproducible results.

plot

logical, plot the palette.

labels

logical, show hex color values in plot.

label_size

numeric, label size in plot.

label_color

text label color.

keep_asp

logical, adjust rectangles in plot to use the image aspect ratio.

quantize

logical, quantize the reference thumbnail image in the plot using the derived color palette. See image_quantmap.

- -

Value

- -

character vector of hex colors, optionally draws a plot

-

Details

+
+
image_pal(
+  file,
+  n = 9,
+  type = c("qual", "seq", "div"),
+  k = 100,
+  bw = c(0, 1),
+  brightness = c(0, 1),
+  saturation = c(0, 1),
+  seq_by = "hsv",
+  div_center = "#FFFFFF",
+  seed = NULL,
+  plot = FALSE,
+  labels = TRUE,
+  label_size = 1,
+  label_color = "#000000",
+  keep_asp = TRUE,
+  quantize = FALSE
+)
+
+ +
+

Arguments

+
file
+

character, file path or URL to an image.

+ + +
n
+

integer, number of colors.

+ + +
type
+

character, type of palette: qualitative, sequential or divergent ("qual", "seq", or "div").

+ + +
k
+

integer, the number of k-means cluster centers to consider in the image. See details.

+ +
bw
+

a numeric vector of length two giving the lower and upper quantiles to trim trim near-black and near-white colors in RGB space.

+ + +
brightness
+

as above, trim possible colors based on brightness in HSV space.

+ + +
saturation
+

as above, trim possible colors based on saturation in HSV space.

+ + +
seq_by
+

character, sort sequential palette by HSV dimensions in a specific order, e.g., "hsv", "svh". See details.

+ + +
div_center
+

character, color used for divergent palette center, defaults to white.

+ + +
seed
+

numeric, set the seed for reproducible results.

+ + +
plot
+

logical, plot the palette.

+ + +
labels
+

logical, show hex color values in plot.

+ + +
label_size
+

numeric, label size in plot.

+ + +
label_color
+

text label color.

+ + +
keep_asp
+

logical, adjust rectangles in plot to use the image aspect ratio.

+ + +
quantize
+

logical, quantize the reference thumbnail image in the plot using the derived color palette. See image_quantmap.

+ +
+
+

Value

+ + +

character vector of hex colors, optionally draws a plot

+
+
+

Details

Ordering colors is a challenging problem. There are many ways to do it; none are perfect. Color is a multi-dimensional property; any reduction to a a one dimensional color spectrum necessarily removes information.

Creating a sequential palette from an arbitrary image that contains several hues, at different saturation and brightness levels, and making a palette that looks sequential is particularly problematic. @@ -233,72 +157,78 @@

Details This is different from n, the number of colors are desired in the derived palette. It is limited by the number of unique colors in the image. Larger k may allow for better palette construction under some conditions, but takes longer to run. k applies to sequential and qualitative palettes, but not divergent palettes.

-

Trimming color distribution

- +
+
+

Trimming color distribution

Some pre-processing can be done to limit undesirable colors from ending up in a palette. bw specifically drops near-black and near-white colors as soon as the image is loaded by looking at the average values in RGB space. brightness and saturation trimming are applied subsequently to trim lower and upper quantiles of the HSV value and saturation, respectively. If you have already trimmed black and white, keep in mind these two arguments will trim further from what remains of the color distribution.

-

Choosing appropriate palette type

- +
+
+

Choosing appropriate palette type

Keep in mind that many images simple do not make sense to try to derive sensible color palettes from. For images that do lend themselves to a useful color palette derivation, some may only make sense to consider for a divergent palette, or an increasing/decreasing sequential palette, or only a qualitative palette if there are too many colors that are difficult to order. For divergent palettes in particular, it is recommended to trim white, e.g. bw = c(0, 0.9), depending on the white space of a given image, since the divergent palettes are centered on white.

-

Sorting sequential palettes

- +
+
+

Sorting sequential palettes

seq_by = "hsv" orders the final palette by hue, then saturation, then value (brightness). This default is not meant to be ideal for all images. It work better in cases where sequential palettes may contain several distinct hues, but not much variation in saturation or brightness. However, for example, palettes derived from an image with relatively little variation in hue may appear more sorted to the human eye if ordered by hue last using "svh" or "vsh", depending on whether you want the palette to appear to transition more from lower saturation or lower brightness to the predominant hue.

-

See also

- - - -

Examples

-
set.seed(1) -x <- system.file("blue-yellow.jpg", package = "imgpalr") - -# Focus on bright, saturated colors for divergent palette: -image_pal(x, n = 3, type = "div", - saturation = c(0.75, 1), brightness = c(0.75, 1), plot = TRUE) -
#> [1] "#4A66A2" "#FFFFFF" "#B4A337"
-# \donttest{ -image_pal(x, n = 5, type = "seq", k = 2, saturation = c(0.5, 1), - brightness = c(0.25, 1), seq_by = "hsv") -
#> [1] "#A8A44D" "#8E905A" "#747D68" "#596A76" "#405784"
# } -
+
+
+

See also

+ +
+ +
+

Examples

+
set.seed(1)
+x <- system.file("blue-yellow.jpg", package = "imgpalr")
+
+# Focus on bright, saturated colors for divergent palette:
+image_pal(x, n = 3, type = "div",
+  saturation = c(0.75, 1), brightness = c(0.75, 1), plot = TRUE)
+
+#> [1] "#B5A335" "#FFFFFF" "#4966A3"
+
+# \donttest{
+image_pal(x, n = 5, type = "seq", k = 2, saturation = c(0.5, 1),
+  brightness = c(0.25, 1), seq_by = "hsv")
+#> [1] "#A6A34B" "#8C9059" "#737D67" "#596975" "#405784"
+# }
+
+
+
-
- - + + diff --git a/docs/reference/image_quantmap-1.png b/docs/reference/image_quantmap-1.png index 4702917..6b936e3 100644 Binary files a/docs/reference/image_quantmap-1.png and b/docs/reference/image_quantmap-1.png differ diff --git a/docs/reference/image_quantmap-2.png b/docs/reference/image_quantmap-2.png index dff2151..7d8e1e3 100644 Binary files a/docs/reference/image_quantmap-2.png and b/docs/reference/image_quantmap-2.png differ diff --git a/docs/reference/image_quantmap.html b/docs/reference/image_quantmap.html index d0f259f..36441dd 100644 --- a/docs/reference/image_quantmap.html +++ b/docs/reference/image_quantmap.html @@ -1,77 +1,12 @@ - - - - - - - -Quantize an image using an existing color palette — image_quantmap • imgpalr - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Quantize an image using an existing color palette — image_quantmap • imgpalr - - + + - - -
-
- -
- -
+
@@ -130,70 +52,72 @@

Quantize an image using an existing color palette

Quantize image colors by mapping all pixels to the nearest color in RGB space, respectively, given an arbitrary palette.

-
image_quantmap(
-  file,
-  pal,
-  pal2 = NULL,
-  k = 100,
-  plot = FALSE,
-  show_pal = TRUE,
-  labels = TRUE,
-  label_size = 1,
-  label_color = "#000000",
-  keep_asp = TRUE
-)
- -

Arguments

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
file

if character, file path or URL to an image. You can also provide an RGB array from an already loaded image file.

pal

character, vector of hex colors, the color palette used to quantize the image colors.

pal2

character, optional vector of hex colors, same length as pal. -After quantizing image to pal, you can subsequently remap pal to pal2.

k

integer, the number of k-means cluster centers to consider in the image. See details.

plot

logical, plot the palette with quantized image reference thumbnail. If FALSE, only return the RGB array.

show_pal

logical, show the palette like with image_pal. If FALSE, plot only the image; all subsequent arguments ignored.

labels

logical, show hex color values in plot.

label_size

numeric, label size in plot.

label_color

text label color.

keep_asp

logical, adjust rectangles in plot to use the image aspect ratio.

- -

Value

- -

an RGB array with values ranging from 0 to 1

-

Details

+
+
image_quantmap(
+  file,
+  pal,
+  pal2 = NULL,
+  k = 100,
+  plot = FALSE,
+  show_pal = TRUE,
+  labels = TRUE,
+  label_size = 1,
+  label_color = "#000000",
+  keep_asp = TRUE
+)
+
+ +
+

Arguments

+
file
+

if character, file path or URL to an image. You can also provide an RGB array from an already loaded image file.

+ + +
pal
+

character, vector of hex colors, the color palette used to quantize the image colors.

+ + +
pal2
+

character, optional vector of hex colors, same length as pal. +After quantizing image to pal, you can subsequently remap pal to pal2.

+ + +
k
+

integer, the number of k-means cluster centers to consider in the image. See details.

+ + +
plot
+

logical, plot the palette with quantized image reference thumbnail. If FALSE, only return the RGB array.

+ + +
show_pal
+

logical, show the palette like with image_pal. If FALSE, plot only the image; all subsequent arguments ignored.

+ + +
labels
+

logical, show hex color values in plot.

+ +
label_size
+

numeric, label size in plot.

+ + +
label_color
+

text label color.

+ + +
keep_asp
+

logical, adjust rectangles in plot to use the image aspect ratio.

+ +
+
+

Value

+ + +

an RGB array with values ranging from 0 to 1

+
+
+

Details

The palette pal does not need to be related to the image colors. Each pixel will be assigned to whichever color in pal that it is nearest to in RGB space. You can use pal2 to remap to arbitrary colors after quantizing. @@ -201,45 +125,48 @@

Details The number of k-means centers k is for binning image colors prior to mapping the palette pal. It is limited by the number of unique colors in the image. Larger k provides more binned distances between image colors and palette colors, but takes longer to run.

-

See also

- - - -

Examples

-
x <- system.file("blue-yellow.jpg", package = "imgpalr") -pal <- c("black", "navyblue", "dodgerblue", "yellow") -pal2 <- c("darkred", "darkgreen", "tomato", "orange") +
+
+

See also

+ +
-a <- image_quantmap(x, pal, k = 7, plot = TRUE) -
str(a) -
#> num [1:317, 1:400, 1:3] 0 0 0 0 0 0 0 0 0 0 ...
-a <- image_quantmap(x, pal, pal2, k = 7, plot = TRUE) -
+
+

Examples

+
x <- system.file("blue-yellow.jpg", package = "imgpalr")
+pal <- c("black", "navyblue", "dodgerblue", "yellow")
+pal2 <- c("darkred", "darkgreen", "tomato", "orange")
+
+a <- image_quantmap(x, pal, k = 7, plot = TRUE)
+
+str(a)
+#>  num [1:317, 1:400, 1:3] 0 0 0 0 0 0 0 0 0 0 ...
+
+a <- image_quantmap(x, pal, pal2, k = 7, plot = TRUE)
+
+
+
+
- - - + + diff --git a/docs/reference/imgpalr.html b/docs/reference/imgpalr.html index 5d41b27..68e010f 100644 --- a/docs/reference/imgpalr.html +++ b/docs/reference/imgpalr.html @@ -1,81 +1,16 @@ - - - - - - - -imgpalr: Create color palettes from images — imgpalr • imgpalr - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -imgpalr: Create color palettes from images — imgpalr • imgpalr - - - - - - - - - - + + - - - - -
-
- -
- -
+
@@ -140,32 +62,27 @@

imgpalr: Create color palettes from images

-
+
-
- - + + diff --git a/docs/reference/index.html b/docs/reference/index.html index e4b9835..c3b7483 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -1,76 +1,12 @@ - - - - - - - -Function reference • imgpalr - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Function reference • imgpalr - + + - - - -
-
- -
- -
+
- - - - - - - - - - -
-

Package

+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+

Package

-

imgpalr

+
+

imgpalr imgpalr-package

imgpalr: Create color palettes from images

-

Functions

+
+

Functions

+

image_pal()

Create a color palette from an image

+

image_quantmap()

Quantize an image using an existing color palette

+

image_load()

Load PNG, JPG, BMP or GIF

- +
+
-
- - + + diff --git a/docs/sitemap.xml b/docs/sitemap.xml index f3d476a..e23f08a 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -1,8 +1,26 @@ + + http://leonawicz.github.io/imgpalr/404.html + + + http://leonawicz.github.io/imgpalr/authors.html + + + http://leonawicz.github.io/imgpalr/CODE_OF_CONDUCT.html + http://leonawicz.github.io/imgpalr/index.html + + http://leonawicz.github.io/imgpalr/LICENSE-text.html + + + http://leonawicz.github.io/imgpalr/LICENSE.html + + + http://leonawicz.github.io/imgpalr/news/index.html + http://leonawicz.github.io/imgpalr/reference/image_load.html @@ -15,4 +33,7 @@ http://leonawicz.github.io/imgpalr/reference/imgpalr.html + + http://leonawicz.github.io/imgpalr/reference/index.html +