channelstats#
- dataeval.metrics.stats.channelstats(images: Iterable[_SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]], flags=ImageStat.ALL_PIXELSTATS) StatsOutput#
Calculates pixel statistics for each image per channel
This function computes pixel-level statistics (e.g., mean, variance, etc.) on a per-channel basis for each image. The statistics can be selected using the flags argument, and the results will be grouped by the number of channels (e.g., RGB channels) in each image.
- Parameters:
images (ArrayLike) – Images to run statistical tests on
flags (ImageStat, default ImageStat.ALL_PIXELSTATS) – Metric(s) to calculate for each image per channel. Only flags within the
ImageStat.ALL_PIXELSTATScategory are supported.
- Returns:
A dictionary-like object containing the computed statistics for each image per channel. The keys correspond to the names of the statistics (e.g., ‘mean’, ‘variance’), and the values are numpy arrays with results for each channel of each image.
- Return type:
StatsOutput
Notes
All metrics in the ImageStat.ALL_PIXELSTATS flag are scaled based on the perceived bit depth (which is derived from the largest pixel value) to allow for better comparison between images stored in different formats and different resolutions.
Examples
Calculating the statistics on a per channel basis for images, whose shape is (N, C, H, W)
>>> results = channelstats(images, flags=ImageStat.MEAN | ImageStat.VAR) >>> print(results.mean) {3: array([[0.01617, 0.5303 , 0.06525, 0.09735, 0.1295 , 0.1616 , 0.1937 , 0.2258 , 0.2578 , 0.29 , 0.322 , 0.3542 , 0.3865 , 0.4185 , 0.4507 , 0.4827 , 0.5146 , 0.547 , 0.579 , 0.6113 , 0.643 , 0.6753 , 0.7075 , 0.7397 , 0.7715 , 0.8037 , 0.836 , 0.868 , 0.9004 , 0.932 ], [0.04828, 0.562 , 0.06726, 0.09937, 0.1315 , 0.1636 , 0.1957 , 0.2278 , 0.26 , 0.292 , 0.3242 , 0.3562 , 0.3884 , 0.4204 , 0.4526 , 0.4846 , 0.5166 , 0.549 , 0.581 , 0.6133 , 0.6455 , 0.6772 , 0.7095 , 0.7417 , 0.774 , 0.8057 , 0.838 , 0.87 , 0.9023 , 0.934 ], [0.0804 , 0.594 , 0.0693 , 0.1014 , 0.1334 , 0.1656 , 0.1978 , 0.2299 , 0.262 , 0.294 , 0.3262 , 0.3584 , 0.3904 , 0.4226 , 0.4546 , 0.4868 , 0.519 , 0.551 , 0.583 , 0.615 , 0.6475 , 0.679 , 0.7114 , 0.7437 , 0.776 , 0.808 , 0.84 , 0.872 , 0.9043 , 0.9365 ]], dtype=float16)} >>> print(results.var) {3: array([[0.00010103, 0.01077 , 0.0001621 , 0.0003605 , 0.0006375 , 0.000993 , 0.001427 , 0.001939 , 0.00253 , 0.003199 , 0.003944 , 0.004772 , 0.005676 , 0.006657 , 0.007717 , 0.00886 , 0.01008 , 0.01137 , 0.01275 , 0.0142 , 0.01573 , 0.01733 , 0.01903 , 0.0208 , 0.02264 , 0.02457 , 0.02657 , 0.02864 , 0.0308 , 0.03305 ], [0.0001798 , 0.0121 , 0.0001721 , 0.0003753 , 0.0006566 , 0.001017 , 0.001455 , 0.001972 , 0.002565 , 0.003239 , 0.00399 , 0.00482 , 0.00573 , 0.006714 , 0.007782 , 0.00893 , 0.01015 , 0.011444 , 0.012825 , 0.01428 , 0.01581 , 0.01743 , 0.01912 , 0.02089 , 0.02274 , 0.02466 , 0.02667 , 0.02875 , 0.03091 , 0.03314 ], [0.000337 , 0.0135 , 0.0001824 , 0.0003903 , 0.0006766 , 0.00104 , 0.001484 , 0.002005 , 0.002604 , 0.00328 , 0.004036 , 0.00487 , 0.005783 , 0.006775 , 0.00784 , 0.00899 , 0.010216 , 0.01152 , 0.0129 , 0.01436 , 0.0159 , 0.01752 , 0.01921 , 0.02098 , 0.02283 , 0.02477 , 0.02676 , 0.02885 , 0.03102 , 0.03326 ]], dtype=float16)}