Wand Rounded Edges on Images - python-2.7

I've been scratching my head for a few days on how to complete the task of making the edges rounded on an image taken from picamera using python-wand. I have it setup now to where it grabs the image and composites it over the banner/background image with the following:
img = Image(filename=Picture)
img.resize(1200, 800)
bimg = Image(filename=Background)
bimg.composite(img, left=300, top=200)
bimg.save(filename=BPicture)
Any help is appreciated!

You can use wand.drawing.Drawing.rectangle to generate rounded corners, and overlay it with composite channels.
from wand.image import Image
from wand.color import Color
from wand.drawing import Drawing
with Image(filename='rose:') as img:
img.resize(240, 160)
with Image(width=img.width,
height=img.height,
background=Color("white")) as mask:
with Drawing() as ctx:
ctx.fill_color = Color("black")
ctx.rectangle(left=0,
top=0,
width=mask.width,
height=mask.height,
radius=mask.width*0.1) # 10% rounding?
ctx(mask)
img.composite_channel('all_channels', mask, 'screen')
img.save(filename='/tmp/out.png')
Now if I understand your question, you can apply the same technique, but composite Picture in the drawing context.
with Image(filename='rose:') as img:
img.resize(240, 160)
with Image(img) as nimg:
nimg.negate() # For fun, let's negate the image for the background
with Drawing() as ctx:
ctx.fill_color = Color("black")
ctx.rectangle(left=0,
top=0,
width=nimg.width,
height=nimg.height,
radius=nimg.width*0.3) # 30% rounding?
ctx.composite('screen', 0, 0, nimg.width, nimg.height, img)
ctx(nimg)
nimg.save(filename='/tmp/out2.png')

Related

libvips perlin to rgb

Using NetVips,
using var per = Image.Perlin(800,800,33,true,3434);
using var per2 = Image.Perlin(800,800,13,true,3435);
using var per3 = Image.Perlin(800,800,13,true,3435);
using var comp = per.Composite(new []{per2, per3},new []{Enums.BlendMode.ColourBurn, Enums.BlendMode.Lighten},compositingSpace:Enums.Interpretation.Rgb);
yeilds
Exception has occurred: CLR/NetVips.VipsException
An unhandled exception of type 'NetVips.VipsException' occurred in NetVips.dll: 'unable to call composite
vips_colourspace: no known route from 'b-w' to 'rgb''
not sure how to get image from perlin, b-w to rgb basically.
Try using sRGB instead of RGB, you should get an image.
Though it'll be black and white since you are compositing black and white images. Did you want to join the three perlin images together as RGB? You need bandjoin, eg. in Python:
#!/usr/bin/python3
import pyvips
per1 = pyvips.Image.perlin(800, 800, cell_size=33, uchar=True, seed=3434)
per2 = pyvips.Image.perlin(800, 800, cell_size=13, uchar=True, seed=3435)
per3 = pyvips.Image.perlin(800, 800, cell_size=13, uchar=True, seed=3435)
# join the three one-band images up as a three-band image, tag as sRGB
image = per1.bandjoin([per2, per3]).copy(interpretation="srgb")
image.write_to_file("x.png")
To make:

How to create transparent Mat

Am trying to create transparent mat but am getting black background image in return so any idea how to do it as i have to overlay this image with some content on camera video feed.
code i tried.
cv::Mat comp = cv::Mat::zeros( currentImage.size(), CV_8UC4 );
comp.setTo(cv::Scalar(0,0,0,0));
imshow( "transparent", comp ); // show black background image.
thanks to #HansHire and #Scheff we find out that problem is in cv::imshow() it not render transparency so to check Mat for transparency it need to dumped to disk to be checked using system image viewer which render transparency very well
cv::Mat comp = cv::Mat::zeros( currentImage.size(), CV_8UC4 );
comp.setTo(cv::Scalar(0,0,0,0));
// imshow( "transparent", comp ); // show black background image because it cant render transparency .
imwrite( "C:/opencv_dump.png", comp ); // transparent upon opening , thumbnail may look black.

Tkinter Background not showing transparent

Hey im a newbie in python in my code there is a animated gif that play whenever i run the code. The gif image is actually transparent when open in adobe etc. but the problem is when i run the code.The frame which is the color gray included in the gif.I want to remove the color gray so that the only thing that can see is my only animated gif
This is my code:
# mimic an animated GIF displaying a series of GIFs
# an animated GIF was used to create the series of GIFs
# with a common GIF animator utility
import time
from Tkinter import *
root = Tk()
imagelist = ["dog001.gif","dog002.gif","dog003.gif"]
# extract width and height info
photo = PhotoImage(file=imagelist[0])
width = photo.width()
height = photo.height()
canvas = Canvas(width=width, height=height)
canvas.create_line(0,240,640,240, fill='blue')
canvas.pack()
# create a list of image objects
giflist = []
for imagefile in imagelist:
photo = PhotoImage(file=imagefile)
giflist.append(photo)
# loop through the gif image objects for a while
for k in range(0, 10):
for gif in giflist:
canvas.delete(ALL)
canvas.create_image(width/2.0, height/2.0, image=gif)
canvas.update()
time.sleep(0.1)
root.mainloop()[![enter image description here][1]][1]
dog001.gif
dog002.gif
dog003.gif
As described here, making a Tkinter window transparent is possible, but depends on your OS.
If you are on Windows, just add the following lines after creating the root:
root = Tk()
# Hide the root window drag bar and close button
root.overrideredirect(True)
# Make the root window always on top
root.wm_attributes("-topmost", True)
# Define a transparent color
root.wm_attributes("-transparentcolor", '#eeefff')
Then set your canvas' background color as the transparent color defined above:
canvas = Canvas(width=width, height=height, bg='#eeefff', highlightthickness=0)

pygame my picture wont show up on my window

import pygame
import sys
import os
from pygame.locals import *
#Allows for the editing of a window
pygame.init()
#Sets screen size
window = pygame.display.set_mode((800,600),0,32)
#Names the window
pygame.display.set_caption("TEST")
#Types of colors (red,green,blue)
black = (0,0,0)
blue = (0,0,255)
green = (0,255,0)
yellow = (255,255,0)
red = (255,0,0)
purple = (255,0,255)
lightblue = (0,255,255)
white = (255,255,255)
pink = (255,125,125)
mif="climb.PNG"
mif=pygame.image.load(mif).convert()
#Loop
gameLoop = True
while gameLoop:
pygame.display.flip() #must flip the image o the color is visable
window.blit(mif, (0,0))
window.fill(black) #used to fill the creen with the certian color variables
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameLoop=False #Allows the user to exit the loop/game
pygame.quit() #quit the pygame interface
exit(0)
When I select run my yellow window pops up but no image...
I'm new to pygame and python so maybe I just did something wrong?
Is there a specific place that I should have my image saved to?
I'm running on a windows 8 hp ENVY...
I just want to learn what I'm doing wrong so I don't make the error again. (I should also add that I have tried many different pictures and some where not able to be located.)
First fill window with black color window.fill(black),
then put image on it window.blit(mif, (0,0)),
and last send it to your graphic card (and on your monitor) pygame.display.flip()
window.fill(black)
window.blit(mif, (0,0))
pygame.display.flip()
If your image is as big as window then you don't need to use fill(black).
You can keep image in the same folder with script. Or you can create subfolder only for image to have order in folders.
If you call this folder images then you have to add this to filenames images/climb.PNG.
BTW: better use / than \ in path because \n in path can be interpreted as ENTER/new line as in any text.
But the most properly is:
import os
filename = os.path.join('images', 'climb.PNG')

Fish swim in pygame

I want to use the python pygame module to make a 2D "fishtank".
Basically I will load a jpg image as background and load a gif animated image depicting fish swimming and make it move.
I know how to make an static image move but how to make a gif image move while the image itself is animated.
I have PIL installed, do sure if need to use it.
If that does not work, I can also break apart the gif file into several static frames and cyclically make each of them show on screen. When the latter one is posted, the former one needs to be removed, how to remove it ?
Here is a class I used in my name to get PyGame animation to work:
class Animation(pygame.sprite.Sprite):
def __init__(self, img, fps = 6):
# Call the parent class (Sprite) constructor
pygame.sprite.Sprite.__init__(self)
# Slice source image to array of images
self.images = self.loadSliced(img)
# Track the time we started, and the time between updates.
# Then we can figure out when we have to switch the image.
self._start = pygame.time.get_ticks()
self._delay = 1000 / fps
self._last_update = 0
self._frame = 0
self.image = self._images[self._frame]
def loadSliced(w, h, filename):
"""
Pre-conditions:
Master can be any height
Sprites frames must be the same width
Master width must be len(frames)*frames.width
Arguments:
w -- Width of a frame in pixels
h -- Height of a frame in pixels
filename -- Master image for animation
"""
images = []
if fileExists( img, "Animation Master Image"):
master_image = pygame.image.load(filename).convert_alpha()
master_width, master_height = master_image.get_size()
for i in range(int(master_width/w)):
images.append(master_image.subsurface((i*w, 0, w, h)))
return images
def update(self, t):
# Note that this doesn't work if it's been more than self._delay
# time between calls to update(); we only update the image once
# then. but it really should be updated twice
if t - self._last_update > self._delay:
self._frame += 1
if self._frame >= len(self._images):
self._frame = 0
self.image = self._images[self._frame]
self._last_update = t
self.image = self._images[self._frame]
self._last_update = t
def getFrame(self, screen):
# Update Frame and Display Sprite
self.update(pygame.time.get_ticks())
return self.image