def createImage(letter, i): size = font.getsize(letter) char = new("L", size, 0) drawChar = Draw(char) drawChar.text((0, 0), letter, font=font, fill=255) path = DIR + "/ascii_" + i + ".bmp" char.save(path) return path
def render(self, hsv_new, palette = True): print 'rendering...' rgb_new = hsv2rgb(hsv_new) # newi = self.img.copy() NEIN: behaelt alte Daten! newi = new('RGB', (256,256)) newi.putdata(rgb_new) if palette: dists = [h-d for (h,d) in zip(self.filt.match, self.filt.distm)] add_palettes(newi, self.filt.match, self.filt.hues, dists) newi.show()
def determineStar(oldWidget): c = gui.Table(width=500,height=100); c.tr(); c.td(gui.Label("Turn on your star and position the camera")); c.tr(); c.td(gui.Label("so the star is in view.")); c.tr(); c.td(gui.Label("Make sure no planets are in the way.")); c.tr(); c.td(gui.Label("Then press OK")); c.tr(); rButton = gui.Button(value = "OK"); c.td(rButton); c.tr(); rButton.connect(gui.CLICK, app.quit, None) app.quit(); app.run(c); app.remove(c); global cam; global getImage; if not cam: cam = NoFontVideoCapture.Device(); def getImage(): return cam.getImage(); for i in range(20): getImage(); camshot = grayscale(getImage()); lightCoords = []; level = camshot.getextrema()[1]-leniency; for p in camshot.getdata(): if p>=level: lightCoords.append(255); else: lightCoords.append(0); global maskIm; maskIm = new("L",res); maskIm.putdata(lightCoords); finishButton.disabled = False; app.run(oldWidget);
def plot(A, kmax = None): """Plot matrix A as an RGB image using the Python Imaging Library and Tkinter A is converted to an RGB image using PIL and saved to disk Then it is displayed using PhotoImage A must be square, integer valued, two dimensional and non-negative If kmax is omitted it will be set to the max value of A Ole Nielsen, SUT 2003 """ #from Tkinter import Frame, Canvas, TOP, NW, PhotoImage from numpy import transpose from Image import new # PIL import time t0 = time.time() # User definable parameters imtype = 'ppm' # Image format (e.g 'ppm', 'bmp', 'tiff') filename ='mandel' # Base filename exponent = 0.998 # Exponent for morphing colors, good with kmax = 2**15 rgbmax = 2**24 # Normalisation constant for RGB # Input check assert len(A.shape) == 2, 'Matrix must be 2 dimensional' assert A.shape[0] == A.shape[1], 'Matrix must be square' msg = 'A must contain integers, I got %c' %A.dtype.char assert A.dtype.char in 'iIbBhHl', msg assert min(A.flat)>=0, 'A must be non-negative' if kmax is None: kmax = max(A.flat) # Convert values from A into RGB values (0 to 255) in each band N = A.shape[0] A = transpose(A).astype('d') # Cast as double im = new("RGB", A.shape) L = [] try: from mandelplot_ext import normalise_and_convert normalise_and_convert(A, L, kmax, rgbmax, exponent) except: print 'WARNING: Could not import C extension from mandelplot_ext' for i in range(A.shape[0]): for j in range(A.shape[1]): c = A[i,j]/kmax if c == 1: c = 0 #Map convergent point (kmax) to black (0) c = c**exponent #Morph slightly c = int(c * rgbmax) #Normalise to 256 levels per channel red = c / 256 / 256 green = (c / 256) % 256 blue = c % 256 L.append( (red, green, blue) ) # Save image to file im.putdata(L) im.save(filename + '.' + imtype, imtype) print 'Computed plot in %.2f seconds: ' %(time.time()-t0) # Display image on screen #answer = raw_input('Show image [Y/N][Y]?') #if answer.lower() in ['n', 'no']: # import sys # sys.exit() # Try to display using a image viewer import os os.system('eog %s' %(filename + '.' + imtype))
if scale <= 0: print "!! Scale must be a positive number !!" sys.exit(1) padding = options.padding + outline size = (scale * len(logo)) + (2 * padding) if invert: background, color = color, background logo = [[not i for i in row] for row in logo] # ------------------------------------------------------------------------------ # Render # ------------------------------------------------------------------------------ im = new('RGB', (size, size), background) draw = Draw(im) if invert: pass if border: start = padding - 1 end = size - padding draw.rectangle([(start, start), (end, end)], outline=border) for y, row in enumerate(logo): for x, pixel in enumerate(row): if pixel: xfactor = (x * scale) + padding yfactor = (y * scale) + padding
def plot(A, kmax=None): """Plot matrix A as an RGB image using the Python Imaging Library and Tkinter A is converted to an RGB image using PIL and saved to disk Then it is displayed using PhotoImage A must be square, integer valued, two dimensional and non-negative If kmax is omitted it will be set to the max value of A Ole Nielsen, SUT 2003 """ #from Tkinter import Frame, Canvas, TOP, NW, PhotoImage from numpy import transpose from Image import new # PIL import time t0 = time.time() # User definable parameters imtype = 'ppm' # Image format (e.g 'ppm', 'bmp', 'tiff') filename = 'mandel' # Base filename exponent = 0.998 # Exponent for morphing colors, good with kmax = 2**15 rgbmax = 2**24 # Normalisation constant for RGB # Input check assert len(A.shape) == 2, 'Matrix must be 2 dimensional' assert A.shape[0] == A.shape[1], 'Matrix must be square' msg = 'A must contain integers, I got %c' % A.dtype.char assert A.dtype.char in 'iIbBhHl', msg assert min(A.flat) >= 0, 'A must be non-negative' if kmax is None: kmax = max(A.flat) # Convert values from A into RGB values (0 to 255) in each band N = A.shape[0] A = transpose(A).astype('d') # Cast as double im = new("RGB", A.shape) L = [] try: from mandelplot_ext import normalise_and_convert normalise_and_convert(A, L, kmax, rgbmax, exponent) except: print 'WARNING: Could not import C extension from mandelplot_ext' for i in range(A.shape[0]): for j in range(A.shape[1]): c = A[i, j] / kmax if c == 1: c = 0 #Map convergent point (kmax) to black (0) c = c**exponent #Morph slightly c = int(c * rgbmax) #Normalise to 256 levels per channel red = c / 256 / 256 green = (c / 256) % 256 blue = c % 256 L.append((red, green, blue)) # Save image to file im.putdata(L) im.save(filename + '.' + imtype, imtype) print 'Computed plot in %.2f seconds: ' % (time.time() - t0) # Display image on screen #answer = raw_input('Show image [Y/N][Y]?') #if answer.lower() in ['n', 'no']: # import sys # sys.exit() # Try to display using a image viewer import os os.system('eog %s' % (filename + '.' + imtype))