Пример #1
0
	def run(self, para = None):
		imgs = readGif(para['path'])
		for i in range(len(imgs)):
			if imgs[i].ndim==3 and imgs[i].shape[2]>3:
				imgs[i] = imgs[i][:,:,:3].copy()
		fp, fn = os.path.split(para['path'])
		fn, fe = os.path.splitext(fn) 
		IPy.show_img(imgs, fn)
Пример #2
0
def processImage(infile):
    driedlist = [[],[],[],[]]

    frames = gifs.readGif(infile,True)
    for frame in frames:
      for i in range( frame.shape[2] ):
        driedlist[i].append(frame[:,:,i])

#    print "chan, frames, height, width:\n",len(driedlist),len(driedlist[0]),len(driedlist[0][0]),len(driedlist[0][0][0])
    return (driedlist, len( driedlist[0] ), (len(driedlist[0][0]), len(driedlist[0][0][0])))
Пример #3
0
def movieRead(filename, asNumpy=True, **kwargs):
    """ movieRead(filename, asNumpy=True)
    
    Read the movie from GIF, SWF, AVI (or MPG), or a series of images (PNG,
    JPG,TIF,BMP). 
    
    Parameters
    ----------
    filename : string
        The name of the file that contains the movie. For a series of images,
        the `*` wildcard can be used.
    asNumpy : bool
        If True, returns a list of numpy arrays. Otherwise return 
        a list if PIL images.
    
    Notes
    ------
    Reading AVI requires the "ffmpeg" application:
      * Most linux users can install it using their package manager
      * There is a windows installer on the visvis website
    
    """
    
    # Get extension
    EXT = os.path.splitext(filename)[1]
    EXT = EXT[1:].upper()
    
    # Start timer
    t0 = time.time()
    
    # Write
    if EXT == 'GIF':
        images = readGif(filename, asNumpy, **kwargs)
    elif EXT == 'SWF':
        images = readSwf(filename,  asNumpy, **kwargs)
    elif EXT in videoTypes:
        images = readAvi(filename,  asNumpy, **kwargs)
    elif EXT in imageTypes:
        images = readIms(filename,  asNumpy, **kwargs)
    else:
        raise ValueError('Given file extension not valid: '+EXT)
    
    # Stop timer
    t1 = time.time()
    dt = t1-t0
    
    # Notify 
    if images:
        print "Read %i frames from %s in %1.2f seconds (%1.0f ms/frame)" % (
                        len(images), EXT, dt, 1000*dt/len(images))
    else:
        print "Could not read any images."
    
    # Done
    return images
Пример #4
0
def movieRead(filename, asNumpy=True, **kwargs):
    """ movieRead(filename, asNumpy=True)
    
    Read the movie from GIF, SWF, AVI (or MPG), or a series of images (PNG,
    JPG,TIF,BMP). 
    
    Parameters
    ----------
    filename : string
        The name of the file that contains the movie. For a series of images,
        the `*` wildcard can be used.
    asNumpy : bool
        If True, returns a list of numpy arrays. Otherwise return 
        a list if PIL images.
    
    Notes
    ------
    Reading AVI requires the "ffmpeg" application:
      * Most linux users can install it using their package manager
      * There is a windows installer on the visvis website
    
    """

    # Get extension
    EXT = os.path.splitext(filename)[1]
    EXT = EXT[1:].upper()

    # Start timer
    t0 = time.time()

    # Write
    if EXT == 'GIF':
        images = readGif(filename, asNumpy, **kwargs)
    elif EXT == 'SWF':
        images = readSwf(filename, asNumpy, **kwargs)
    elif EXT in videoTypes:
        images = readAvi(filename, asNumpy, **kwargs)
    elif EXT in imageTypes:
        images = readIms(filename, asNumpy, **kwargs)
    else:
        raise ValueError('Given file extension not valid: ' + EXT)

    # Stop timer
    t1 = time.time()
    dt = t1 - t0

    # Notify
    if images:
        print "Read %i frames from %s in %1.2f seconds (%1.0f ms/frame)" % (
            len(images), EXT, dt, 1000 * dt / len(images))
    else:
        print "Could not read any images."

    # Done
    return images
Пример #5
0
 def __init__(self, original_file, action_tuples=[], quality=80, output_path=None, **kwargs):
     if not os.path.exists(original_file) or not os.path.isfile(original_file):
         self.im = None
     else:
         self.im = Image.open(original_file)
         if 'duration' in self.im.info and self.im.format == 'GIF':
             self.duration = int(self.im.info['duration']) / 1000.0
             self.frames = images2gif.readGif(original_file, False)
         else:
             self.duration = None
             self.frames = []
     self.output_path = output_path
     self.original_file = original_file
     self.actions = action_tuples
     self.cropname = None
     self.quality = quality
Пример #6
0
def resizegif(filename):
#     base_gif = imageio.mimread(filename)
#     reader = imageio.get_reader(filename)
#     new_gif = []
#     new_name = filename[0:len(filename)-4]+'_new.gif'
#     print(new_name)
#     print(reader.get_data(index))
#     dur = reader.get_meta_data()['duration']
#     for frame in base_gif:
#         frame = Image.resize((frame.size[1]/2,frame.size[2]/2))
#         new_gif.append(frame)
#     imageio.mimsave(new_name, new_gif, fps=dur)
    
    frames = images2gif.readGif("Abra.gif",False)
    for frame in frames:
        frame.thumbnail((100,100), Image.ANTIALIAS)

    images2gif.writeGif('abranew.gif', frames)
Пример #7
0
    def generate_thumbnail(self,
                           thumbnail_options,
                           high_resolution=False,
                           silent_template_exception=False):
        """
        Return an unsaved ``ThumbnailFile`` containing a thumbnail image.

        The thumbnail image is generated using the ``thumbnail_options``
        dictionary.
        """
        thumbnail_options = self.get_options(thumbnail_options)
        orig_size = thumbnail_options['size']  # remember original size
        # Size sanity check.
        min_dim, max_dim = 0, 0
        for dim in orig_size:
            try:
                dim = int(dim)
            except (TypeError, ValueError):
                continue
            min_dim, max_dim = min(min_dim, dim), max(max_dim, dim)
        if max_dim == 0 or min_dim < 0:
            raise exceptions.EasyThumbnailsError(
                "The source image is an invalid size (%sx%s)" % orig_size)

        if high_resolution:
            thumbnail_options['size'] = (orig_size[0] * 2, orig_size[1] * 2)
        image = engine.generate_source_image(
            self,
            thumbnail_options,
            self.source_generators,
            fail_silently=silent_template_exception)
        if image is None:
            raise exceptions.InvalidImageFormatError(
                "The source file does not appear to be an image")

        thumbnail_image = None
        IS_GIF = False
        if isinstance(image, GifImageFile):
            IS_GIF = True
            import images2gif
            gif_image, gif_params = images2gif.readGif(image, False)
            frames = []
            for frame in gif_image:
                thumbnail_frame = engine.process_image(
                    frame, thumbnail_options, self.thumbnail_processors)
                frames.append(thumbnail_frame)
                if thumbnail_image is None:
                    thumbnail_image = frame
        else:
            thumbnail_image = engine.process_image(image, thumbnail_options,
                                                   self.thumbnail_processors)

        if high_resolution:
            thumbnail_options['size'] = orig_size  # restore original size

        filename = self.get_thumbnail_name(
            thumbnail_options,
            transparent=utils.is_transparent(thumbnail_image),
            high_resolution=high_resolution)
        quality = thumbnail_options['quality']
        subsampling = thumbnail_options['subsampling']

        if IS_GIF:
            try:
                # try save with speedup
                img = images2gif.writeGif(frames, **gif_params)
                saved = True
            except:
                # if not saved, simple save
                gif_params.update({
                    'subRectangles': False,
                })
                img = images2gif.writeGif(frames, **gif_params)
        else:
            img = engine.save_image(thumbnail_image,
                                    filename=filename,
                                    quality=quality,
                                    subsampling=subsampling)
        data = img.read()

        thumbnail = ThumbnailFile(filename,
                                  file=ContentFile(data),
                                  storage=self.thumbnail_storage,
                                  thumbnail_options=thumbnail_options)
        thumbnail.image = thumbnail_image
        thumbnail._committed = False

        return thumbnail
Пример #8
0
 def __init__(self, path):
     Grid.__init__(self)
     self.frame = 0
     self.frames = images2gif.readGif(path, False)
     [frame.thumbnail((32, 32), Image.ANTIALIAS) for frame in self.frames]
Пример #9
0
def load_video(video_path):
    return np.array(images2gif.readGif(video_path, True))
Пример #10
0
    def generate_thumbnail(self, thumbnail_options, high_resolution=False,
                           silent_template_exception=False):
        """
        Return an unsaved ``ThumbnailFile`` containing a thumbnail image.

        The thumbnail image is generated using the ``thumbnail_options``
        dictionary.
        """
        thumbnail_options = self.get_options(thumbnail_options)
        orig_size = thumbnail_options['size']  # remember original size
        # Size sanity check.
        min_dim, max_dim = 0, 0
        for dim in orig_size:
            try:
                dim = int(dim)
            except (TypeError, ValueError):
                continue
            min_dim, max_dim = min(min_dim, dim), max(max_dim, dim)
        if max_dim == 0 or min_dim < 0:
            raise exceptions.EasyThumbnailsError(
                "The source image is an invalid size (%sx%s)" % orig_size)

        if high_resolution:
            thumbnail_options['size'] = (orig_size[0] * 2, orig_size[1] * 2)
        image = engine.generate_source_image(
            self, thumbnail_options, self.source_generators,
            fail_silently=silent_template_exception)
        if image is None:
            raise exceptions.InvalidImageFormatError(
                "The source file does not appear to be an image")

        thumbnail_image = None
        IS_GIF = False
        if isinstance(image, GifImageFile):
            IS_GIF = True
            import images2gif
            gif_image, gif_params = images2gif.readGif(image, False)
            frames = []
            for frame in gif_image:
                thumbnail_frame = engine.process_image(frame, thumbnail_options,
                                                       self.thumbnail_processors)
                frames.append(thumbnail_frame)
                if thumbnail_image is None:
                    thumbnail_image = frame
        else:
            thumbnail_image = engine.process_image(image, thumbnail_options,
                                               self.thumbnail_processors)

        if high_resolution:
            thumbnail_options['size'] = orig_size  # restore original size

        filename = self.get_thumbnail_name(
            thumbnail_options,
            transparent=utils.is_transparent(thumbnail_image),
            high_resolution=high_resolution)
        quality = thumbnail_options['quality']
        subsampling = thumbnail_options['subsampling']

        if IS_GIF:
            try:
                # try save with speedup
                img = images2gif.writeGif(frames, **gif_params)
                saved = True
            except:
                # if not saved, simple save
                gif_params.update({'subRectangles': False,})
                img = images2gif.writeGif(frames, **gif_params)
        else:
            img = engine.save_image(
                thumbnail_image, filename=filename, quality=quality,
                subsampling=subsampling)
        data = img.read()

        thumbnail = ThumbnailFile(
            filename, file=ContentFile(data), storage=self.thumbnail_storage,
            thumbnail_options=thumbnail_options)
        thumbnail.image = thumbnail_image
        thumbnail._committed = False

        return thumbnail