class_docstr: This class provides a way to calculate a reasonable output voxel spacing according to
  the input dataset. The achieved values can used to resample the input in 3d segmentation tasks
  (like using as the `pixdim` parameter in `monai.transforms.Spacingd`).
  In addition, it also supports to compute the mean, std, min and max intensities of the input,
  and these statistics are helpful for image normalization
  (as parameters of `monai.transforms.ScaleIntensityRanged` and `monai.transforms.NormalizeIntensityd`).
  
  The algorithm for calculation refers to:
  `Automated Design of Deep Learning Methods for Biomedical Image Segmentation <https://arxiv.org/abs/1904.08128>`_.
class_docstr_tok: ["This","class","provides","a","way","to","calculate","a","reasonable","output","voxel","spacing","according","to","the","input","dataset",".","The","achieved","values","can","used","to","resample","the","input","in","3d","segmentation","tasks","(","like","using","as","the","`","pixdim","`","parameter","in","`","monai.transforms.Spacingd","`",")",".","In","addition",",","it","also","supports","to","compute","the","mean",",","std",",","min","and","max","intensities","of","the","input",",","and","these","statistics","are","helpful","for","image","normalization","(","as","parameters","of","`","monai.transforms.ScaleIntensityRanged","`","and","`","monai.transforms.NormalizeIntensityd","`",")",".","The","algorithm","for","calculation","refers","to",":","`","Automated","Design","of","Deep","Learning","Methods","for","Biomedical","Image","Segmentation","<","https",":","\/\/arxiv.org\/abs\/1904.08128",">","`","_","."]
docstr: This function is used to calculate the maximum, minimum, mean and standard deviation of intensities of
  the input dataset.
  
  Args:
      foreground_threshold: the threshold to distinguish if a voxel belongs to foreground, this parameter
          is used to select the foreground of images for calculation. Normally, `label > 0` means the corresponding
          voxel belongs to foreground, thus if you need to calculate the statistics for whole images, you can set
          the threshold to ``-1`` (default: ``0``).
docstr_tok: ["This","function","is","used","to","calculate","the","maximum",",","minimum",",","mean","and","standard","deviation","of","intensities","of","the","input","dataset",".","Args",":","foreground_threshold",":","the","threshold","to","distinguish","if","a","voxel","belongs","to","foreground",",","this","parameter","is","used","to","select","the","foreground","of","images","for","calculation",".","Normally",",","`","label",">","0","`","means","the","corresponding","voxel","belongs","to","foreground",",","thus","if","you","need","to","calculate","the","statistics","for","whole","images",",","you","can","set","the","threshold","to","``","-1","``","(","default",":","``","0","``",")","."]
code: def calculate_statistics(self, foreground_threshold: int = 0):
      """
      This function is used to calculate the maximum, minimum, mean and standard deviation of intensities of
      the input dataset.
  
      Args:
          foreground_threshold: the threshold to distinguish if a voxel belongs to foreground, this parameter
              is used to select the foreground of images for calculation. Normally, `label > 0` means the corresponding
              voxel belongs to foreground, thus if you need to calculate the statistics for whole images, you can set
              the threshold to ``-1`` (default: ``0``).
  
      """
      voxel_sum = torch.as_tensor(0.0)
      voxel_square_sum = torch.as_tensor(0.0)
      voxel_max, voxel_min = [], []
      voxel_ct = 0
  
      for data in self.data_loader:
          if self.image_key and self.label_key:
              image, label = data[self.image_key], data[self.label_key]
          else:
              image, label = data
          image, *_ = convert_data_type(
              data=image, output_type=torch.Tensor
          )
          label, *_ = convert_data_type(
              data=label, output_type=torch.Tensor
          )
  
          image_foreground = image[
              torch.where(label > foreground_threshold)
          ]
  
          voxel_max.append(image_foreground.max().item())
          voxel_min.append(image_foreground.min().item())
          voxel_ct += len(image_foreground)
          voxel_sum += image_foreground.sum()
          voxel_square_sum += torch.square(image_foreground).sum()
  
      self.data_max, self.data_min = max(voxel_max), min(voxel_min)
      self.data_mean = (voxel_sum / voxel_ct).item()
      self.data_std = (
          torch.sqrt(voxel_square_sum / voxel_ct - self.data_mean**2)
      ).item()
  
file_path: MONAI/monai/data/dataset_summary.py
imports: from __future__ import annotations
  import warnings
  from itertools import chain
  import numpy
  import torch
  from monai.config import KeysCollection
  from monai.data.dataloader import DataLoader
  from monai.data.dataset import Dataset
  from monai.data.meta_tensor import MetaTensor
  from monai.data.utils import affine_to_spacing
  from monai.transforms import concatenate
  from monai.utils import PostFix, convert_data_type, convert_to_tensor
label_desc: Use image node_id 4 for calling the DatasetSummary obj's underlying member method code with example usage: obj.calculate_statistics(foreground_threshold) without return types