t = np.linspace(0,1,N) R = 10 noise = 1/1.25 # Generate dataset x = R*sin(theta)*np.exp(-t) + noise*np.random.random(len(t)) y = R*cos(theta)*np.exp(-t) + noise*np.random.random(len(t)) shuffle = np.random.permutation(np.arange(len(x))) data = np.vstack((x[shuffle],y[shuffle])).T x = R*sin(-theta)*np.exp(-t) + noise*np.random.random(len(t)) y = R*cos(-theta)*np.exp(-t) + noise*np.random.random(len(t)) data = np.vstack((data,np.vstack((x,y)).T)) dm = DiffusionMap(data, kernel=gauss_kernel, kernel_params={'eps': eps}, cache_filename=None) w,v = dm.map(ndim=2) plt.title('Time step %s' % T) plt.subplot(311) plt.plot(data[:,0],data[:,1],'x') plt.axis('equal') plt.subplot(312) plt.imshow(dm.H, cmap='viridis') plt.subplot(313) for i,(x,y) in enumerate(zip(v[:,0].flat,v[:,1].flat)): plt.plot([x],[y],'.b')
template = io.imread('template.png', as_grey=True) shape = np.array(template.shape) x_off,y_off = (shape-1)/2 data = np.empty((len(angles),np.prod(template.shape)),float) dx,dy = data.shape for i,a in enumerate(angles): print("Rotating %i" % i) data[i] = rotate_around_centre(template,angle=a,cval=255).flat # EXPERIMENT: Simulate colour image old_data = data.copy() data = data.repeat(3, axis=1) # Compute diffusion map on dataset dm = DiffusionMap(data, kernel=gauss_kernel, kernel_params={'eps':1e9}) w,v = dm.map() # Plot the raw data as seen by the diffusion map plt.figure() plt.imshow(data,aspect=float(dy)/dx,cmap=plt.cm.gray) plt.xticks([]) # Plot the unsorted images on a circle on the x-y plane plot_images(np.cos(angles_ord),np.sin(angles_ord),old_data,template.shape) #plt.savefig('images_unordered.png') # Plot the images on the diffusion coordinates, which should be sorted plot_images(v[:,0],v[:,1],old_data,template.shape) #plt.savefig('images_ordered.png')
template = io.imread('template.png', as_grey=True) shape = np.array(template.shape) x_off, y_off = (shape - 1) / 2 data = np.empty((len(angles), np.prod(template.shape)), float) dx, dy = data.shape for i, a in enumerate(angles): print("Rotating %i" % i) data[i] = rotate_around_centre(template, angle=a, cval=255).flat # EXPERIMENT: Simulate colour image old_data = data.copy() data = data.repeat(3, axis=1) # Compute diffusion map on dataset dm = DiffusionMap(data, kernel=gauss_kernel, kernel_params={'eps': 1e9}) w, v = dm.map() # Plot the raw data as seen by the diffusion map plt.figure() plt.imshow(data, aspect=float(dy) / dx, cmap=plt.cm.gray) plt.xticks([]) # Plot the unsorted images on a circle on the x-y plane plot_images(np.cos(angles_ord), np.sin(angles_ord), old_data, template.shape) #plt.savefig('images_unordered.png') # Plot the images on the diffusion coordinates, which should be sorted plot_images(v[:, 0], v[:, 1], old_data, template.shape) #plt.savefig('images_ordered.png')
R = 10 noise = 1 / 1.25 # Generate dataset x = R * sin(theta) * np.exp(-t) + noise * np.random.random(len(t)) y = R * cos(theta) * np.exp(-t) + noise * np.random.random(len(t)) shuffle = np.random.permutation(np.arange(len(x))) data = np.vstack((x[shuffle], y[shuffle])).T x = R * sin(-theta) * np.exp(-t) + noise * np.random.random(len(t)) y = R * cos(-theta) * np.exp(-t) + noise * np.random.random(len(t)) data = np.vstack((data, np.vstack((x, y)).T)) dm = DiffusionMap(data, kernel=gauss_kernel, kernel_params={'eps': eps}, cache_filename=None) w, v = dm.map(ndim=2) plt.title('Time step %s' % T) plt.subplot(311) plt.plot(data[:, 0], data[:, 1], 'x') plt.axis('equal') plt.subplot(312) plt.imshow(dm.H, cmap='viridis') plt.subplot(313) for i, (x, y) in enumerate(zip(v[:, 0].flat, v[:, 1].flat)):