def to_rect_png(inp, date=None): """ Convert *inp* into a PNG file. Input file can be a step5mask file (produces greyscale PNG), or if *date* is supplied it can be a subbox file. """ # http://code.google.com/p/pypng/ import png values = cells(inp, date) # :todo: move into proper module. from landmask import centrein resolution = 0.25 width = 360 / resolution height = 180 / resolution assert int(width) == width assert int(height) == height width = int(width) height = int(height) if not date: colour = greyscale else: colour = colourscale if colour == greyscale: black = 0 else: black = (0, 0, 0) # an array of rows: a = [[black] * width for _ in range(height)] for v, box in values: v = colour(v) for x, y in centrein(box, resolution): a[y][x] = v # For colour images each row of *a* is of the form: # [(R,G,B), (R,G,B), ...] we want to flatten it to: # [R,G,B,R,G,B,...] if colour != greyscale: a = [list(itertools.chain(*row)) for row in a] try: outpath = inp.name + '.png' except ValueError: outpath = 'out.png' w = png.Writer(width=width, height=height, greyscale=(colour == greyscale), alpha=False, bitdepth=8) w.write(open(outpath, 'wb'), a)
def topng(inp, date=None): """Convert *inp* into a PNG file. Input file can be a step5mask file (produces greyscale PNG), or if *date* is supplied it can be a subbox file.""" # :todo: move into proper module. from landmask import centrein resolution = 0.25 width = 360 / resolution height = 180 / resolution assert int(width) == width assert int(height) == height width = int(width) height = int(height) cells = eqarea.grid8k() if not date: # Mask file in text format. values = gio.maskboxes(inp, cells) colour = greyscale isgrey = True else: values = extractdate(inp, cells, date) colour = colourscale isgrey = False if isgrey: black = 0 else: black = (0, 0, 0) # an array of rows: a = [[black] * width for _ in range(height)] for v, box in values: v = colour(v) for x, y in centrein(box, resolution): a[y][x] = v # For colour images each row of *a* is of the form: # [(R,G,B), (R,G,B), ...] we want to flatten it to: # [R,G,B,R,G,B,...] if not isgrey: a = [list(itertools.chain(*row)) for row in a] try: outpath = inp.name + '.png' except: outpath = 'out.png' w = png.Writer(width=width, height=height, greyscale=isgrey, alpha=False, bitdepth=8) w.write(open(outpath, 'wb'), a)
def to_rect_png(inp, date=None): """ Convert *inp* into a PNG file. Input file can be a step5mask file (produces greyscale PNG), or if *date* is supplied it can be a subbox file. """ # http://code.google.com/p/pypng/ import png values = cells(inp, date) # :todo: move into proper module. from landmask import centrein resolution = 0.25 width = 360/resolution height = 180/resolution assert int(width) == width assert int(height) == height width = int(width) height = int(height) if not date: colour = greyscale else: colour = colourscale if colour == greyscale: black = 0 else: black = (0,0,0) # an array of rows: a = [[black]*width for _ in range(height)] for v,box in values: v = colour(v) for x,y in centrein(box, resolution): a[y][x] = v # For colour images each row of *a* is of the form: # [(R,G,B), (R,G,B), ...] we want to flatten it to: # [R,G,B,R,G,B,...] if colour != greyscale: a = [list(itertools.chain(*row)) for row in a] try: outpath = inp.name + '.png' except: outpath = 'out.png' w = png.Writer(width=width, height=height, greyscale=(colour == greyscale), alpha=False, bitdepth=8) w.write(open(outpath, 'wb'), a)
def topng(inp, date=None): """Convert *inp* into a PNG file. Input file can be a step5mask file (produces greyscale PNG), or if *date* is supplied it can be a subbox file.""" # :todo: move into proper module. from landmask import centrein resolution = 0.25 width = 360 / resolution height = 180 / resolution assert int(width) == width assert int(height) == height width = int(width) height = int(height) cells = eqarea.grid8k() if not date: # Mask file in text format. values = gio.maskboxes(inp, cells) colour = greyscale isgrey = True else: values = extractdate(inp, cells, date) colour = colourscale isgrey = False if isgrey: black = 0 else: black = (0, 0, 0) # an array of rows: a = [[black] * width for _ in range(height)] for v, box in values: v = colour(v) for x, y in centrein(box, resolution): a[y][x] = v # For colour images each row of *a* is of the form: # [(R,G,B), (R,G,B), ...] we want to flatten it to: # [R,G,B,R,G,B,...] if not isgrey: a = [list(itertools.chain(*row)) for row in a] try: outpath = inp.name + ".png" except: outpath = "out.png" w = png.Writer(width=width, height=height, greyscale=isgrey, alpha=False, bitdepth=8) w.write(open(outpath, "wb"), a)