code: def calc_max_2D_diameter_ellipse(
      input_data,
      pixdim=None,
      affine=None,
      mask_value=0,
      axis=2,
      calc_multiple=False,
  ):
      input_data, input_affine = read_image_files(
          input_data, return_affine=True
      )
  
      pixdim = _get_pixdim(pixdim, affine, input_affine)
  
      input_data = input_data[..., -1]
  
      connected_components = label(input_data, connectivity=2)
      component_labels = np.unique(connected_components)
  
      max_2ds = []
  
      major_diameter = None
      for label_idx in component_labels:
          component = connected_components.astype(int)
          component[connected_components != label_idx] = 0
  
          major_diameter = None
  
          for z_slice in range(component.shape[2]):
              label_slice = component[..., z_slice]
  
              if np.sum(label_slice) == 0:
                  continue
  
              label_properties = regionprops(label_slice)
              current_major = label_properties[0].major_axis_length
              current_orientation = label_properties[0].orientation
  
              x_dim = abs(np.cos(current_orientation) * current_major)
              y_dim = abs(np.sin(current_orientation) * current_major)
              current_major = (
                  (x_dim * pixdim[0]) ** 2 + (y_dim * pixdim[1]) ** 2
              ) ** 0.5
  
              if major_diameter is None:
                  major_diameter = current_major
              elif current_major > major_diameter:
                  major_diameter = current_major
  
          if major_diameter is not None:
              max_2ds += [major_diameter]
  
      if calc_multiple:
          return max_2ds
      else:
          return max(max_2ds)
  
file_path: DeepNeuro/deepneuro/outputs/measure.py
imports: import numpy
  from skimage.morphology import label
  from skimage.measure import regionprops, mesh_surface_area, marching_cubes
  from scipy import signal
  from deepneuro.utilities.conversion import read_image_files
label_desc: Use image node_id 2 for calling a global function with example usage: calc_max_2D_diameter_ellipse(input_data, pixdim, affine, mask_value, axis, calc_multiple) and returns: max_2ds, max