This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try: import simplejson as json | |
| except ImportError: import json | |
| import os | |
| import urllib, urlparse | |
| import glob | |
| import numpy as np | |
| import Image | |
| from itertools import combinations | |
| import simplejson as json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| imlist=[] | |
| for infile in glob.glob( os.path.join(path, '*.jpg') ): | |
| imlist.append(infile) | |
| imlist=np.sort(imlist) | |
| features = np.zeros([len(imlist),512]) | |
| for i,f in enumerate(imlist): | |
| im = np.array(Image.open(f)) | |
| h, edges = np.histogramdd(im.reshape(-1,3),8,normed=True, range=[(0,255),(0,255),(0,255)]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_alpha_shape(infile,radius): | |
| command = "%s -A -aa %s -r -m10000000 -oN -oFpoints < %s" % (hull_path, str(radius), infile) | |
| print >> sys.stderr, "Running command: %s" % command | |
| retcode = subprocess.call(command, shell=True) | |
| results_file = open("points-alf") | |
| results_file.next() | |
| results_indices = [[int(i) for i in line.rstrip().split()] for line in results_file] | |
| results_file.close() | |
| return results_indices |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| hull_path = "./hull" | |
| infile='C.txt' | |
| with open(infile, 'w') as f: | |
| np.savetxt(f, C.T, delimiter=' ', fmt="%0.7f %0.7f\n") | |
| radius=1 | |
| indices = get_alpha_shape(infile,radius) | |
| alpha=C.T[indices] | |
| plot(C[0],C[1],'.'), plot(alpha[1:].T[0],alpha[1:].T[1],'r') | |
| savefig("C_radius="+str(radius)+".png") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from scipy.cluster.vq import kmeans,vq | |
| from pylab import * | |
| def patchwork(data,numsegs,numclass): | |
| # computing K-Means with K = numsegs | |
| centroids,_ = kmeans(data,numsegs) | |
| # assign each sample to a cluster | |
| idx,_ = vq(data,centroids) | |
| # loop through number of classes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CC = gcc | |
| AR = ar | |
| OBJS = hull.o ch.o io.o rand.o pointops.o fg.o | |
| HDRS = hull.h points.h pointsites.h stormacs.h | |
| SRC = hull.c ch.c io.c rand.c pointops.c fg.c | |
| PROG = hull | |
| BINDIR = /usr/bin | |
| LIBDIR = /usr/lib64 # or just /usr/lib on a 32 bit machine? | |
| LIB = $(LIBDIR)/lib$(PROG).a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| s = urlread('http://s1270.photobucket.com/albums/SERVERNAME/YOURUSERNAME/YOURALBUMNAME/?start=all'); | |
| indices = regexp(s,'pbthumburl='); | |
| for k=1:length(indices) | |
| tmp=strtrim(s(indices(k):indices(k)+100)); | |
| tmp=tmp(regexp(tmp,'"','once')+1:end); | |
| tmp=tmp(1:regexp(tmp,'"','once')-1); | |
| system(['wget ',tmp(1:regexp(tmp,'th_')-1),tmp(regexp(tmp,'th_')+3:end)]); | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function P = bwconvhull_alt(BW) | |
| % usage: P is a binary image wherein the convex hull of objects are returned, BW is the input binary image | |
| % P= bwconvhull_alt(BW); | |
| warning off all | |
| s=regionprops(logical(BW),'ConvexImage','BoundingBox'); | |
| P=zeros(size(BW)); | |
| for no=1:length(s) | |
| P(s(no).BoundingBox(2):s(no).BoundingBox(2)+s(no).BoundingBox(4)-1,... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| addpath(genpath('~/googleearth')) | |
| dat=importdata('myFile.csv'); | |
| maps=dat.textdata(:,2); | |
| prices=dat.data; | |
| for i=1:size(maps,1) | |
| address=char(maps(i,:)); | |
| address=address(regexp(address,'loc')+3:end); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function [lat,lon] = geocode(address) | |
| fid=fopen('test.py','wt'); | |
| fprintf(fid,'%s\n','from pygeocoder import Geocoder'); | |
| fprintf(fid,'%s\n',['results = Geocoder.geocode(''',deblank(address),''')']); | |
| fprintf(fid,'%s\n','print results[0].coordinates'); | |
| fclose(fid); | |
| [stat1,stat2]=system('python test.py'); | |
| stat2=deblank(stat2); |