docstr: Computing the measurements for a single map of objects
docstr_tok: ["Computing","the","measurements","for","a","single","map","of","objects"]
code: def analyze_objects(self, objects, desired_properties):
      """Computing the measurements for a single map of objects"""
      labels = objects.segmented
      nobjects = len(objects.indices)
      if len(objects.shape) == 2:
          props = skimage.measure.regionprops_table(
              labels, properties=desired_properties
          )
  
          formfactor = (
              4.0 * numpy.pi * props["area"] / props["perimeter"] ** 2
          )
          denom = [max(x, 1) for x in 4.0 * numpy.pi * props["area"]]
          compactness = props["perimeter"] ** 2 / denom
  
          max_radius = numpy.zeros(nobjects)
          median_radius = numpy.zeros(nobjects)
          mean_radius = numpy.zeros(nobjects)
          min_feret_diameter = numpy.zeros(nobjects)
          max_feret_diameter = numpy.zeros(nobjects)
          zernike_numbers = self.get_zernike_numbers()
  
          zf = {}
          for n, m in zernike_numbers:
              zf[(n, m)] = numpy.zeros(nobjects)
  
          for index, mini_image in enumerate(props["image"]):
              # Pad image to assist distance tranform
              mini_image = numpy.pad(mini_image, 1)
              distances = scipy.ndimage.distance_transform_edt(
                  mini_image
              )
              max_radius[
                  index
              ] = centrosome.cpmorphology.fixup_scipy_ndimage_result(
                  scipy.ndimage.maximum(distances, mini_image)
              )
              mean_radius[
                  index
              ] = centrosome.cpmorphology.fixup_scipy_ndimage_result(
                  scipy.ndimage.mean(distances, mini_image)
              )
              median_radius[
                  index
              ] = centrosome.cpmorphology.median_of_labels(
                  distances, mini_image.astype("int"), [1]
              )
          #
          # Zernike features
          #
          if self.calculate_zernikes.value:
              zf_l = centrosome.zernike.zernike(
                  zernike_numbers, labels, objects.indices
              )
              for (n, m), z in zip(zernike_numbers, zf_l.transpose()):
                  zf[(n, m)] = z
  
          if nobjects > 0:
              (
                  chulls,
                  chull_counts,
              ) = centrosome.cpmorphology.convex_hull_ijv(
                  objects.ijv, objects.indices
              )
              #
              # Feret diameter
              #
              (
                  min_feret_diameter,
                  max_feret_diameter,
              ) = centrosome.cpmorphology.feret_diameter(
                  chulls, chull_counts, objects.indices
              )
  
          features_to_record = {
              F_AREA: props["area"],
              F_PERIMETER: props["perimeter"],
              F_MAJOR_AXIS_LENGTH: props["major_axis_length"],
              F_MINOR_AXIS_LENGTH: props["minor_axis_length"],
              F_ECCENTRICITY: props["eccentricity"],
              F_ORIENTATION: props["orientation"] * (180 / numpy.pi),
              F_CENTER_X: props["centroid-1"],
              F_CENTER_Y: props["centroid-0"],
              F_BBOX_AREA: props["bbox_area"],
              F_MIN_X: props["bbox-1"],
              F_MAX_X: props["bbox-3"],
              F_MIN_Y: props["bbox-0"],
              F_MAX_Y: props["bbox-2"],
              F_FORM_FACTOR: formfactor,
              F_EXTENT: props["extent"],
              F_SOLIDITY: props["solidity"],
              F_COMPACTNESS: compactness,
              F_EULER_NUMBER: props["euler_number"],
              F_MAXIMUM_RADIUS: max_radius,
              F_MEAN_RADIUS: mean_radius,
              F_MEDIAN_RADIUS: median_radius,
              F_CONVEX_AREA: props["convex_area"],
              F_MIN_FERET_DIAMETER: min_feret_diameter,
              F_MAX_FERET_DIAMETER: max_feret_diameter,
              F_EQUIVALENT_DIAMETER: props["equivalent_diameter"],
          }
          if self.calculate_advanced.value:
              features_to_record.update(
                  {
                      F_SPATIAL_MOMENT_0_0: props["moments-0-0"],
                      F_SPATIAL_MOMENT_0_1: props["moments-0-1"],
                      F_SPATIAL_MOMENT_0_2: props["moments-0-2"],
                      F_SPATIAL_MOMENT_0_3: props["moments-0-3"],
                      F_SPATIAL_MOMENT_1_0: props["moments-1-0"],
                      F_SPATIAL_MOMENT_1_1: props["moments-1-1"],
                      F_SPATIAL_MOMENT_1_2: props["moments-1-2"],
                      F_SPATIAL_MOMENT_1_3: props["moments-1-3"],
                      F_SPATIAL_MOMENT_2_0: props["moments-2-0"],
                      F_SPATIAL_MOMENT_2_1: props["moments-2-1"],
                      F_SPATIAL_MOMENT_2_2: props["moments-2-2"],
                      F_SPATIAL_MOMENT_2_3: props["moments-2-3"],
                      F_CENTRAL_MOMENT_0_0: props[
                          "moments_central-0-0"
                      ],
                      F_CENTRAL_MOMENT_0_1: props[
                          "moments_central-0-1"
                      ],
                      F_CENTRAL_MOMENT_0_2: props[
                          "moments_central-0-2"
                      ],
                      F_CENTRAL_MOMENT_0_3: props[
                          "moments_central-0-3"
                      ],
                      F_CENTRAL_MOMENT_1_0: props[
                          "moments_central-1-0"
                      ],
                      F_CENTRAL_MOMENT_1_1: props[
                          "moments_central-1-1"
                      ],
                      F_CENTRAL_MOMENT_1_2: props[
                          "moments_central-1-2"
                      ],
                      F_CENTRAL_MOMENT_1_3: props[
                          "moments_central-1-3"
                      ],
                      F_CENTRAL_MOMENT_2_0: props[
                          "moments_central-2-0"
                      ],
                      F_CENTRAL_MOMENT_2_1: props[
                          "moments_central-2-1"
                      ],
                      F_CENTRAL_MOMENT_2_2: props[
                          "moments_central-2-2"
                      ],
                      F_CENTRAL_MOMENT_2_3: props[
                          "moments_central-2-3"
                      ],
                      F_NORMALIZED_MOMENT_0_0: props[
                          "moments_normalized-0-0"
                      ],
                      F_NORMALIZED_MOMENT_0_1: props[
                          "moments_normalized-0-1"
                      ],
                      F_NORMALIZED_MOMENT_0_2: props[
                          "moments_normalized-0-2"
                      ],
                      F_NORMALIZED_MOMENT_0_3: props[
                          "moments_normalized-0-3"
                      ],
                      F_NORMALIZED_MOMENT_1_0: props[
                          "moments_normalized-1-0"
                      ],
                      F_NORMALIZED_MOMENT_1_1: props[
                          "moments_normalized-1-1"
                      ],
                      F_NORMALIZED_MOMENT_1_2: props[
                          "moments_normalized-1-2"
                      ],
                      F_NORMALIZED_MOMENT_1_3: props[
                          "moments_normalized-1-3"
                      ],
                      F_NORMALIZED_MOMENT_2_0: props[
                          "moments_normalized-2-0"
                      ],
                      F_NORMALIZED_MOMENT_2_1: props[
                          "moments_normalized-2-1"
                      ],
                      F_NORMALIZED_MOMENT_2_2: props[
                          "moments_normalized-2-2"
                      ],
                      F_NORMALIZED_MOMENT_2_3: props[
                          "moments_normalized-2-3"
                      ],
                      F_NORMALIZED_MOMENT_3_0: props[
                          "moments_normalized-3-0"
                      ],
                      F_NORMALIZED_MOMENT_3_1: props[
                          "moments_normalized-3-1"
                      ],
                      F_NORMALIZED_MOMENT_3_2: props[
                          "moments_normalized-3-2"
                      ],
                      F_NORMALIZED_MOMENT_3_3: props[
                          "moments_normalized-3-3"
                      ],
                      F_HU_MOMENT_0: props["moments_hu-0"],
                      F_HU_MOMENT_1: props["moments_hu-1"],
                      F_HU_MOMENT_2: props["moments_hu-2"],
                      F_HU_MOMENT_3: props["moments_hu-3"],
                      F_HU_MOMENT_4: props["moments_hu-4"],
                      F_HU_MOMENT_5: props["moments_hu-5"],
                      F_HU_MOMENT_6: props["moments_hu-6"],
                      F_INERTIA_TENSOR_0_0: props["inertia_tensor-0-0"],
                      F_INERTIA_TENSOR_0_1: props["inertia_tensor-0-1"],
                      F_INERTIA_TENSOR_1_0: props["inertia_tensor-1-0"],
                      F_INERTIA_TENSOR_1_1: props["inertia_tensor-1-1"],
                      F_INERTIA_TENSOR_EIGENVALUES_0: props[
                          "inertia_tensor_eigvals-0"
                      ],
                      F_INERTIA_TENSOR_EIGENVALUES_1: props[
                          "inertia_tensor_eigvals-1"
                      ],
                  }
              )
  
          if self.calculate_zernikes.value:
              features_to_record.update(
                  {
                      self.get_zernike_name((n, m)): zf[(n, m)]
                      for n, m in zernike_numbers
                  }
              )
  
      else:
          props = skimage.measure.regionprops_table(
              labels, properties=desired_properties
          )
  
          # SurfaceArea
          surface_areas = numpy.zeros(len(props["label"]))
          for index, label in enumerate(props["label"]):
              # this seems less elegant than you might wish, given that regionprops returns a slice,
              # but we need to expand the slice out by one voxel in each direction, or surface area freaks out
              volume = labels[
                  max(props["bbox-0"][index] - 1, 0) : min(
                      props["bbox-3"][index] + 1, labels.shape[0]
                  ),
                  max(props["bbox-1"][index] - 1, 0) : min(
                      props["bbox-4"][index] + 1, labels.shape[1]
                  ),
                  max(props["bbox-2"][index] - 1, 0) : min(
                      props["bbox-5"][index] + 1, labels.shape[2]
                  ),
              ]
              volume = volume == label
              (
                  verts,
                  faces,
                  _normals,
                  _values,
              ) = skimage.measure.marching_cubes(
                  volume,
                  method="lewiner",
                  spacing=objects.parent_image.spacing
                  if objects.has_parent_image
                  else (1.0,) * labels.ndim,
                  level=0,
              )
              surface_areas[index] = skimage.measure.mesh_surface_area(
                  verts, faces
              )
  
          features_to_record = {
              F_VOLUME: props["area"],
              F_SURFACE_AREA: surface_areas,
              F_MAJOR_AXIS_LENGTH: props["major_axis_length"],
              F_MINOR_AXIS_LENGTH: props["minor_axis_length"],
              F_CENTER_X: props["centroid-2"],
              F_CENTER_Y: props["centroid-1"],
              F_CENTER_Z: props["centroid-0"],
              F_BBOX_VOLUME: props["bbox_area"],
              F_MIN_X: props["bbox-2"],
              F_MAX_X: props["bbox-5"],
              F_MIN_Y: props["bbox-1"],
              F_MAX_Y: props["bbox-4"],
              F_MIN_Z: props["bbox-0"],
              F_MAX_Z: props["bbox-3"],
              F_EXTENT: props["extent"],
              F_EULER_NUMBER: props["euler_number"],
              F_EQUIVALENT_DIAMETER: props["equivalent_diameter"],
          }
          if self.calculate_advanced.value:
              features_to_record[F_SOLIDITY] = props["solidity"]
      return features_to_record
  
imports: import centrosome.cpmorphology
  import centrosome.zernike
  import numpy
  import scipy.ndimage
  import skimage.measure
  from cellprofiler_core.constants.measurement import COLTYPE_FLOAT
  from cellprofiler_core.module import Module
  from cellprofiler_core.object import Objects
  from cellprofiler_core.setting import Divider, Binary, ValidationError
  from cellprofiler_core.setting.subscriber import LabelListSubscriber
  import cellprofiler.gui.help.content
  import cellprofiler.icons
label_desc: Use image node_id 12 for calling the MeasureObjectSizeShape obj's underlying member method code with example usage: obj.analyze_objects(objects, desired_properties) and returns: features_to_record