@thi.ng/pixel-analysis 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2025-07-10T14:20:23Z
3
+ - **Last updated**: 2025-07-14T10:38:44Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -11,6 +11,14 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
11
11
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
12
12
  and/or version bumps of transitive dependencies.
13
13
 
14
+ ## [0.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/pixel-analysis@0.4.0) (2025-07-14)
15
+
16
+ #### 🚀 Features
17
+
18
+ - add color channel precision ([beb2c21](https://github.com/thi-ng/umbrella/commit/beb2c21))
19
+ - add `AnalysisOpts.prec`
20
+ - update `analyzeColors()`
21
+
14
22
  ## [0.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/pixel-analysis@0.3.0) (2025-06-24)
15
23
 
16
24
  #### 🚀 Features
package/analyze-colors.js CHANGED
@@ -21,6 +21,7 @@ import { pluck } from "@thi.ng/transducers/pluck";
21
21
  import { reduce } from "@thi.ng/transducers/reduce";
22
22
  import { transduce } from "@thi.ng/transducers/transduce";
23
23
  import { dot } from "@thi.ng/vectors/dot";
24
+ import { roundN } from "@thi.ng/vectors/roundn";
24
25
  import { warmIntensityHsv } from "./hues.js";
25
26
  const analyzeColors = (img, opts) => {
26
27
  let $img = img.format !== FLOAT_RGBA ? img.as(FLOAT_RGBA) : img;
@@ -34,9 +35,11 @@ const analyzeColors = (img, opts) => {
34
35
  const imgGray = $img.as(FLOAT_GRAY);
35
36
  const imgHsv = $img.as(FLOAT_HSVA);
36
37
  const dominantColors = opts?.dominantFn ?? dominantColorsKmeans;
37
- const colors = dominantColors($img, opts?.numColors ?? 4).sort(
38
- compareByKey("area", compareNumDesc)
39
- );
38
+ const prec = opts?.prec ?? 1e-3;
39
+ const colors = dominantColors($img, opts?.numColors ?? 4).sort(compareByKey("area", compareNumDesc)).map((x) => {
40
+ roundN(null, x.color, prec);
41
+ return x;
42
+ });
40
43
  const colorAreas = colors.map((x) => x.area);
41
44
  const dominantLuma = colors.map((x) => luminanceSrgb(x.color));
42
45
  const dominantSrgb = colors.map((x) => srgb(x.color));
package/api.d.ts CHANGED
@@ -20,6 +20,12 @@ export interface AnalysisOpts {
20
20
  * Min. saturation to consider for computing {@link warmIntensity}.
21
21
  */
22
22
  minSat: number;
23
+ /**
24
+ * Channel precision for dominant colors.
25
+ *
26
+ * @defaultValue 0.001
27
+ */
28
+ prec: number;
23
29
  }
24
30
  export interface AnalyzedImage {
25
31
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/pixel-analysis",
3
- "version": "0.3.3",
3
+ "version": "0.4.0",
4
4
  "description": "Image color & feature analysis utilities",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -40,14 +40,14 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@thi.ng/api": "^8.11.30",
43
- "@thi.ng/color": "^5.7.45",
43
+ "@thi.ng/color": "^5.7.46",
44
44
  "@thi.ng/compare": "^2.4.22",
45
45
  "@thi.ng/math": "^5.11.30",
46
46
  "@thi.ng/pixel": "^7.5.2",
47
47
  "@thi.ng/pixel-convolve": "^1.1.2",
48
- "@thi.ng/pixel-dominant-colors": "^2.0.1",
48
+ "@thi.ng/pixel-dominant-colors": "^2.0.2",
49
49
  "@thi.ng/transducers": "^9.6.0",
50
- "@thi.ng/vectors": "^8.3.2"
50
+ "@thi.ng/vectors": "^8.3.3"
51
51
  },
52
52
  "devDependencies": {
53
53
  "esbuild": "^0.25.6",
@@ -107,5 +107,5 @@
107
107
  "status": "beta",
108
108
  "year": 2024
109
109
  },
110
- "gitHead": "a81765bd79046980463c56a8bd187f9aaa88dd65\n"
110
+ "gitHead": "89a9dc2519be2461de39381de3c13e2771178c39\n"
111
111
  }