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


Python image_ops.encode_png方法代碼示例

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


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

示例1: _make_sprite_image

# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_png [as 別名]
def _make_sprite_image(thumbnails, thumbnail_dim):
  """Constructs a sprite image from thumbnails and returns the png bytes."""
  if len(thumbnails) < 1:
    raise ValueError('The length of "thumbnails" must be >= 1')

  if isinstance(thumbnails, np.ndarray) and thumbnails.ndim != 4:
    raise ValueError('"thumbnails" should be of rank 4, '
                     'but is of rank %d' % thumbnails.ndim)
  if isinstance(thumbnails, list):
    if not isinstance(thumbnails[0], np.ndarray) or thumbnails[0].ndim != 3:
      raise ValueError('Each element of "thumbnails" must be a 3D `ndarray`')
    thumbnails = np.array(thumbnails)

  with ops.Graph().as_default():
    s = session.Session()
    resized_images = image_ops.resize_images(thumbnails, thumbnail_dim).eval(
        session=s)
    images_per_row = int(math.ceil(math.sqrt(len(thumbnails))))
    thumb_height = thumbnail_dim[0]
    thumb_width = thumbnail_dim[1]
    master_height = images_per_row * thumb_height
    master_width = images_per_row * thumb_width
    num_channels = thumbnails.shape[3]
    master = np.zeros([master_height, master_width, num_channels])
    for idx, image in enumerate(resized_images):
      left_idx = idx % images_per_row
      top_idx = int(math.floor(idx / images_per_row))
      left_start = left_idx * thumb_width
      left_end = left_start + thumb_width
      top_start = top_idx * thumb_height
      top_end = top_start + thumb_height
      master[top_start:top_end, left_start:left_end, :] = image

    return image_ops.encode_png(master).eval(session=s) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:36,代碼來源:projector_plugin.py

示例2: _encoder

# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_png [as 別名]
def _encoder(image, image_format):
  assert image_format in ['jpeg', 'png']
  if image_format == 'jpeg':
    tf_image = constant_op.constant(image, dtype=dtypes.uint8)
    return image_ops.encode_jpeg(tf_image)
  if image_format == 'png':
    tf_image = constant_op.constant(image, dtype=dtypes.uint8)
    return image_ops.encode_png(tf_image) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:10,代碼來源:test_utils.py

示例3: _Encoder

# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_png [as 別名]
def _Encoder(self, image, image_format):
    assert image_format in ['jpeg', 'JPEG', 'png', 'PNG', 'raw', 'RAW']
    if image_format in ['jpeg', 'JPEG']:
      tf_image = constant_op.constant(image, dtype=dtypes.uint8)
      return image_ops.encode_jpeg(tf_image)
    if image_format in ['png', 'PNG']:
      tf_image = constant_op.constant(image, dtype=dtypes.uint8)
      return image_ops.encode_png(tf_image)
    if image_format in ['raw', 'RAW']:
      return constant_op.constant(image.tostring(), dtype=dtypes.string) 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:12,代碼來源:tfexample_decoder_test.py

示例4: _Encoder

# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_png [as 別名]
def _Encoder(self, image, image_format):
    assert image_format in ['jpeg', 'JPEG', 'png', 'PNG', 'raw', 'RAW']
    if image_format in ['jpeg', 'JPEG']:
      tf_image = tf.constant(image, dtype=tf.uint8)
      return image_ops.encode_jpeg(tf_image)
    if image_format in ['png', 'PNG']:
      tf_image = tf.constant(image, dtype=tf.uint8)
      return image_ops.encode_png(tf_image)
    if image_format in ['raw', 'RAW']:
      # If machine is big endian, change the byte ordering in case of dtype
      # float32 so that it should be interpreted correctly.
      if image.dtype == np.float32 and sys.byteorder == 'big':
        image = image.astype('<f4')
      return tf.constant(image.tostring(), dtype=tf.string) 
開發者ID:google-research,項目名稱:tf-slim,代碼行數:16,代碼來源:tfexample_decoder_test.py

示例5: testExisting

# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_png [as 別名]
def testExisting(self):
    # Read some real PNGs, converting to different channel numbers
    prefix = 'tensorflow/core/lib/png/testdata/'
    inputs = (1, 'lena_gray.png'), (4, 'lena_rgba.png')
    for channels_in, filename in inputs:
      for channels in 0, 1, 3, 4:
        with self.test_session(use_gpu=True) as sess:
          png0 = io_ops.read_file(prefix + filename)
          image0 = image_ops.decode_png(png0, channels=channels)
          png0, image0 = sess.run([png0, image0])
          self.assertEqual(image0.shape, (26, 51, channels or channels_in))
          if channels == channels_in:
            image1 = image_ops.decode_png(image_ops.encode_png(image0))
            self.assertAllEqual(image0, image1.eval()) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:16,代碼來源:image_ops_test.py

示例6: testSynthetic

# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_png [as 別名]
def testSynthetic(self):
    with self.test_session(use_gpu=True) as sess:
      # Encode it, then decode it
      image0 = constant_op.constant(_SimpleColorRamp())
      png0 = image_ops.encode_png(image0, compression=7)
      image1 = image_ops.decode_png(png0)
      png0, image0, image1 = sess.run([png0, image0, image1])

      # PNG is lossless
      self.assertAllEqual(image0, image1)

      # Smooth ramps compress well, but not too well
      self.assertGreaterEqual(len(png0), 400)
      self.assertLessEqual(len(png0), 750) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:16,代碼來源:image_ops_test.py

示例7: testSyntheticUint16

# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_png [as 別名]
def testSyntheticUint16(self):
    with self.test_session(use_gpu=True) as sess:
      # Encode it, then decode it
      image0 = constant_op.constant(_SimpleColorRamp(), dtype=dtypes.uint16)
      png0 = image_ops.encode_png(image0, compression=7)
      image1 = image_ops.decode_png(png0, dtype=dtypes.uint16)
      png0, image0, image1 = sess.run([png0, image0, image1])

      # PNG is lossless
      self.assertAllEqual(image0, image1)

      # Smooth ramps compress well, but not too well
      self.assertGreaterEqual(len(png0), 800)
      self.assertLessEqual(len(png0), 1500) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:16,代碼來源:image_ops_test.py

示例8: testSyntheticTwoChannel

# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_png [as 別名]
def testSyntheticTwoChannel(self):
    with self.test_session(use_gpu=True) as sess:
      # Strip the b channel from an rgb image to get a two-channel image.
      gray_alpha = _SimpleColorRamp()[:, :, 0:2]
      image0 = constant_op.constant(gray_alpha)
      png0 = image_ops.encode_png(image0, compression=7)
      image1 = image_ops.decode_png(png0)
      png0, image0, image1 = sess.run([png0, image0, image1])
      self.assertEqual(2, image0.shape[-1])
      self.assertAllEqual(image0, image1) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:12,代碼來源:image_ops_test.py

示例9: testSyntheticTwoChannelUint16

# 需要導入模塊: from tensorflow.python.ops import image_ops [as 別名]
# 或者: from tensorflow.python.ops.image_ops import encode_png [as 別名]
def testSyntheticTwoChannelUint16(self):
    with self.test_session(use_gpu=True) as sess:
      # Strip the b channel from an rgb image to get a two-channel image.
      gray_alpha = _SimpleColorRamp()[:, :, 0:2]
      image0 = constant_op.constant(gray_alpha, dtype=dtypes.uint16)
      png0 = image_ops.encode_png(image0, compression=7)
      image1 = image_ops.decode_png(png0, dtype=dtypes.uint16)
      png0, image0, image1 = sess.run([png0, image0, image1])
      self.assertEqual(2, image0.shape[-1])
      self.assertAllEqual(image0, image1) 
開發者ID:tobegit3hub,項目名稱:deep_image_model,代碼行數:12,代碼來源:image_ops_test.py


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