npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

calc-image-stats

v0.9.0

Published

Calculate Band Statistics for an Image

Downloads

8,359

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, which avoids intermediary calculations
♦️ dynamic: works on numerical image data in any layout (by using xdim)
🧭 precise: support for super precise calculations (by using preciso)
⭐ type-safe: supports TypeScript

bash

npm install calc-image-stats

basic usage

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:

{
  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

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"
    }
  ]
}