# calc-image-stats

> Calculate Band Statistics for an Image

Latest version **0.9.0** (published 2023-07-29) · CC0-1.0 license · 0 weekly downloads

## Install

```sh
npm install calc-image-stats
pnpm add calc-image-stats
yarn add calc-image-stats
bun add calc-image-stats
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.0 |
| Published | 2023-07-29 |
| First published | 2021-11-16 |
| Weekly downloads | 0 |
| License | CC0-1.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 21.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Daniel J. Dufour |
| Maintainers | danieljdufour |
| Keywords | calc, image, jpg, png, tif, stats |

## Links

- npm: https://www.npmjs.com/package/calc-image-stats
- Repository: https://github.com/DanielJDufour/calc-image-stats
- Homepage: https://github.com/DanielJDufour/calc-image-stats#readme
- Issues: https://github.com/DanielJDufour/calc-image-stats/issues
- npm.io page: https://npm.io/package/calc-image-stats

## Dependencies (3)

- [xdim](https://npm.io/package/xdim.md) ^1.10.1
- [calc-stats](https://npm.io/package/calc-stats.md) ^2.2.0
- [guess-image-layout](https://npm.io/package/guess-image-layout.md) ^0.1.0

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 0.9.0 (latest) — 2023-07-29
- 0.8.0 — 2023-07-28
- 0.7.0 — 2022-08-21
- 0.6.0 — 2022-07-08
- 0.5.0 — 2022-07-08
- 0.4.0 — 2022-06-25
- 0.3.0 — 2022-06-25
- 0.2.0 — 2022-05-15
- 0.1.0 — 2021-12-09
- 0.0.1 — 2021-11-16

## README

# calc-image-stats
> Calculate Band Statistics for an Image

## features
🦺 memory-safe: uses iterators to avoid copying pixel value arrays  
🚀 fast: uses [calc-stats](https://github.com/danieljdufour/calc-stats), which avoids intermediary calculations  
♦️  dynamic: works on numerical image data in any layout (by using [xdim](https://github.com/danieljdufour/xdim))  
🧭 precise: support for super precise calculations (by using [preciso](https://github.com/danieljdufour/preciso))  
⭐ type-safe: supports [TypeScript](https://www.typescriptlang.org/)

## bash
```bash
npm install calc-image-stats
```

## basic usage
```js
import calcImageStats from "calc-image-stats";

// array of RGBA values of 10x10 image
const data = [
   52,  70,  42, 255, 56,  72, 53, 255,  45,  60,  45, 255,
   37,  54,  30, 255, 62,  85, 48, 255,  70,  88,  53, 255,
   // ... 376 more items
];

const stats = calcImageStats(data, { height: 10, width: 10 });
```
stats will be the following object:
```js
{
  depth: 4, // number of bands
  height: 10,
  width: 10,
  bands: [
    {
      // red band
      count: 100,
      valid: 100,
      invalid: 0,
      median: 87,
      min: 9,
      max: 220,
      sum: 10489,
      range: 211,
      mean: 104.89,
      std: 53.908792418305936,
      modes: [51, 69, 87, 190],
      mode: 99.25
    },
    { ... }, // green band
    { ... }, // blue band
    {
      // alpha band
      count: 100,
      valid: 100,
      invalid: 0,
      median: 255,
      min: 255,
      max: 255,
      sum: 25500,
      range: 0,
      mean: 255,
      std: 0,
      modes: [255],
      mode: 255
    }
  ]
};
```

## advanced usage
```js
const stats = calcImageStats(data, {
   height: 123456,
   precise: true, // calculate using super precise numerical strings
   stats: ["variance"], // choose which stats to calculate
   width: 123456
});

{
  depth: 1, // only 1 band of data
  height: 123456,
  width: 123456,
  bands: [
    {
      // super precise result because we set precise to true
      variance: "1321.41725347154236125321387514273412736"
    }
  ]
}   
```

---
_Source: https://npm.io/package/calc-image-stats · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
