Python imageio 模块,mimwrite() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用imageio.mimwrite()

项目:pcbot    作者:pckv    | 项目源码 | 文件源码
def modify(self, function, *args, **kwargs):
        """ Modify the image object using the given Image function.
        This function supplies sequence support. """
        if not gif_support or not self.gif:
            self.object = function(self.object, *args, **kwargs)
        else:
            frames = []
            duration = self.object.info.get("duration") / 1000
            for frame in ImageSequence.Iterator(self.object):
                frame_bytes = utils.convert_image_object(function(frame, *args, **kwargs))
                frames.append(imageio.imread(frame_bytes, format="PNG"))

            # Save the image as bytes and recreate the image object
            image_bytes = imageio.mimwrite(imageio.RETURN_BYTES, frames, format=self.format, duration=duration)
            self.object = Image.open(BytesIO(image_bytes))
            self.gif_bytes = image_bytes
项目:ctrl-f-vision    作者:osmanio2    | 项目源码 | 文件源码
def gifwrite(name, img_buf):
    print("Thread spawned"*7)
    kargs = { 'quantizer':'nq' }
    imageio.mimwrite(name + ".gif", img_buf, 'GIF-FI', **kargs)
    # write additional data inside json
    fp = open("../records/%s.json" % name, 'w')
    fp.write("{\n")
    fp.write("    \"id\": 123,");
    fp.write("    \"gifUrl\": \"%s.gif\", \n" % name);
    fp.write("    \"timestamp\": \"%s\", \n" %
                             str(datetime.datetime.now()))
    fp.write("    \"tags\": [\"andrej\",\"hack\"]");
    fp.write("}\n")
    fp.close()

# main loop
项目:DeepVideo    作者:AniketBajpai    | 项目源码 | 文件源码
def visualize(name):
    for counter, file in enumerate(sorted(glob.glob(os.path.join(args.train_dir, '{}_*.hy'.format(name))), key=os.path.getmtime)[-args.n:]):
        print (file)
        f = h5py.File(file, 'r')
        # I = np.zeros((args.h, args.num_frames * args.w, args.c))
        generated_frames = f[f.keys()[0]]
        _, _, h, w, c = generated_frames.shape
        h_low = (h - args.h) / 2
        h_high = (h + args.h) / 2
        w_low = (w - args.w) / 2
        w_high = (w + args.w) / 2
        # Take only first set of frames from batch
        II = []
        if args.c == 1:
            for j in range(args.num_frames):
                I = np.reshape(generated_frames[0, j, h_low:h_high, w_low:w_high, 0], (args.h, args.w))
                if (I < 1.0).all() and (I > -1.0).all():
                    print ('Image in [-1, 1]')
                    I = ((I + 1.0) / 2 * 255).astype(np.int32)

                II.append(I)

        else:
            for j in range(args.num_frames):
                I = np.reshape(generated_frames[0, j, h_low:h_high, w_low:w_high, 0:args.c], (args.h, args.w, args.c))
                II.append(I)

        # II = np.stack(II)
        output_img_path = './outputs/{}_{}_{}.png'.format(args.output_prefix, name, str(counter))
        print ('Writing image:', output_img_path)
        print (len(II), II[0].shape)
        imageio.mimwrite(output_img_path, II)
项目:CAAPR    作者:Stargrazer82301    | 项目源码 | 文件源码
def save(self, path):

        """
        This function ...
        :param path:
        :param fps:
        :return:
        """

        # Create and write the GIF file
        imageio.mimwrite(path, self.frames, fps=self.fps)

    # -----------------------------------------------------------------
项目:CAAPR    作者:Stargrazer82301    | 项目源码 | 文件源码
def save(self, path):

        """
        This function ...
        :param path:
        :param fps:
        :return:
        """

        # Create and write the GIF file
        imageio.mimwrite(path, self.frames, fps=self.fps)

    # -----------------------------------------------------------------
项目:TensorArtist    作者:vacancy    | 项目源码 | 文件源码
def _save_gif(traj, filename):
    traj = np.asarray(traj, dtype='uint8')
    return imageio.mimwrite(filename, traj,  duration=0.1)