code: def rescale_opacity(
      images,
      min_opacity=15 / 255,
      opaque_frac=0.1,
      max_scale=10,
      keep_zeros=False,
  ):
      images_orig = images
      images = images_orig.copy()
      opacities_flat = images[..., 3].reshape(
          images.shape[:-3] + (images.shape[-3] * images.shape[-2],)
      )
      opaque_threshold = np.percentile(
          opacities_flat, (1 - opaque_frac) * 100, axis=-1
      )
      opaque_threshold = np.maximum(
          opaque_threshold, np.amax(opacities_flat, axis=-1) / max_scale
      )[..., None, None]
      opaque_threshold[opaque_threshold == 0] = 1
      images[..., 3] = (
          images[..., 3] * (1 - min_opacity) / opaque_threshold
      )
      images[..., 3] = np.minimum(1, min_opacity + images[..., 3])
      if keep_zeros:
          images[..., 3][images_orig[..., 3] == 0] = 0
      return images
  
file_path: lucid/lucid/scratch/rl_util/nmf.py
imports: import numpy
  from functools import reduce
  import scipy.ndimage
  from lucid.misc.channel_reducer import ChannelReducer
  import lucid.optvis.param
  import lucid.optvis.objectives
  import lucid.optvis.render
  import lucid.optvis.transform
  from .attribution import get_acts, get_attr
label_desc: Use image node_id 2 for calling a global function with example usage: rescale_opacity(images, min_opacity, opaque_frac, max_scale, keep_zeros) and returns: images