docstr: Calculate a correlation measure from the Harlick feature set
docstr_tok: ["Calculate","a","correlation","measure","from","the","Harlick","feature","set"]
code: def calculate_correlation(self, image_group, workspace):
      """Calculate a correlation measure from the Harlick feature set"""
      result = []
      for image_name in self.images_to_process(image_group, workspace):
          image = workspace.image_set.get_image(
              image_name, must_be_grayscale=True
          )
          pixel_data = image.pixel_data
  
          # Compute Haralick's correlation texture for the given scales
          image_labels = numpy.ones(pixel_data.shape, int)
          if image.has_mask:
              image_labels[~image.mask] = 0
          for scale_group in image_group.scale_groups:
              scale = scale_group.scale.value
  
              value = centrosome.haralick.Haralick(
                  pixel_data, image_labels, 0, scale
              ).H3()
  
              if len(value) != 1 or not numpy.isfinite(value[0]):
                  value = 0.0
              else:
                  value = float(value)
  
              workspace.add_measurement(
                  "Image",
                  "{}_{}_{}_{:d}".format(
                      C_IMAGE_QUALITY, F_CORRELATION, image_name, scale
                  ),
                  float(value),
              )
              result += [
                  [
                      "{} {} @{:d}".format(
                          image_name, F_CORRELATION, scale
                      ),
                      "{:.2f}".format(float(value)),
                  ]
              ]
      return result
  
imports: import itertools
  import logging
  import cellprofiler_core.utilities.image
  import centrosome.cpmorphology
  import centrosome.haralick
  import centrosome.radial_power_spectrum
  import centrosome.threshold
  import centrosome.threshold
  import numpy
  import scipy.linalg.basic
  import scipy.ndimage
  from cellprofiler_core.constants.image import C_SCALING
  from cellprofiler_core.constants.measurement import COLTYPE_FLOAT, EXPERIMENT, MCA_AVAILABLE_POST_RUN
  from cellprofiler_core.constants.module._identify import O_WEIGHTED_VARIANCE, O_ENTROPY, O_FOREGROUND, O_BACKGROUND
  from cellprofiler_core.module import Module
  from cellprofiler_core.preferences import get_headless
  from cellprofiler_core.setting import Divider, HiddenCount, SettingsGroup, Binary, ValidationError
  from cellprofiler_core.setting.choice import Choice
  from cellprofiler_core.setting.do_something import DoSomething, RemoveSettingButton
  from cellprofiler_core.setting.subscriber import ImageListSubscriber
  from cellprofiler_core.setting.text import ImageName, Integer, Float
  from cellprofiler.modules.threshold import O_THREE_CLASS, O_TWO_CLASS
label_desc: Use image node_id 29 for calling the MeasureImageQuality obj's underlying member method code with example usage: obj.calculate_correlation(image_group, workspace) and returns: result