code: def _gain_density(mask1, attr, mask2=None):
      # Compute the attr density over mask1. If mask2 is specified, compute density
      # for mask1 \ mask2
      if mask2 is None:
          added_mask = mask1
      else:
          added_mask = _get_diff_mask(mask1, mask2)
      if not np.any(added_mask):
          return -np.inf
      else:
          return attr[added_mask].mean()
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import logging
  from .base import CoreSaliency
  from .integrated_gradients import IntegratedGradients
  import numpy
  from skimage import segmentation
  from skimage.morphology import dilation
  from skimage.morphology import disk
  from skimage.transform import resize
label_desc: Use image node_id 4 for calling a global function with example usage: _gain_density(mask1, attr, mask2) and returns: unknown, attr