def save(self): d = a107.new_filename(self.data_dir) os.mkdir(d) ret = {"data_dir": d, "filenames": []} for img in self.bank: _, fn = os.path.split(img.filename) newpath = os.path.join(d, fn) img.save(newpath) ret["filenames"].append(newpath) return ret
def main(args): output = a107.new_filename("tyled-" + os.path.splitext(args.input)[0], "jpg") print(f"input filename: {args.input}") print(f"output filename: {output}") print(f"thumbnails directory: {args.thumbnails_dir}") print(f"Interactive? {'YES' if args.interactive else 'no'}") td = tylerdurden.TylerDurden(args.input, output, args.thumbnails_dir, args.niter, args.interactive) td.init() td.run() td.save()
def draw_bank(self, ratio=1.3, flag_save=False, backgroundcolor=(0, 0, 0, 255)): """ Builds a grid-like image containing all the bank images with each cell in the grid containing a "star". Args: ratio: ratio between columns and rows in image flag_save: whether or not to save image to disk """ img = self._make_draw_bank(ratio, backgroundcolor) if flag_save: filename = a107.new_filename(f"grid-{self.bankname}", "png") img.save(filename) print(f"Saved file '{filename}'") img.show()
def save(self, flag_imgref=False): flag_imgref = a107.to_bool(flag_imgref) img = self._make_image(flag_imgref) filename = a107.new_filename("nowstars0", "png", False) img.save(filename) return filename
def temp_filename(prefix, extension=None): """Wrapper for new_filename that filename without path nor extension from prefix and prepends '/tmp/ to it.""" return a107.new_filename(os.path.join("/tmp", os.path.splitext(os.path.split(prefix)[1])[0]), extension)
def main(args): import matplotlib.pyplot as plt filename = args.input img = Image.open(filename, "r") if False: img.show() aimg = np.asarray(img) if False: aimgd = np.diff(aimg, 1, 1) if False: plt.imshow(aimgd) plt.show() if False: imgdc = Image.fromarray(aimgd) imgdc.show() o = Session(aimg) hei, wid, _ = aimg.shape ostia = [] yi = AA while yi < hei: xi = AA ly = [] while xi < wid: x0, y0, x1, y1 = o.find_sth(xi, yi) if x1 - x0 > 0 and y1 - y0 > 0 and x1 - x0 + y1 - y0 > 1: s = np.s_[y0:y1 + 1, x0:x1 + 1] if False: anave = aimg[s] plt.imshow(anave) plt.show() if False: anave = o.shit[s] plt.matshow(anave) plt.show() ostia.append(Point((x1 + x0) // 2, (y1 + y0) // 2, s, "")) xi = x1 + 1 ly.append(y1) else: xi += 2 * AA + 1 if ly: yi = max(ly) + 1 else: yi += 2 * AA + 1 # if len(ostia) > 10: # break if False: _, axarr = plt.subplots(4, 5) k = 0 for j in range(4): for i in range(5): a = axarr[j][i] if k < len(ostia): if False: a.matshow(o.shit[ostia[k].s]) else: a.imshow(o.aimg[ostia[k].s]) k += 1 a.axis("off") plt.show() print(f"Found {len(ostia)} objects") savedir = args.datadir dirname = a107.new_filename(os.path.join(savedir, "sky"), flag_minimal=False) os.mkdir(dirname) for i, p in enumerate(ostia): outputfilename = a107.new_filename(os.path.join(dirname, "ostia"), "png", flag_minimal=False) p.filename = outputfilename print(f"Saving {outputfilename}...") M = o.aimg[p.s] h, w, _ = M.shape MA = np.zeros((h, w, 4), dtype="uint8") MA[:, :, :3] = M MA[:, :, 3] = o.shit[p.s] * 255 Image.fromarray(MA).save(outputfilename) print("...done") csvfilename = os.path.join(dirname, "metadata.csv") wr = csv.writer(open(csvfilename, "w")) wr.writerows([(os.path.split(p.filename)[1], p.x, p.y) for p in ostia]) print(f"Saved {csvfilename}")
import imageio import argparse import a107 if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__, formatter_class=a107.SmartFormatter) parser.add_argument("-d", "--duration", default=100, type=int, help="Frame duration in miliseconds") parser.add_argument( "-b", "--backwardsbind", action="store_true", help="Repeats frames backwards to bind end of loop with beginning") args = parser.parse_args() filenames = glob.glob("*") filenames.sort() images = [] allimages = [imageio.imread(filename) for filename in filenames] for image in allimages: images.append(image) if args.backwardsbind: for image in allimages[:0:-1]: images.append(image) outputfilename = a107.new_filename("movie", "gif") imageio.mimsave(outputfilename, images, duration=args.duration / 1000) print(f"Saved '{outputfilename}")