# Home grown import muddymorph_algo as algo ########### # Try-out # ########### # Make an announcement print("") print("MuddyMorph Local Contrast Proto") print("===============================") print("") B = algo.load_rgba(image) D, _, _ = algo.edgy(B, channel=channel) stopwatch = -time() C = algo.loco(D, algorithm=algorithm, cutoff=cutoff, detail=detail) stopwatch += time() ########## # Review # ########## print("Image \t{}".format(path.basename(image))) print("Channel\t{}".format(channel)) print("Cutoff \t{}".format(cutoff)) print("Detail \t{}".format(detail)) print("Min \t{0:.3f}".format(C.min())) print("Mean \t{0:.3f}".format(C.mean()))
print("MuddyMorph Warp Proto 2") print("=======================") print("") # Load data print("Loading images ... ", end="") Ka = algo.load_rgba(settings['keyframes'][0]) Kb = algo.load_rgba(settings['keyframes'][1]) h, w = Ka.shape[:2] print("done") # Edge detection 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)
######## # Make an announcement print("") print("MuddyMorph Similarity Proto") print("===========================") print("") # Load images print("Loading images ...", end="") Ka = algo.load_rgba(key_a) Kb = algo.load_rgba(key_b) print("done") print("Edge detection ...", end="") Da, Sa, Ea = algo.edgy(Ka, channel=channel, threshold=threshold, blur=blur, dolines=dolines) Db, Sb, Eb = algo.edgy(Kb, channel=channel, threshold=threshold, blur=blur, dolines=dolines) Gx, Gy = algo.grid(Ea) xea, yea = Gx[Ea].flatten(), Gy[Ea].flatten() xeb, yeb = Gx[Eb].flatten(), Gy[Eb].flatten() print("done") # Serial random similarity evaluation msg = "Random similarity evaluation ({} edge points) ..." print(msg.format(repeats), end="") best, worst = None, None stopwatch = -time() for repeat in range(repeats): ia = algo.pick_int((0, len(xea) - 1))
stopwatch = -time() K = algo.load_rgba(imagefile) simisize = max(int(np.ceil(max(K.shape[:2]) * detail)) + 1, 4) stopwatch += time() print("\tResolution {} x {}".format(K.shape[1], K.shape[0])) print("\tDone in {0:.3f}s\n".format(stopwatch)) #%% Get that silhouette print("Edge detection ...") stopwatch = -time() 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))
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
print("") print("MuddyMorph Spawn Test") print("=====================") print("") # Load data 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.))