def sticker_attack(image):
    foreground = Image.open("/home/carla/Downloads/cutout.png")
    foreground = np.array(foreground)
    foreground = Image.fromarray(foreground)

    background = Image.fromarray(image)
    background = background.convert('RGBA')
    combined = Image.new('RGBA', background.size)
    combined = Image.alpha_composite(combined, background)
    combined = Image.alpha_composite(combined, foreground)
    combined = np.array(combined)

    return combined
Ejemplo n.º 2
0
    def run(self):
        print "Starting " + self.name
        ds = DotStar.DotStar(numPixels, maxBrightness)
        ds.open(args.spidev, args.spics)

        while not endThreads:
            # calculate current framenumber
            now = time.time()
            frame = int(now * HZ)

            # handle state changes
            while (not nextStates.empty()):
                nextState = nextStates.get()
                if (nextState in self.oneTimeOverlays.keys()):
                    self.oneTimeOverlays[nextState].startOverlay(frame)

                if (nextState in self.images):
                    self.currentState = nextState
                    img = self.images[nextState]["image"]
                    width = self.images[nextState]["width"]
                    height = self.images[nextState]["height"]

            # get background image column
            x = int(frame % width)
            column = img.crop((x, 0, x + 1, img.size[1]))

            # conditionally overlay one time patterns
            for overlay in self.oneTimeOverlays.itervalues():
                column = overlay.paste(frame, column)

            # overlay progress image in state processingOrder
            if (self.currentState == "processingOrder"):
                progress = self.progressImage.crop(
                    (productionProgress, 0, productionProgress + 1, height))
                if (progress):
                    column = Image.alpha_composite(column, progress)

            pixels = column.load()
            for y in range(height):  # For each pixel in column...
                value = pixels[0, y]  # Read pixel in image
                r = value[0]
                g = value[1]
                b = value[2]

                ds.setPixel(y, r, g, b)

            ds.show()

            time.sleep(float(frame + 1) / HZ - now)

        ds.close()
        print "Exiting " + self.name
def laser_attack(image):
    foreground = Image.open("/home/carla/Downloads/laser_transparent.png")
    foreground = np.array(foreground)
    foreground[:, :, 0] = 0
    foreground[:, :, 2] = 0
    foreground = Image.fromarray(foreground)

    basewidth = 800
    wpercent = (basewidth / float(foreground.size[0]))
    hsize = int((float(foreground.size[1]) * float(wpercent)))
    foreground = foreground.resize((basewidth, hsize), Image.ANTIALIAS)
    foreground = foreground.crop((0, 200, 800, 800))

    background = Image.fromarray(image)
    background = background.convert('RGBA')
    print background.size
    combined = Image.new('RGBA', background.size)
    combined = Image.alpha_composite(combined, background)
    combined = Image.alpha_composite(combined, foreground)
    combined = np.array(combined)

    return combined
Ejemplo n.º 4
0
    def convert_file(input_file, output_dir, output_extension, bg_replacement):
        input_file_name, input_extension = os.path.splitext(
            os.path.basename(input_file))
        output_file = os.path.join(output_dir,
                                   input_file_name + '.' + output_extension)

        input_image = Image.open(input_file).convert(
            'RGBA')  # always load with alpha channel

        # Replace transparency when converting from file formats that support it to ones that don't.
        if output_extension.lower() not in FILE_FORMATS_WITH_TRANSPARENCY:
            print('Replacing transparent parts with color %s.' %
                  bg_replacement)
            bg_image = Image.new(
                'RGBA', input_image.size,
                (bg_replacement[0], bg_replacement[1], bg_replacement[2]))

            non_transparent_image = Image.alpha_composite(
                bg_image, input_image)
            non_transparent_image = non_transparent_image.convert('RGB')

            non_transparent_image.save(output_file)
        else:
            input_image.save(output_file)
import Image

background = Image.open("untitled2.jpg")
foreground = Image.open("input.png")

background.paste(foreground, (0, 0), foreground)
background.show()


background = Image.open("untitled2.jpg")
foreground = Image.open("input.png")

Image.alpha_composite(background, foreground).save("test3.png")
Ejemplo n.º 6
0
 def paste(self, frame, background):
     x = frame - self.startFrame
     if (self.width < x):
         return background
     overlay = self.image.crop((x, 0, x + 1, self.image.size[1]))
     return Image.alpha_composite(background, overlay)
Ejemplo n.º 7
0
map = Basemap(llcrnrlon=llcrnrlon,
              llcrnrlat=llcrnrlat,
              urcrnrlon=urcrnrlon,
              urcrnrlat=urcrnrlat,
              epsg=5520)
map.arcgisimage(service='ESRI_Imagery_World_2D', xpixels=1500, verbose=True)
x, y = map(ln, lt)
#map.plot(x, y, 'bo', markersize=5,zorder=None, markerfacecolor='#424FA4',markeredgecolor="none", alpha=0.33 )
map.plot(x, y, 'ro', markersize=5, markeredgecolor="none", alpha=0.33)

plt.savefig("out.png")

back = Image.open("out.png")
loc = Image.open('loc.png')

Image.alpha_composite(back, loc).save("test.png")
"""
back.paste(loc, (10,10), loc)
back.show()

x0, y0 = map(40.423623, -3.694575)
x1, y1 = map(41.443683, -4.714505)
extent = [10, 12, 36, 38]
map.imshow(plt.imread('loc.png'), origin="lower", extent = extent)
plt.show()


x_size, y_size = 0.8, 0.4
x0, y0 = map(x[-1] - x_size/2., y[-1] - y_size/2.)
x1, y1 = map(x[-1] + x_size/2., y[-1] + y_size/2.)
im = plt.imshow(plt.imread('loc.png'), extent=(0, 0, 0, 0))
Ejemplo n.º 8
0
import Image

background = Image.open("untitled2.jpg")
foreground = Image.open("input.png")

background.paste(foreground, (0, 0), foreground)
background.show()

background = Image.open("untitled2.jpg")
foreground = Image.open("input.png")

Image.alpha_composite(background, foreground).save("test3.png")