Beispiel #1
0
def main(screen):
    # Load logo
    logo = app.load_image("player.bmp", -1)
    r = image.get_rect()
    # blit background on to the screen

    # Create a new FaderSurface with the same dimensions and an initial
    # transparency of 1.

    surface = Complex.FaderSurface(r.width, r.height, 1)
    
    #Blit the original o  the FaderSurface.
    screen.blit(logo, (0,0))

    #The default step value is -1, but we wnat to fade the image in.
    surface.step = 1
Beispiel #2
0
def reload_image(context):
	image = context.document.CurrentObject()
	if image is not None and isinstance(image, external.ExternalGraphics):
		# Don't try this at home :) It pokes around in the internals of
		# Sketch!

		olddata = image.data
		filename = olddata.Filename()
		oldrect = image.bounding_rect

		# first, remove the old object from the cache.
		if olddata.stored_in_cache \
			and external.instance_cache.has_key(filename):
			del external.instance_cache[filename]
			olddata.stored_in_cache = 0

		# now we can load the data again the normal way because it's not
		# in the cache anymore.
		if image.is_Eps:
			data = eps.load_eps(filename)
		else:
			data = app.load_image(filename)

		# replace the old data object with the new one. Normally we
		# would have to handle the undo info returned. Here we just
		# discard it so that the reload won't be in the history.
		image.SetData(data)

		# some house keeping tasks that are necessary because the sort
		# of thing we're doing here, i.e. modifying an object without
		# undo information etc., wasn't anticipated:
		
		# to make sure that the bboxes get recomputed etc, call the
		# _changed method. SetData should probably do that
		# automatically, but currently it doesn't
		image._changed()

		# make sure the object itself is properly redrawn
		context.document.AddClearRect(oldrect)
		context.document.AddClearRect(image.bounding_rect)
		
		# make sure the selection's idea of the bounding rect is updated
		# too and have the canvas update the handles
		context.document.selection.ResetRectangle()
		context.main_window.canvas.update_handles()
Beispiel #3
0
    def image(self, attrs):
        if self.in_defs:
            return
        href = attrs['xlink:href']
        image = None

        if href[:5] == 'data:':
            # embed image
            coma = href.find(',')
            semicolon = href.find(';')
            mime = href[5:semicolon]
            if mime in [
                    'image/png', 'image/jpg', 'image/jpeg', 'image/gif',
                    'image/bmp'
            ]:
                import base64
                image = Image.open(StringIO(base64.decodestring(href[coma:])))
                if image.mode == 'P':
                    image = image.convert('RGBA')
        else:
            # linked image
            import urlparse, urllib
            path = urlparse.urlparse(href).path
            href = urllib.unquote(path.encode('utf-8'))
            path = os.path.realpath(href)
            if os.path.isfile(path):
                image = load_image(path).image
            else:
                self.loader.add_message(
                    _('Cannot find linked image file %s') % path)

        if image:
            x, y = self.user_point(attrs.get('x', '0'), attrs.get('y', '0'))

            width = self.user_length(attrs['width'])
            scalex = width / image.size[0]

            height = self.user_length(attrs['height'])
            scaley = -height / image.size[1]

            self.parse_attrs(attrs)
            self.set_loader_style()
            t = self.trafo(Trafo(scalex, 0, 0, scaley, x, y + height))
            self._print('image', t)
            self.loader.image(image, t)
	def image(self, attrs):
		if self.in_defs:
			return
		href = attrs['xlink:href']
		image = None
		
		if href[:5] == 'data:':
			# embed image
			coma = href.find(',')
			semicolon = href.find(';')
			mime = href[5:semicolon]
			if mime in ['image/png','image/jpg','image/jpeg','image/gif','image/bmp']:
				import base64
				image = Image.open(StringIO(base64.decodestring(href[coma:])))
				if image.mode == 'P':
					image = image.convert('RGBA')
		else:
			# linked image
			import urlparse, urllib
			path = urlparse.urlparse(href).path
			href = urllib.unquote(path.encode('utf-8'))
			path = os.path.realpath(href)
			if os.path.isfile(path):
				image = load_image(path).image
			else:
				self.loader.add_message(_('Cannot find linked image file %s') % path)

		if image:
			x, y = self.user_point(attrs.get('x', '0'), attrs.get('y', '0'))
			
			width = self.user_length(attrs['width'])
			scalex =  width / image.size[0]
	
			height = self.user_length(attrs['height']) 
			scaley = -height / image.size[1]
	
			self.parse_attrs(attrs)
			self.set_loader_style()
			t = self.trafo(Trafo(scalex, 0, 0, scaley, x, y + height))
			self._print('image', t)
			self.loader.image(image, t)
Beispiel #5
0
import torch
import torch.optim as optim
from torchvision import transforms, models
import matplotlib.pyplot as plt
from app import load_image, im_convert, get_features, gram_matrix

vgg = models.vgg19(pretrained=True).features
for param in vgg.parameters():
    param.requires_grad_(False)

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
vgg.to(device)

content = load_image('/home/murugesh/PycharmProjects/Style_Transfer/images/5.jpg').to(device)
style = load_image('/home/murugesh/PycharmProjects/Style_Transfer/images/4.jpg', shape=content.shape[-2:]).to(device)

content_features = get_features(content, vgg)
style_features = get_features(style, vgg)

style_grams = {layer: gram_matrix(style_features[layer]) for layer in style_features}

target = content.clone().requires_grad_(True).to(device)
style_weights = {'conv1_1': 1.,
                 'conv2_1': 0.75,
                 'conv3_1': 0.2,
                 'conv4_1': 0.2,
                 'conv5_1': 0.2}

content_weight = 1
style_weight = 1e6
show_every = 400