print("Edge detection ... ", end="") Da, Sa, Ea = algo.edgy(Ka, channel=se['channel'], threshold=se['threshold'], blur=se['blur'], dolines=se['dolines']) Db, Sb, Eb = algo.edgy(Kb, channel=se['channel'], threshold=se['threshold'], blur=se['blur'], dolines=se['dolines']) print("done") # CoM detection print("A ", end="") com_a = algo.commie(Sa) print("B ", end="") com_b = algo.commie(Sb) # Basic trajectory nodes_ab = algo.seed(com_a, com_b, h, w) nodes_ba = nodes_ab[:, [2, 3, 0, 1]] nodes_i = 0.5 * (nodes_ab[:, [0, 1]] + nodes_ab[:, [2, 3]]) # Warp print("Warping ...", end="") Wa, posi_a = algo.deform(Ka, nodes_ab, 0.5, com_a, com_b) Wb, posi_b = algo.deform(Kb, nodes_ba, 0.5, com_b, com_a) print("done") # Apply solid background color
def silhouette(settings, k, recycle=False, K=None, X=None, Y=None, showsil=True, showedge=True, showcom=True): """ Perform silhouette extraction and contour detection for frame *k*. These analysis files are generated: - silly.png silhouette shape binary map. - edgy.png silhouette edges binary map. - com.json silhouette center of mass properties. - shape.png silhouette detection diagram (returned for preview). Usage ----- >>> f, K, E, com = silhouette(settings, k) Returns ------- 1. Filename of diagnostics chart 2. Key frame bitmap 3. Edge map 4. Center of mass properties """ # This is where the action is folder = path.join(settings['temppath'], 'k{0:03d}'.format(k + 1)) f = path.join(folder, 'shape.png') # Fetch ingredients se = settings['edge'] sr = settings['render'] bc = None if sr['autoback'] else sr['backcolor'] if K is None: K = algo.load_rgba(settings['keyframes'][k]) # Do we need to do anything at all? if recycle and path.isfile(f) and \ path.isfile(path.join(folder, 'com.json' )) and \ path.isfile(path.join(folder, 'silly.png')) and \ path.isfile(path.join(folder, 'edgy.png' )): return f, K, None, None # Make mesh grid if X is None or Y is None: X, Y = algo.grid(K) # Extract silhouette D, S, E = algo.edgy(K, backcolor = bc, linecolor = sr['linecolor'], dolines = sr['lineart' ], threshold = se['threshold'][k] * 0.01, channel = se['channel' ][k], doscharr = se['scharr' ][k], blur = se['blur' ][k], invert = se['invert' ][k]) # Center of mass measurement com = algo.commie(S, X=X, Y=Y, verbose=False) # Save the harvest saveit(com, path.join(folder, 'com.json' )) saveit(S , path.join(folder, 'silly.png')) saveit(E , path.join(folder, 'edgy.png' )) # Combine all results into one classy chart Sp = S if showsil else None Ep = E if showedge else None comp = com if showcom else None fig = algo.big_figure('MuddyMorph - Silhouette Chart', *E.shape) algo.edgeplot(D, Sp, Ep, comp, X=X, Y=Y) plt.axis('off') plt.savefig(f, **chartopts) plt.close(fig) return f, K, E, com
D, S, E = algo.edgy(K, channel=channel, threshold=threshold, blur=blur, dolines=dolines, doscharr=doscharr) stopwatch += time() print("\t{} edge points".format(E.sum())) print("\tDone in {0:.3f}s\n".format(stopwatch)) #%% Center of mass print("Center of mass computation ...\n\t", end="") stopwatch = -time() com = algo.commie(S) stopwatch += time() print("\tDone in {0:.3f}s\n".format(stopwatch)) #%% Detect silhouette key points print("Detecting silhouette points ...", end="") stopwatch = -time() nodes0 = algo.seed(*E.shape, com, com) base = nodes0[4:] sp = algo.spawn(E, base[:, [0, 1]], spawnpoints, r_min=simisize) stopwatch += time() print("\t{} silhouette points".format(len(sp))) print("\tDone in {0:.3f}s\n".format(stopwatch))
print("Loading image ... ", end="") K = algo.load_rgba(settings['keyframes'][0]) h, w = K.shape[:2] print("done") # Edge detection print("Edge detection ... ", end="") D, S, E = algo.edgy(K, channel = se['channel' ], threshold = se['threshold'], blur = se['blur' ], dolines = se['dolines' ]) print("done") # CoM detection com = algo.commie(S) base = algo.seed(com, com, *S.shape)[:, :2] # Pick edge points print("Picking {} edge points ... ".format(n), end="") stopwatch = - time() kp = algo.spawn(E, base, n) stopwatch += time() print("done in {0:.0f} ms".format(stopwatch * 1000.)) ########## # Review # ########## print("Plotting result ... ", end="")