def gen_features(self, new_map, params = None): ''' input: - new_map: MapObject output: - feature representation of map ''' #entropy, entropy_name = px_features.entr(new_map.bw_img, img_name = new_map.name) #glcm, glcm_name = px_features.GLCM(new_map.bw_img, 50, img_name = new_map.name) if new_map.X is None: p = 'features/data_{}.npy'.format(new_map.name[-1]) if os.path.exists(p): data = np.load(p) else: if params == None: params = self.params rgb, rgb_name = px_features.normalized(new_map.getMapData(), img_name = new_map.name) ave_rgb, ave_rgb_name = px_features.blurred(new_map.img, img_name = new_map.name) edges, edges_name = px_features.edge_density(new_map.bw_img, params['edge_k'], img_name = new_map.name, amp = 1) hog, hog_name = px_features.hog(new_map.bw_img, params['hog_k'], img_name = new_map.name, bins = params['nbins']) max_d, max_d_names = px_features.bright_max_diff(new_map.img, params['edge_k'], img_name = new_map.name) v_print('Concatenating', self.verbose) data = np.concatenate((rgb, ave_rgb, edges, max_d, hog), axis = 1) np.save(p, data) names = np.concatenate((rgb_name, ave_rgb_name, edges_name, max_d_names, hog_name)) v_print('Done Concatenating', self.verbose) new_map.X = data self.feat_names = names else: data = new_map.X return data
def vis_px(): fn = 'haiti/haiti_1002003.tif' img = cv2.imread(fn) bw_img = cv2.imread(fn, 0) myMap = MapOverlay(fn) h,w,c = img.shape ''' norm = img blur = features.blurred(myMap.img, "haiti_1002003")[0] print blur.shape f1 = plt.figure('Px Colors', frameon = False) f1.subplots_adjust(bottom=0, left = 0, right = 1, top = 1, wspace = 0, hspace = 0) ax = plt.Axes(f1, [0., 0., 1., 1.]) ax.set_axis_off() f1.add_axes(ax) r = norm[:,:,0] plt.subplot(231) plt.imshow(r, 'Reds') plt.xticks([]), plt.yticks([]) g = norm[:,:,1] plt.subplot(232) plt.imshow(g, 'Greens') plt.xticks([]), plt.yticks([]) b = norm[:,:,2] plt.subplot(233) plt.imshow(b, 'Blues') plt.xticks([]), plt.yticks([]) ave_r = blur[:,0].reshape(h,w) plt.subplot(234) plt.imshow(ave_r, 'Reds') plt.xticks([]), plt.yticks([]) ave_g = blur[:,1].reshape(h,w) plt.subplot(235) plt.imshow(ave_g, 'Greens') plt.xticks([]), plt.yticks([]) ave_b = blur[:,2].reshape(h,w) plt.subplot(236) plt.imshow(ave_b, 'Blues') plt.xticks([]), plt.yticks([]) ''' f2 = plt.figure('Px Edges', frameon = False) f2.subplots_adjust(bottom=0, left = 0, right = 1, top = 1, wspace = 0, hspace = 0) ax = plt.Axes(f2, [0., 0., 1., 1.]) ax.set_axis_off() f2.add_axes(ax) edge = features.edge_density(img, 100, img_name = 'haiti_1002003', amp = 1)[0].reshape(h,w) print np.max(edge) print edge/0.0096 plt.subplot(111) plt.imshow(edge, cmap = 'gray') plt.xticks([]), plt.yticks([]) ''' f3 = plt.figure('Histogram of Gradients', frameon = False) f2.subplots_adjust(bottom=0, left = 0, right = 1, top = 1, wspace = 0, hspace = 0) ax = plt.Axes(f3, [0., 0., 1., 1.]) ax.set_axis_off() f3.add_axes(ax) hog = features.hog(bw_img, 50, img_name = 'haiti_1002003')[0] for i in range(hog.shape[1]): f3.add_subplot(4,4,i+1) plt.imshow(hog[:,i].reshape(h,w), 'gray') plt.xticks([]), plt.yticks([])''' plt.show()