How to use the imageio.mimwrite function in imageio

To help you get started, we’ve selected a few imageio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BPHO-Salk / PSSR / utils / utils.py View on Github external
tile_sz=size,
                                                  wsize=wsize)
            pred = (out_img * 255).cpu().numpy().astype(np.uint8)
            preds.append(pred)
            #imsave(folder/f'{t}.tif', pred[0])

            orig = (img[wsize // 2][None] * 255).astype(np.uint8)
            origs.append(orig)
        if len(preds) > 0:
            all_y = img_to_uint8(np.concatenate(preds))
            imageio.mimwrite(
                pred_out, all_y,
                bigtiff=True)  #, fps=30, macro_block_size=None) # for mp4

            all_y = img_to_uint8(np.concatenate(origs))
            imageio.mimwrite(orig_out, all_y,
                             bigtiff=True)  #, fps=30, macro_block_size=None)
github miykael / gif_your_nifti / gif_your_nifti / core.py View on Github external
out_img3, maximum3 = load_and_prepare_image(filename3, size)

    if maximum1 == maximum2 and maximum1 == maximum3:
        maximum = maximum1

    # Create output mosaic
    new_img = create_mosaic_RGB(out_img1, out_img2, out_img3, maximum)

    # Generate output path
    out_filename = '{}_{}_{}_rgb.gif'.format(parse_filename(filename1)[1],
                                             parse_filename(filename2)[1],
                                             parse_filename(filename3)[1])
    out_path = os.path.join(parse_filename(filename1)[0], out_filename)

    # Write gif file
    mimwrite(out_path, new_img, format='gif', fps=int(fps * size))
github vacancy / TensorArtist / examples / human-preference / libhpref / pcollector.py View on Github external
def _save_gif(traj, filename):
    traj = np.asarray(traj, dtype='uint8')
    return imageio.mimwrite(filename, traj,  duration=0.1)
github miykael / gif_your_nifti / gif_your_nifti / core.py View on Github external
Between 0 and 1.
    fps: int
        Frames per second

    """
    # Load NIfTI and put it in right shape
    out_img, maximum = load_and_prepare_image(filename, size)

    # Create output mosaic
    new_img = create_mosaic_depth(out_img, maximum)

    # Figure out extension
    ext = '.{}'.format(parse_filename(filename)[2])

    # Write gif file
    mimwrite(filename.replace(ext, '_depth.gif'), new_img,
             format='gif', fps=int(fps * size))
github BPHO-Salk / PSSR / image_gen.py View on Github external
time_slice = slice(t-offset_frames, t+offset_frames+1)
            img = data[time_slice].copy()
            pred_img = proc_func(img, img_info=img_info, mode=mode)
            pred_img8 = (pred_img * np.iinfo(np.uint8).max).astype(np.uint8)
            img_tiffs.append(pred_img8[None])

        imgs = np.concatenate(img_tiffs)
        if processor!='bilinear':
            fldr_name = f'{out_fn.parent}/{processor}'
        else:
            fldr_name = out_fn.parent.parent.parent/processor/out_fn.parent.stem
        save_name = f'{fn.stem}_{processor}.tif'
        out_fldr = ensure_folder(out_fn.parent/processor)

        if imgs.size < 4e9:
            imageio.mimwrite(out_fldr/save_name, imgs)
        else:
            imageio.mimwrite(out_fldr/save_name, imgs, bigtiff=True)
        #imageio.mimwrite((out_fldr/save_name).with_suffix('.mp4'), imgs, fps=30, macro_block_size=None)
github guanfuchen / videopred / ext / EEN / visualize.py View on Github external
pred_z = pred_z.data.view(opt.batch_size, opt.npred, opt.nc, opt.height, opt.width)
        for b in range(opt.batch_size):
            img = dataloader.plot_seq(cond[b].cpu().unsqueeze(0), pred_z[b].cpu())
            fname = '{}/ep{}'.format(save_dir, b)
            torchvision.utils.save_image(img, '{}/z{}.png'.format(fname, indx))
            mov[-1].append(img)


    # write in movie form for easier viewing
    for indx in range(nz):
        mov[indx]=torch.stack(mov[indx])
    mov=torch.stack(mov)
    mov=mov.permute(1, 0, 3, 4, 2).cpu().clone()
    for b in range(opt.batch_size):
        print('{}/movie{}.mp4'.format(save_dir, b))
        imageio.mimwrite('{}/movie{}.mp4'.format(save_dir, b) , mov[b].cpu().numpy() , fps = 5)
github mmatl / pyrender / pyrender / viewer.py View on Github external
flag and the ``run_in_thread`` flags set.
        Kill the viewer after your desired time with
        :meth:`.Viewer.close_external`, and then call :meth:`.Viewer.save_gif`.

        Parameters
        ----------
        filename : str
            The file to save the GIF to. If not specified,
            a file dialog will be opened to ask the user where
            to save the GIF file.
        """
        if filename is None:
            filename = self._get_save_filename(['gif', 'all'])
        if filename is not None:
            self.viewer_flags['save_directory'] = os.path.dirname(filename)
            imageio.mimwrite(filename, self._saved_frames,
                             fps=self.viewer_flags['refresh_rate'],
                             palettesize=128, subrectangles=True)
        self._saved_frames = []
github yzaretskiy / hanzi-gif / main.py View on Github external
frames.extend([transp_char] * fps)

    # draw over the transparent character
    for idx, stroke in enumerate(character.strokes):
        path = stroke.to_mpl_path()
        color = radical_color if idx in character.radical_strokes else stroke_color

        w = walker(stroke.medians, step=brush_step)
        for pt, isDone in w:
            # ensure we cover the whole stroke
            radius = brush_radius if not isDone else 200
            frame_maker.add_path(path, color, color,
                                 clipping_radius=radius, clipping_pt=pt)
            frames.append(frame_maker.draw())

    imageio.mimwrite(filename, frames, format='gif', fps=fps, subrectangles=True)
github sourcerer-io / anishot / anishot / __main__.py View on Github external
def make_anishot():
    image = Image.fromarray(imageio.imread(ARGS.input.name))
    frames = []

    if ARGS.zoom_steps:
        make_zoomin(image, frames)
    make_scroll(image, frames)

    imageio.mimwrite(ARGS.output,
                     map(lambda f: numpy.array(f[0]), frames),
                     duration=list(map(lambda f: f[1], frames)))
github moderngl / moderngl / examples / next / 08_compute_shader.py View on Github external
# toggle 2 buffers as input and output
    last_buffer = buffer_a if toggle else buffer_b

    # local invocation id x -> pixel x
    # work groupid x -> pixel y
    # eg) buffer[x, y] = gl_LocalInvocationID.x + gl_WorkGroupID.x * W
    compute_shader.run(group_x=H, group_y=1)

    # print out
    output = np.frombuffer(last_buffer.read(), dtype=np.float32)
    output = output.reshape((H, W, 4))
    output = np.multiply(output, 255).astype(np.uint8)
    imgs.append(output)

# if you don't want to use imageio, remove this line
imageio.mimwrite(f"./{OUTPUT_DIRPATH}/debug.gif", imgs, "GIF", duration=0.15)