当前位置: 首页>>代码示例>>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;未经允许,请勿转载。