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


Python png.Writer方法代碼示例

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


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

示例1: writepng

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def writepng(self):
        # pack
        s=[]
        i = 0
        b = 0
        for c in self.m:
            i = i + 1
            b = b | (int(c)<<(9-((i-1)%7)))
            if i % 7 == 0: 
                b = b | (b>>1)
                s.append(tobin(~b,10))
                s.append(tobin(~0,10))
                b = 0
        s = map(lambda x: map(int, x), s)
        
        f = open('u%04x.png'%self.charcode, 'wb')
        w = png.Writer(len(s[0]), len(s), greyscale=True, bitdepth=1)
        w.write(f, s)
        f.close() 
開發者ID:svofski,項目名稱:glasstty,代碼行數:21,代碼來源:vtparse.py

示例2: convertToScreen

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def convertToScreen(data, out, org=0):
    pixel = []
    for y in range(192):
        pixrow = []
        pixel.append(pixrow)
        for col in range(32):
            palette = readColor(data, y, col)
            bits = readBits(data, y, col)
            for b in range(8):
                if bits & (0b10000000 >> b):
                    pixrow.append(palette[0])
                else:
                    pixrow.append(palette[1])

    import png
    pngw = png.Writer(256, 192, palette=PALETTE)
    pngw.write(out, pixel) 
開發者ID:shred,項目名稱:tzxtools,代碼行數:19,代碼來源:convert.py

示例3: save16bitPNG

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def save16bitPNG(filename, data):
    """
    It's not easy to save 16-bit images in Python.
    Here is a way to save a 16-bit PNG
    Again, this is thanks to stackoverflow:
    https://stackoverflow.com/questions/25696615/\
    can-i-save-a-numpy-array-as-a-16-bit-image-using-normal-enthought-python
    This requires pyPNG
    """

    import png
    with open(filename, 'wb') as f:
        writer = png.Writer(width=data.shape[1], height=data.shape[0],
                            bitdepth=16, greyscale=True)
        data_list = data.tolist()
        writer.write(f, data_list) 
開發者ID:PyAbel,項目名稱:PyAbel,代碼行數:18,代碼來源:io.py

示例4: save_depth

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def save_depth(path, im):
    """Saves a depth image (16-bit) to a PNG file.
    From the BOP toolkit (https://github.com/thodan/bop_toolkit).

    :param path: Path to the output depth image file.
    :param im: ndarray with the depth image to save.
    """
    if not path.endswith(".png"):
        raise ValueError('Only PNG format is currently supported.')

    im[im > 65535] = 65535
    im_uint16 = np.round(im).astype(np.uint16)

    # PyPNG library can save 16-bit PNG and is faster than imageio.imwrite().
    w_depth = png.Writer(im.shape[1], im.shape[0], greyscale=True, bitdepth=16)
    with open(path, 'wb') as f:
        w_depth.write(f, np.reshape(im_uint16, (-1, im.shape[1]))) 
開發者ID:DLR-RM,項目名稱:BlenderProc,代碼行數:19,代碼來源:BopWriter.py

示例5: write_dataset

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def write_dataset(labels, data, size, rows, cols, output_dir):
    # create output directories
    output_dirs = [
        path.join(output_dir, str(i))
        for i in range(10)
    ]
    for dir in output_dirs:
        if not path.exists(dir):
            os.makedirs(dir)

    # write data
    for (i, label) in enumerate(labels):
        output_filename = path.join(output_dirs[label], str(i) + ".png")
        print("writing " + output_filename)
        with open(output_filename, "wb") as h:
            w = png.Writer(cols, rows, greyscale=True)
            data_i = [
                data[ (i*rows*cols + j*cols) : (i*rows*cols + (j+1)*cols) ]
                for j in range(rows)
            ]
            w.write(h, data_i) 
開發者ID:myleott,項目名稱:mnist_png,代碼行數:23,代碼來源:convert_mnist_to_png.py

示例6: __init__

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def __init__(self, handoff_url, message_queue, disk_size, mem_size):
        self.url = handoff_url
        self.mq = message_queue
        self.viz_interval = 1 #1000 msecs
        self.disk_chunks = disk_size / 4096
        self.mem_chunks = mem_size / 4096
        self.time_start = self.last_update =  time.time()
        self.num_blobs = 0
        self.disk_applied = 0
        self.mem_applied = 0
        self.iter = 0
        self.outfd = open(name='/var/tmp/cloudlet/handoff_from_%s_at_%d.log' % (self.url, self.time_start), mode = 'w')
        self.stats_path = '/var/www/html/heatmap/stats.txt'

        self.disk_path = '/var/www/html/heatmap/disk.png'
        self.disk_width, self.disk_height = self.layout(self.disk_chunks)
        self.disk_img_data = [[0 for _ in range(self.disk_width)] for _ in range(self.disk_height)]
        self.disk_writer = png.Writer(self.disk_width, self.disk_height, greyscale=True)

        self.mem_path = '/var/www/html/heatmap/mem.png'
        self.mem_width, self.mem_height = self.layout(self.mem_chunks)
        self.mem_img_data = [[0 for _ in range(self.mem_width)] for _ in range(self.mem_height)]
        self.mem_writer = png.Writer(self.mem_width, self.mem_height, greyscale=True)
        multiprocessing.Process.__init__(self, target=self.read_queue) 
開發者ID:cmusatyalab,項目名稱:elijah-provisioning,代碼行數:26,代碼來源:stream_server.py

示例7: save_depth

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def save_depth(path, im):
  """Saves a depth image (16-bit) to a PNG file.

  :param path: Path to the output depth image file.
  :param im: ndarray with the depth image to save.
  """
  if path.split('.')[-1].lower() != 'png':
    raise ValueError('Only PNG format is currently supported.')

  im_uint16 = np.round(im).astype(np.uint16)

  # PyPNG library can save 16-bit PNG and is faster than imageio.imwrite().
  w_depth = png.Writer(im.shape[1], im.shape[0], greyscale=True, bitdepth=16)
  with open(path, 'wb') as f:
    w_depth.write(f, np.reshape(im_uint16, (-1, im.shape[1]))) 
開發者ID:thodan,項目名稱:bop_toolkit,代碼行數:17,代碼來源:inout.py

示例8: save

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def save(image, filename):
        """save a PNG file"""
        with open(filename, "wb") as file:
            writer = png.Writer(width=image.width, height=image.height,
                    alpha=True)
            writer.write_array(file, list(_rgba_for_pixels(image.pixels))) 
開發者ID:lovexiaov,項目名稱:python-in-practice,代碼行數:8,代碼來源:Png.py

示例9: save_image

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def save_image(image, path):
    """Save an image as a png file"""
    image = dcgan_utils.inverse_transform(image)
    png_writer = png.Writer(64, 64)
    with open(path, 'wb') as outfile:
        png_writer.write(outfile, 255*image.reshape([64,-1])) 
開發者ID:AshishBora,項目名稱:csgm,代碼行數:8,代碼來源:celebA_utils.py

示例10: save_image

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def save_image(image, path):
    """Save an image as a png file"""
    png_writer = png.Writer(28, 28, greyscale=True)
    with open(path, 'wb') as outfile:
        png_writer.write(outfile, 255*image) 
開發者ID:AshishBora,項目名稱:csgm,代碼行數:7,代碼來源:mnist_utils.py

示例11: save_im

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def save_im(path, im):
    scipy.misc.imsave(path, im)

    # Using PyPNG (for RGB)
    # w_rgb = png.Writer(im.shape[1], im.shape[0], greyscale=False, bitdepth=8)
    # with open(path, 'wb') as f:
    #     w_rgb.write(f, np.reshape(im, (-1, 3 * im.shape[1]))) 
開發者ID:meiqua,項目名稱:patch_linemod,代碼行數:9,代碼來源:inout.py

示例12: save_depth

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def save_depth(path, im):
    # PyPNG library is used since it allows to save 16-bit PNG
    w_depth = png.Writer(im.shape[1], im.shape[0], greyscale=True, bitdepth=16)
    im_uint16 = np.round(im).astype(np.uint16)
    with open(path, 'wb') as f:
        w_depth.write(f, np.reshape(im_uint16, (-1, im.shape[1]))) 
開發者ID:meiqua,項目名稱:patch_linemod,代碼行數:8,代碼來源:inout.py

示例13: _save_3d_numpy_array_as_png

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def _save_3d_numpy_array_as_png(self, img, path):
        """saves a NxNx3 8 bit numpy array as a png image

        :param img: N.N.3 numpy array
        :param path: path to save image to, e.g. './img/img.png
        :return:
        """
        if len(img.shape) != 3 or img.dtype is not np.dtype('uint8'):
            raise TypeError('image must be NxNx3 array')
        with open(str(path), 'wb') as f:
            writer = png.Writer(img.shape[1], img.shape[0], greyscale=False, bitdepth=8)
            writer.write(f, np.reshape(img, (-1, img.shape[1] * img.shape[2]))) 
開發者ID:danmacnish,項目名稱:cartoonify,代碼行數:14,代碼來源:workflow.py

示例14: write_rgba_png_file

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def write_rgba_png_file(filepath, rows):
    width = len(rows[0]) / 4
    height = len(rows)
    writer = png.Writer(width=width, height=height, alpha=True)
    with open(filepath, 'wb') as file:
        writer.write(file, rows)


#--------------------------------------------------------------------------------------------------
# Utility class to log progress.
#-------------------------------------------------------------------------------------------------- 
開發者ID:appleseedhq,項目名稱:blenderseed,代碼行數:13,代碼來源:runtestsuite.py

示例15: mri_to_png

# 需要導入模塊: import png [as 別名]
# 或者: from png import Writer [as 別名]
def mri_to_png(mri_file, png_file, do_auto_contrast=False):
    """ Function to convert from a DICOM image to png

        @param mri_file: An opened file like object to read te dicom data
        @param png_file: An opened file like object to write the png data
    """

    image_2d = extract_grayscale_image(mri_file)

    if do_auto_contrast:
        image_2d = auto_contrast(image_2d)

    # Writing the PNG file
    w = png.Writer(image_2d.width, image_2d.height, greyscale=True)
    w.write(png_file, image_2d.image) 
開發者ID:danishm,項目名稱:mritopng,代碼行數:17,代碼來源:__init__.py


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