當前位置: 首頁>>代碼示例>>Python>>正文


Python cm.colors方法代碼示例

本文整理匯總了Python中matplotlib.cm.colors方法的典型用法代碼示例。如果您正苦於以下問題:Python cm.colors方法的具體用法?Python cm.colors怎麽用?Python cm.colors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在matplotlib.cm的用法示例。


在下文中一共展示了cm.colors方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: colorize

# 需要導入模塊: from matplotlib import cm [as 別名]
# 或者: from matplotlib.cm import colors [as 別名]
def colorize(value, vmin=None, vmax=None, cmap=None):
    # normalize
    vmin = tf.reduce_min(value) if vmin is None else vmin
    vmax = tf.reduce_max(value) if vmax is None else vmax
    value = (value - vmin) / (vmax - vmin)  # vmin..vmax

    # squeeze last dim if it exists
    value = tf.squeeze(value)

    # quantize
    indices = tf.to_int32(tf.round(value * 255))

    # gather
    cm = matplotlib.cm.get_cmap(cmap if cmap is not None else 'gray')
    colors = tf.constant(cm.colors, dtype=tf.float32)
    value = tf.gather(colors, indices)

    return value 
開發者ID:FangGet,項目名稱:tf-monodepth2,代碼行數:20,代碼來源:tools.py

示例2: colorize

# 需要導入模塊: from matplotlib import cm [as 別名]
# 或者: from matplotlib.cm import colors [as 別名]
def colorize(img, vmin=None, vmax=None, cmap='plasma'):
    # normalize
    vmin = tf.reduce_min(img) if vmin is None else vmin
    vmax = tf.contrib.distributions.percentile(img, 99.) if vmax is None else vmax
    img = (img - vmin) / (vmax - vmin)

    img = tf.squeeze(img, axis=[-1])

    # quantize
    indices = tf.clip_by_value(tf.to_int32(tf.round(img * 255)), 0, 255)

    # gather
    cm = matplotlib.cm.get_cmap(cmap if cmap is not None else 'gray')
    colors = tf.constant(cm.colors, dtype=tf.float32)
    img = tf.gather(colors, indices)

    return img 
開發者ID:flkraus,項目名稱:bayesian-yolov3,代碼行數:19,代碼來源:vis_uncertainty.py

示例3: tf_colorize

# 需要導入模塊: from matplotlib import cm [as 別名]
# 或者: from matplotlib.cm import colors [as 別名]
def tf_colorize(value, factor=1, vmin=None, vmax=None, cmap=None):
    """
    A utility function for TensorFlow that maps a grayscale image to a matplotlib
    colormap for use with TensorBoard image summaries.

    By default it will normalize the input value to the range 0..1 before mapping
    to a grayscale colormap.

    Arguments:
      - value: 2D Tensor of shape [height, width] or 3D Tensor of shape
        [height, width, 1].
      - factor: resize factor, scalar
      - vmin: the minimum value of the range used for normalization.
        (Default: value minimum)
      - vmax: the maximum value of the range used for normalization.
        (Default: value maximum)
      - cmap: a valid cmap named for use with matplotlib's `get_cmap`.
        (Default: 'gray')

    Example usage:

    ```
    output = tf.random_uniform(shape=[256, 256, 1])
    output_color = colorize(output, vmin=0.0, vmax=1.0, cmap='viridis')
    tf.summary.image('output', output_color)
    ```

    Returns a 3D tensor of shape [height, width, 3].
    """

    # normalize
    vmin = tf.reduce_min(value) if vmin is None else vmin
    vmax = tf.reduce_max(value) if vmax is None else vmax
    value = (value - vmin) / (vmax - vmin)  # vmin..vmax

    # squeeze last dim if it exists
    value = tf.squeeze(value)

    # quantize
    indices = tf.to_int32(tf.round(value * 255))

    # gather
    cm = matplotlib.cm.get_cmap(cmap if cmap is not None else 'gray')
    colors = tf.constant(cm.colors, dtype=tf.float32)
    value = tf.gather(colors, indices)

    return value 
開發者ID:pyun-ram,項目名稱:FL3D,代碼行數:49,代碼來源:colorize.py

示例4: colorize_image

# 需要導入模塊: from matplotlib import cm [as 別名]
# 或者: from matplotlib.cm import colors [as 別名]
def colorize_image(value, vmin=None, vmax=None, cmap='viridis'):
  """
  A utility function for TensorFlow that maps a grayscale image to a matplotlib
  colormap for use with TensorBoard image summaries.

  By default it will normalize the input value to the range 0..1 before mapping
  to a grayscale colormap.

  Arguments:
    - value: 2D Tensor of shape [height, width] or 3D Tensor of shape
      [height, width, 1].
    - vmin: the minimum value of the range used for normalization.
      (Default: value minimum)
    - vmax: the maximum value of the range used for normalization.
      (Default: value maximum)
    - cmap: a valid cmap named for use with matplotlib's `get_cmap`.
      (Default: 'gray')

  Example usage:

  ```
  output = tf.random_uniform(shape=[256, 256, 1])
  output_color = colorize(output, vmin=0.0, vmax=1.0, cmap='viridis')
  tf.summary.image('output', output_color)
  ```

  Returns a 3D tensor of shape [height, width, 3].
  """

  # normalize
  vmin = tf.reduce_min(value) if vmin is None else vmin
  vmax = tf.reduce_max(value) if vmax is None else vmax
  value = (value - vmin) / (vmax - vmin) # vmin..vmax

  # squeeze last dim if it exists
  value = tf.squeeze(value)

  # quantize
  indices = tf.to_int32(tf.round(value * 255))

  # gather
  import matplotlib.cm
  cm = matplotlib.cm.get_cmap(cmap if cmap is not None else 'gray')
  colors = tf.constant(cm.colors, dtype=tf.float32)
  value = tf.gather(colors, indices)

  return value 
開發者ID:afourast,項目名稱:deep_lip_reading,代碼行數:49,代碼來源:tb_util.py


注:本文中的matplotlib.cm.colors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。